本文整理汇总了Python中sword2.Connection.get_resource方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.get_resource方法的具体用法?Python Connection.get_resource怎么用?Python Connection.get_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sword2.Connection
的用法示例。
在下文中一共展示了Connection.get_resource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_15_retrieve_content_em_iri_as_feed
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import get_resource [as 别名]
def test_15_retrieve_content_em_iri_as_feed(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# we're going to work with the edit_media_feed iri
assert receipt.edit_media_feed is not None
response = conn.get_resource(content_iri=receipt.edit_media_feed)
assert response.code == 200
assert response.content is not None
# the response should be an xml document, so let's see if we can parse
# it. This should give us an exception which will fail the test if not
dom = etree.fromstring(response.content)
示例2: test_17_Simple_POST_and_GET
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import get_resource [as 别名]
def test_17_Simple_POST_and_GET(self):
conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
col_iri = conn.sd.workspaces[0][1][0].href # pick the first collection
dr = conn.create(payload = "Simple_POST_and_GET",
mimetype = "text/plain",
filename = "readme.txt",
packaging = 'http://purl.org/net/sword/package/Binary',
col_iri = col_iri,
in_progress=True,
metadata_entry=None)
assert dr.code == 201
# Now to GET that resource with no prescribed for packaging
content_object = conn.get_resource(dr.cont_iri)
# Can't guarantee that sss.py won't mangle submissions, so can't validate response at this moment
assert content_object != None
示例3: test_14_Invalid_Packaging_cached_receipt
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import get_resource [as 别名]
def test_14_Invalid_Packaging_cached_receipt(self):
conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True, honour_receipts=True)
col_iri = conn.sd.workspaces[0][1][0].href # pick the first collection
dr = conn.create(payload = "Payload is just a load of text",
mimetype = "text/plain",
filename = "readme.txt",
packaging = 'http://purl.org/net/sword/package/Binary',
col_iri = col_iri,
in_progress=True)
# Now to GET that resource with invalid packaging
try:
content = conn.get_resource(dr.cont_iri, packaging="foofar")
assert 1 == 0 # fail
except PackagingFormatNotAvailable:
# test the 'honour_receipts' flag and cached deposit
pass
示例4: test_14_error_retrieve_content_em_iri
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import get_resource [as 别名]
def test_14_error_retrieve_content_em_iri(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
error_response_raises_exceptions=False)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
error = 'http://purl.org/net/sword/package/IJustMadeThisUp'
response = conn.get_resource(content_iri=receipt.edit_media, packaging=error)
assert response.code == 406
assert isinstance(response, Error_Document)
assert response.error_href == "http://purl.org/net/sword/error/ErrorContent"
示例5: test_12_basic_retrieve_content_em_iri
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import get_resource [as 别名]
def test_12_basic_retrieve_content_em_iri(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# we're going to work with the edit_media iri
assert receipt.edit_media is not None
resource = conn.get_resource(content_iri=receipt.edit_media)
assert resource.code == 200
assert resource.content is not None
示例6: test_13_advanced_retrieve_content_em_iri
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import get_resource [as 别名]
def test_13_advanced_retrieve_content_em_iri(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
packaging = 'http://purl.org/net/sword/package/SimpleZip'
if receipt.packaging is not None and len(receipt.packaging) > 0:
packaging = receipt.packaging[0]
resource = conn.get_resource(content_iri=receipt.edit_media, packaging=packaging, on_behalf_of=SSS_OBO)
assert resource.code == 200
assert resource.content is not None