SWORDv3客户端库

sword3client的Python项目详细描述


SWORDv3客户端

Documentation Status

这个客户机库将SWORDv3的所有基本特性作为Python API提供。在

示例用法

创建客户端的新实例

fromsword3clientimportSWORD3Clientclient=SWORD3Client()

有关所有可用操作的详细信息,请参见对象定义。常见用法有:

  • 仅使用元数据创建对象:
^{pr2}$
  • 使用包创建对象:
fromsword3commonimportconstantsfromsword3clientimportSWORD3Clientclient=SWORD3Client()package_path="/path/to/file.zip"digest={constants.DIGEST_SHA_256:"digest...."}SERVICE="http://example.com/service-document"withopen(package_path,"rb")asstream:response=client.create_object_with_package(SERVICE,stream,"test.zip",digest,content_type="application/zip",packaging=constants.PACKAGE_SWORDBAGIT,)
  • 检索对象的状态:
fromsword3clientimportSWORD3Clientclient=SWORD3Client()OBJ_URL="http://example.com/object/1"status=client.get_object(OBJ_URL)
  • 附加二进制文件:
fromsword3clientimportSWORD3Clientclient=SWORD3Client()OBJ_URL="http://example.com/object/1"file_path="/path/to/binary.bin"digest={sword3common.constants.DIGEST_SHA_256:"digest...."}withopen(file_path,"rb")asstream:response=client.add_binary(OBJ_URL,stream,"test.bin",digest)
  • 删除对象:
fromsword3clientimportSWORD3Clientclient=SWORD3Client()OBJ_URL="http://example.com/object/1"response=client.delete_object(OBJ_URL)
  • 通过引用创建对象:
fromsword3commonimportByReferencefromsword3clientimportSWORD3Clientclient=SWORD3Client()SERVICE="http://example.com/service-document"br=ByReference()br.add_file("http://example.com/file.pdf","file.pdf","application/pdf",True)response=client.create_object_by_reference(SERVICE,br)
  • 分段上传大文件
fromioimportBytesIOfromsword3commonimportconstantsfromsword3clientimportSWORD3Clientclient=SWORD3Client()SERVICE="http://example.com/service-document"FILE_SIZE=1000000SEGMENT_COUNT=10SEGMENT_SIZE=100000DIGEST={constants.DIGEST_SHA_256:"digest...."}LARGE_FILE="/path/to/large/file.zip"# get the service document, which tells us important details on segmented uploadsservice_document=client.get_service(SERVICE)# initialise the upload, to get a temporary urlresp=client.initialise_segmented_upload(service_document,assembled_size=FILE_SIZE,segment_count=SEGMENT_COUNT,segment_size=SEGMENT_SIZE,digest=DIGEST)temporary_url=resp.location# send each segment to the temporary urlwithopen(LARGE_FILE,"rb")asf:foriinrange(SEGMENT_COUNT):segment=f.read(SEGMENT_SIZE)stream=BytesIO(segment)segment_response=client.upload_file_segment(temporary_url,stream,i)
  • 检索有关分段上载的信息
fromsword3clientimportSWORD3Clientclient=SWORD3Client()# Temporary URL obtained from initialisation of segmented upload step (see above)TEMPORARY_URL="http://example.com/temporary_url"upload_status=client.segmented_upload_status(TEMPORARY_URL)print(upload_status.received)print(upload_status.expecting)print(upload_status.size)print(upload_status.segment_size)
  • 存放分段上传的文件
fromsword3clientimportSWORD3Clientclient=SWORD3Client()SERVICE="http://example.com/service-document"# Temporary URL obtained from initialisation of segmented upload step (see above)TEMPORARY_URL="http://example.com/temporary_url"resp=client.create_object_with_temporary_file(SERVICE,TEMPORARY_URL,"test.zip","application/zip")

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何在JavaSpring引导应用程序中合并两个对象?   java序列化与防止按钮、链接等被点击两次有关吗?   java CORBA序列:我可以用方法定义对象序列吗?   java没有SonarQube的Spring批处理项目的代码覆盖   java如何在eclipse中删除上述方法和属性的搜索引用链接   spring boot如何在java注释中使用泛型T类型?   java导入外部(未编译)groovy类,并将它们保留在jar之外   如何在int[]Java中找到所有值的总和?   Java在ArrayList中删除重复项的问题   Java更改菜单栏、项目背景和文本颜色   网络设置网络。使用Elasticsearch JAVA API将主机发布到客户端节点   Python到Java加密/解密,确保密码匹配?   java Faing在Ubuntu12.04上构建eucalyptus的困难   java使用org。阿帕奇。平民fileupload在mysql数据库中上传图像,但调用servlet会得到一个空白的白页