本文整理汇总了Python中sword2.Connection.create方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.create方法的具体用法?Python Connection.create怎么用?Python Connection.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sword2.Connection
的用法示例。
在下文中一共展示了Connection.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_15_retrieve_content_em_iri_as_feed
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [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_15_Metadata_POST_to_sss_w_coliri
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_15_Metadata_POST_to_sss_w_coliri(self):
conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
dr = conn.create(metadata_entry = e,
col_iri = conn.sd.workspaces[0][1][0].href,
in_progress=True)
assert dr.code == 201
示例3: test_17_advanced_replace_file_content
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_17_advanced_replace_file_content(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
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)
# now do the replace
with open(PACKAGE) as pkg:
new_receipt = conn.update(dr = receipt,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="update.zip",
packaging='http://purl.org/net/sword/package/SimpleZip',
metadata_relevant=True)
assert new_receipt.code == 204
assert new_receipt.dom is None
示例4: test_31_delete_container
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_31_delete_container(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO,
error_response_raises_exceptions=False)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
#e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
#metadata_entry = e,
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)
edit_iri = receipt.location
receipt = conn.get_deposit_receipt(edit_iri)
# delete the container
new_receipt = conn.delete_container(dr=receipt)
assert new_receipt.code == 204
assert new_receipt.dom is None
# the next check is that this 404s appropriately now
another_receipt = conn.get_deposit_receipt(edit_iri)
示例5: __init__
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def __init__(self, owner):
raise NotImplementedError
c = Connection(SD_URI, user_name = owner.username, user_pass=owner.password)
c.get_service_document()
# pick the first collection within the first workspace:
workspace_1_title, workspace_1_collections = c.workspaces[0]
collection = workspace_1_collections[0]
# upload "package.zip" to this collection as a new (binary) resource:
with open("package.zip", "r") as pkg:
receipt = c.create(col_iri = collection.href,
payload = pkg,
mimetype = "application/zip",
filename = "package.zip",
packaging = 'http://purl.org/net/sword/package/Binary',
in_progress = True) # As the deposit isn't yet finished
# Add a metadata record to this newly created resource (or 'container')
from sword2 import Entry
# Entry can be passed keyword parameters to add metadata to the entry (namespace + '_' + tagname)
e = Entry(id="atomid",
title="atom-title",
dcterms_abstract = "Info about the resource....",
)
# to add a new namespace:
e.register_namespace('skos', 'http://www.w3.org/2004/02/skos/core#')
e.add_field("skos_Concept", "...")
# Update the metadata entry to the resource:
updated_receipt = c.update(metadata_entry = e,
dr = receipt, # use the receipt to discover the right URI to use
in_progress = False) # finish the deposit
示例6: preflight_submission
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def preflight_submission(self):
opener = self.get_opener()
conn = Connection(self.sword2_sd_url, error_response_raises_exceptions=False, http_impl=UrlLib2Layer(opener))
logger.debug("Retrieving the service document")
conn.get_service_document()
logger.debug("Retrieved the service document")
self.assertIsNotNone(conn.sd)
self.assertIsNotNone(conn.sd.workspaces)
self.assertNotEqual(len(conn.sd.workspaces),0)
workspace = conn.sd.workspaces[0][1]
# we require there to be at least one collection
self.assertNotEqual(len(workspace),0)
col = workspace[0]
testid = "testid_"+str(uuid.uuid4())
logger.debug("col iri = " + str(col.href))
e = Entry(id=testid, title="test title", dcterms_abstract="test description")
print str(e)
receipt = conn.create(col_iri=col.href, metadata_entry=e, suggested_identifier=testid)
#col.href=http://192.168.2.237/swordv2/silo/test-silo
self.assertIsNotNone(receipt)
self.assertEquals(receipt.code,201)
return receipt.location
示例7: test_30_advanced_add_multipart
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_30_advanced_add_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
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)
ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
dcterms_creator="Me!", dcterms_rights="CC0")
with open(PACKAGE) as pkg:
new_receipt = conn.append(dr=receipt,
metadata_entry=ne,
payload=pkg,
filename="addition.zip",
mimetype=PACKAGE_MIME,
packaging="http://purl.org/net/sword/package/SimpleZip",
in_progress=True,
metadata_relevant=True)
assert new_receipt.code >= 200 and new_receipt.code < 400
示例8: test_21_advanced_replace_with_multipart
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_21_advanced_replace_with_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
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)
# now do the replace
ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
with open(PACKAGE) as pkg:
new_receipt = conn.update(dr = receipt,
metadata_entry = ne,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="update.zip",
packaging='http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
assert new_receipt.code == 204 or new_receipt.code == 200
if new_receipt.code == 204:
assert new_receipt.dom is None
if new_receipt.code == 200:
assert new_receipt.parsed == True
assert new_receipt.valid == True
示例9: test_12_Metadata_POST_to_sss
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_12_Metadata_POST_to_sss(self):
conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
resp = conn.create(metadata_entry = e,
workspace='Main Site',
collection=conn.sd.workspaces[0][1][0].title,
in_progress=True)
assert resp != None
示例10: preflight_submission
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def preflight_submission(self, dataset, opener, repository, silo ):
logger.debug("Carrying out pre-flight submission")
# verify that we can get a service document, and that there
# is at least one silo and that we can authenticate
if repository.sword2_sd_url is None:
raise SwordServiceError("No sword2 service-document URL for repository configuration")
# get the service document (for which we must be authenticated)
conn = Connection(repository.sword2_sd_url, error_response_raises_exceptions=False, http_impl=UrlLib2Layer(opener))
conn.get_service_document()
# we require there to be at least one workspace
if conn.sd is None:
raise SwordServiceError("did not successfully retrieve a service document")
if conn.sd.workspaces is None:
raise SwordServiceError("no workspaces defined in service document")
if len(conn.sd.workspaces) == 0:
raise SwordServiceError("no workspaces defined in service document")
workspace = conn.sd.workspaces[0][1]
# we require there to be at least one collection
if len(workspace) == 0:
raise SwordServiceError("no collections defined in workspace")
# FIXME: we don't currently have a mechanism to make decisions about
# which collection to put stuff in, so we just put stuff in the first
# one for the time being
col = workspace[0]
silohref = repository.homepage + "swordv2/silo/" + silo
# assemble the entry ready for deposit, using the basic metadata
# FIXME: is there anything further we need to do about the metadata here?
e = Entry(id=dataset.identifier, title=dataset.title, dcterms_abstract=dataset.description)
# create the item using the metadata-only approach (suppress errors along the way,
# we'll check for them below)
#receipt = conn.create(col_iri=col.href, metadata_entry=e, suggested_identifier=dataset.identifier)
logger.debug( "Deposit is being created" )
receipt = conn.create(col_iri=silohref, metadata_entry=e, suggested_identifier=dataset.identifier)
logger.debug( "Deposit created" )
# check for errors
if receipt.code >= 400:
# this is an error
logger.debug("Received error message from server: " + receipt.to_xml())
if receipt.error_href == "http://databank.ox.ac.uk/errors/DatasetConflict":
raise SwordSlugRejected()
raise SwordDepositError(receipt)
logger.debug("Deposit carried out to: " + receipt.location)
# return receipt.location
return (receipt.alternate,receipt.location)
示例11: test_34_check_metadata_only_state
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_34_check_metadata_only_state(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
receipt = conn.create(col_iri = col.href, metadata_entry = e)
statement = conn.get_ore_sword_statement(receipt.ore_statement_iri)
assert len(statement.states) == 1
assert statement.states[0][0] == "http://databank.ox.ac.uk/state/EmptyContainer"
示例12: test_06_Simple_POST_to_sss
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_06_Simple_POST_to_sss(self):
conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
resp = conn.create(payload = "Payload is just a load of text",
mimetype = "text/plain",
filename = "readme.txt",
packaging = 'http://purl.org/net/sword/package/Binary',
workspace = 'Main Site',
collection = conn.sd.workspaces[0][1][0].title,
in_progress=True,
metadata_entry=None)
assert resp.code == 201
示例13: test_08_Simple_POST_to_sss_w_coliri
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_08_Simple_POST_to_sss_w_coliri(self):
conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
resp = 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 = conn.sd.workspaces[0][1][0].href,
in_progress=True,
metadata_entry=None)
assert resp.code == 201
示例14: test_07_Multipart_POST_to_sss
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_07_Multipart_POST_to_sss(self):
conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
resp = conn.create(payload = "Multipart payload here",
metadata_entry = e,
mimetype = "text/plain",
filename = "readme.txt",
packaging = 'http://purl.org/net/sword/package/Binary',
workspace='Main Site',
collection=conn.sd.workspaces[0][1][0].title,
in_progress=True)
assert resp.code == 201
示例15: test_22_Create_deposit_and_delete_deposit
# 需要导入模块: from sword2 import Connection [as 别名]
# 或者: from sword2.Connection import create [as 别名]
def test_22_Create_deposit_and_delete_deposit(self):
conn = Connection("http://localhost:%s/sd-uri" % PORT_NUMBER, user_name="sword", user_pass="sword", download_service_document=True)
e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
deposit_receipt = conn.create(payload = "Multipart_POST_then_update_on_EM_IRI",
metadata_entry = e,
mimetype = "text/plain",
filename = "readme.txt",
packaging = 'http://purl.org/net/sword/package/Binary',
col_iri = conn.sd.workspaces[0][1][0].href,
in_progress=True)
assert deposit_receipt.edit != None
dr = conn.delete(resource_iri = deposit_receipt.edit)
assert dr.code == 204 or dr.code == 200