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第三方库


热门话题
java静态键入和编写一个简单的矩阵库   java如何最小化层次结构的代码量   这是在Google云数据存储中使用Java按键查询的正确方法吗?   java Android php+mysql+json执行异步任务时出错   java Hadoop Hbase访问被拒绝异常   java如何在json中指定特定的对象路径   JavaSpringJPA/Hibernate在使用@modify和@Query进行特殊更新之前调用完整更新   java多个错误通知   java插入Linkedlist和Node   java将图像放在webview中并调整其宽度   Java没有真实属性的缺点是什么?   java“isGooglePlayServicesAvailable”(此)已被弃用   java托管HIPPO CMS   安卓 Java。网URI构造函数不是编码字符(&C)   java如何用hibernate映射Deque?   java传递枚举类型作为参数   java自由堆大小在Maven中不会增加   java如何使用hashmap和arraylist的循环逻辑?   java如何使用JDBC复制MySql数据库