11# -*- coding: utf-8 -*-
22
3- from .compact import *
4- from . import config
5-
63import base64
74import hashlib
5+ import mimetypes
86import os
97import struct
10-
11- import mimetypes
12- from os import path
138import warnings
14- from .config import BLOCKSIZE
9+ from os import path
10+
11+ from . import config
12+ from .compact import *
13+ from .config import BLOCKSIZE
1514
1615_EXTRA_TYPES_MAP = {
1716 ".js" : "application/javascript" ,
@@ -428,7 +427,10 @@ def shardingupload_url(bucket, key, uploadid, part_number, upload_suffix=None):
428427 :param part_number: integer类型, 分片上传的编号,从0开始
429428 :return: string类型, 结束分片上传UFile的url
430429 """
431- return 'http://{0}{1}/{2}?uploadId={3}&partNumber={4}' .format (bucket , upload_suffix or config .get_default ('upload_suffix' ), key , uploadid , s (str (part_number )))
430+ return 'http://{0}{1}/{2}?uploadId={3}&partNumber={4}' .format (bucket ,
431+ upload_suffix or config .get_default ('upload_suffix' ),
432+ key , uploadid , s (str (part_number )))
433+
432434
433435def ufile_getfilelist_url (bucket , upload_suffix = None ):
434436 """
@@ -439,6 +441,7 @@ def ufile_getfilelist_url(bucket, upload_suffix=None):
439441 """
440442 return 'http://{0}{1}/?list' .format (bucket , upload_suffix or config .get_default ('upload_suffix' ))
441443
444+
442445def mimetype_from_file (file ):
443446 """
444447 获取文件的mimetype
@@ -454,6 +457,7 @@ def mimetype_from_file(file):
454457
455458 return 'application/unknowntype'
456459
460+
457461def mimetype_from_buffer (stream ):
458462 """
459463 获取流对象的mimetype
@@ -463,6 +467,7 @@ def mimetype_from_buffer(stream):
463467 """
464468 return 'application/octet-stream'
465469
470+
466471def ufile_restore_url (bucket , key , upload_suffix = None ):
467472 """
468473 解冻冷存文件的url
@@ -473,6 +478,7 @@ def ufile_restore_url(bucket, key, upload_suffix=None):
473478 """
474479 return 'http://{0}{1}/{2}?restore' .format (bucket , upload_suffix or config .get_default ('upload_suffix' ), key )
475480
481+
476482def ufile_classswitch_url (bucket , key , upload_suffix = None ):
477483 """
478484 文件存储类型转换的url
@@ -483,6 +489,7 @@ def ufile_classswitch_url(bucket, key, upload_suffix=None):
483489 """
484490 return 'http://{0}{1}/{2}' .format (bucket , upload_suffix or config .get_default ('upload_suffix' ), key )
485491
492+
486493def ufile_copy_url (bucket , key , upload_suffix = None ):
487494 """
488495 拷贝文件的url
@@ -493,6 +500,7 @@ def ufile_copy_url(bucket, key, upload_suffix=None):
493500 """
494501 return 'http://{0}{1}/{2}' .format (bucket , upload_suffix or config .get_default ('upload_suffix' ), key )
495502
503+
496504def ufile_rename_url (bucket , key , upload_suffix = None ):
497505 """
498506 重命名文件的url
@@ -504,6 +512,7 @@ def ufile_rename_url(bucket, key, upload_suffix=None):
504512 """
505513 return 'http://{0}{1}/{2}' .format (bucket , upload_suffix or config .get_default ('upload_suffix' ), key )
506514
515+
507516def ufile_listobjects_url (bucket , upload_suffix = None ):
508517 """
509518 获取目录文件列表的url
@@ -513,13 +522,35 @@ def ufile_listobjects_url(bucket, upload_suffix=None):
513522 """
514523 return 'http://{0}{1}/?listobjects' .format (bucket , upload_suffix or config .get_default ('upload_suffix' ))
515524
525+
526+ def ufile_listparts_url (bucket , upload_suffix , upload_id , max_parts = None , part_number_marker = None ):
527+ """
528+ 获取未完成分片上传的对象的已上传成功的分片列表。
529+
530+ :param bucket: string类型, 空间名称
531+ :param upload_suffix: string类型, 域名后缀
532+ :param upload_id: string类型, 初始化分片上传获得的uploadid字符串
533+ :param max_parts: integer类型, 规定在US3响应中的最大Part数目。
534+ :param part_number_marker: integer类型, 指定List的起始位置,只有Part Number数目大于该参数的Part会被列出
535+ """
536+ url = 'http://{0}{1}/?muploadpart&uploadId={2}' .format (bucket , upload_suffix or config .get_default ('upload_suffix' ),
537+ upload_id )
538+ if max_parts is not None :
539+ url += '&max-parts={}' .format (max_parts )
540+ if part_number_marker is not None :
541+ url += '&part-number-marker={}' .format (part_number_marker )
542+ return url
543+
544+
516545def deprecated (message ):
517- def deprecated_decorator (func ):
518- def deprecated_func (* args , ** kwargs ):
519- warnings .warn ("Call to deprecated function {} . -- {}" .format (func .__name__ , message ),
520- category = DeprecationWarning ,
521- stacklevel = 2 )
522- warnings .simplefilter ('default' , DeprecationWarning )
523- return func (* args , ** kwargs )
524- return deprecated_func
525- return deprecated_decorator
546+ def deprecated_decorator (func ):
547+ def deprecated_func (* args , ** kwargs ):
548+ warnings .warn ("Call to deprecated function {} . -- {}" .format (func .__name__ , message ),
549+ category = DeprecationWarning ,
550+ stacklevel = 2 )
551+ warnings .simplefilter ('default' , DeprecationWarning )
552+ return func (* args , ** kwargs )
553+
554+ return deprecated_func
555+
556+ return deprecated_decorator
0 commit comments