本文整理匯總了Python中webob.byterange.ContentRange類的典型用法代碼示例。如果您正苦於以下問題:Python ContentRange類的具體用法?Python ContentRange怎麽用?Python ContentRange使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ContentRange類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_cr_parse_no_bytes
def test_cr_parse_no_bytes():
contentrange = ContentRange(0, 99, 100)
assert_equal(contentrange.parse("0-99 100"), None)
示例2: test_cr_parse_missing_slash
def test_cr_parse_missing_slash():
contentrange = ContentRange(0, 99, 100)
assert_equal(contentrange.parse("bytes 0-99 100"), None)
示例3: test_parse_content_range_stop
def test_parse_content_range_stop():
from webob.byterange import ContentRange
from webob.descriptors import parse_content_range
val = parse_content_range("bytes 0-499/1234")
assert val.stop == ContentRange.parse("bytes 0-499/1234").stop
示例4: test_contentrange_str_length_none
def test_contentrange_str_length_none():
contentrange = ContentRange( 0, 99, 100 )
contentrange.length = None
assert_equal( str(contentrange), 'bytes 0-98/*' )
示例5: test_cr_parse_content_invalid
def test_cr_parse_content_invalid():
contentrange = ContentRange(0, 99, 100)
assert_equal(contentrange.parse("bytes 99-0/100"), None)
示例6: test_contentrange_iter
def test_contentrange_iter():
contentrange = ContentRange(0, 99, 100)
assert_true(type(contentrange.__iter__()), iter)
assert_true(ContentRange.parse('bytes 0-99/100').__class__, ContentRange)
eq_(ContentRange.parse(None), None)
eq_(ContentRange.parse('0-99 100'), None)
eq_(ContentRange.parse('bytes 0-99 100'), None)
eq_(ContentRange.parse('bytes 0-99/xxx'), None)
eq_(ContentRange.parse('bytes 0 99/100'), None)
eq_(ContentRange.parse('bytes */100').__class__, ContentRange)
eq_(ContentRange.parse('bytes A-99/100'), None)
eq_(ContentRange.parse('bytes 0-B/100'), None)
eq_(ContentRange.parse('bytes 99-0/100'), None)
eq_(ContentRange.parse('bytes 0 99/*'), None)
示例7: test_contentrange_repr
def test_contentrange_repr():
contentrange = ContentRange(0, 99, 100)
assert_true(contentrange.__repr__(), "<ContentRange bytes 0-98/100>")
示例8: test_cr_parse_range_star
def test_cr_parse_range_star():
contentrange = ContentRange(0, 99, 100)
assert_equal(contentrange.parse("bytes */100").__class__, ContentRange)
示例9: test_parse_content_range_length
def test_parse_content_range_length():
from webob.byterange import ContentRange
from webob.descriptors import parse_content_range
val = parse_content_range("bytes 0-499/1234")
eq_(val.length, ContentRange.parse("bytes 0-499/1234").length)
示例10: test_parse_content_range_start
def test_parse_content_range_start():
from webob.byterange import ContentRange
from webob.descriptors import parse_content_range
val = parse_content_range("bytes 0-499/1234")
eq_(val.start, ContentRange.parse("bytes 0-499/1234").start)
示例11: post_repertoire_upload
def post_repertoire_upload(request):
# create paths
create_paths(request)
# upload files
files = []
for name, fieldStorage in request.POST.items():
# check fieldStorage
if not isinstance(fieldStorage, FieldStorage):
continue
# configure upload
rank = (request.registry.settings['abuse_rank.active'] == 'true')
rank_max = int(request.registry.settings['abuse_rank.max'])
hostname = get_hostname()
descriptor = fieldStorage.file
filename = os.path.basename(fieldStorage.filename).encode('utf-8')
filename_hash = _hash_algorithm(filename).hexdigest()
temporary_path = get_path(request, _path_temporary, filename_hash)
contentrange = ContentRange.parse(
request.headers.get('Content-Range', None)
)
contentlength = request.headers.get('Content-Length', None)
# create checksum
with benchmark(request, name='checksum', uid=filename,
normalize=descriptor, scale=100*1024*1024):
checksum = create_checksum(
descriptor=descriptor,
algorithm=_checksum_algorithm
)
save_checksum(
path=temporary_path + _checksum_postfix,
algorithm=_checksum_algorithm.__name__,
checksum=checksum.hexdigest(),
contentrange=contentrange or (0, contentlength, contentlength)
)
# abuse rank
if rank:
if is_banned(request):
# TODO: number wont be replaced, also see
# BirthdateField line 300+ in register_webuser.py
files.append({
'name': fieldStorage.filename,
'error': _(
u"Abuse detected. Wait for {number}"
u" seconds before trying another"
u" upload.",
mapping={'number': int(still_banned_for(request))}
)})
continue
if is_collision(contentrange, checksum):
raise_abuse_rank(request)
current_rank = request.session['abuse_rank']['current']
if current_rank == rank_max:
ban(request)
# save to filesystem (-> temporary)
ok, complete = save_upload_to_fs(
descriptor=descriptor,
absolute_path=temporary_path,
contentrange=contentrange
)
if not ok:
pass
if not complete:
# client feedback
files.append({
'name': fieldStorage.filename,
'size': os.path.getsize(temporary_path)
})
continue
# get content uuid
content_uuid = get_content_uuid()
# get uuid paths
uploaded_path = get_path(request, _path_uploaded, content_uuid)
rejected_path = get_path(request, _path_rejected, content_uuid)
file_category = get_category_from_mimetype(temporary_path)
file_size = os.path.getsize(temporary_path)
mime_type = str(mime.from_file(temporary_path))
# validate file
error = validate_upload(filename, temporary_path)
if error:
# move files (temporary -> rejected)
ok = move_files_with_prefixes(
source=temporary_path, target=rejected_path
)
if not ok:
panic(
request,
reason="Files could not be moved.",
identifiers=[filename_hash, content_uuid]
)
#.........這裏部分代碼省略.........
示例12: test_cr_parse_parse_problem_1
def test_cr_parse_parse_problem_1():
contentrange = ContentRange( 0, 99, 100 )
assert_equal( contentrange.parse( 'bytes A-99/100' ), None )
示例13: test_contentrange_str_start_none
def test_contentrange_str_start_none():
contentrange = ContentRange( 0, 99, 100 )
contentrange.start = None
contentrange.stop = None
assert_equal( str(contentrange), 'bytes */100' )
示例14: test_cr_parse_invalid_length
def test_cr_parse_invalid_length():
contentrange = ContentRange(0, 99, 100)
assert_equal(contentrange.parse("bytes 0-99/xxx"), None)
示例15: test_contentrange_str_length_none
def test_contentrange_str_length_none():
contentrange = ContentRange(0, 99, 100)
contentrange.length = None
assert_equal(contentrange.__str__(), "bytes 0-98/*")