本文整理汇总了Python中b2handle.handleclient.EUDATHandleClient类的典型用法代码示例。如果您正苦于以下问题:Python EUDATHandleClient类的具体用法?Python EUDATHandleClient怎么用?Python EUDATHandleClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EUDATHandleClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, handle_server_url, username, password, prefix=None, handleowner=None, **config):
'''
Initialize client credentials instance with Handle server url,
username and password.
:param handle_server_url: URL to your handle server
:param username: User information in the format "index:prefix/suffix"
:param password: Password.
:param prefix: Prefix.
:param config: Any key-value pairs added are stored as config.
:raises: HandleSyntaxError
'''
EUDATHandleClient.check_handle_syntax_with_index(username)
self.__handle_server_url = handle_server_url
self.__username = username
self.__password = password
self.__prefix = prefix
self.__handleowner = handleowner
self.__config = None
if len(config) > 0:
self.__config = config
if handleowner is not None:
EUDATHandleClient.check_handle_syntax_with_index(handleowner)
self.__handleowner = handleowner
开发者ID:merretbuurman,项目名称:B2HANDLE,代码行数:25,代码来源:clientcredentials.py
示例2: test_global_resolve
def test_global_resolve(self):
"""Testing if instantiating with default handle server'works
and if a handle is correctly retrieved. """
# Create instance with default server url:
inst = EUDATHandleClient(HTTPS_verify=self.https_verify)
rec = inst.retrieve_handle_record_json(self.handle_global)
self.assertIn("handle", rec, 'Response lacks "handle".')
self.assertIn("responseCode", rec, 'Response lacks "responseCode".')
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:10,代码来源:handleclient_readaccess_test.py
示例3: test_modify_handle_value_without_authentication
def test_modify_handle_value_without_authentication(self):
"""Test if exception when not authenticated."""
log_new_test_case("test_modify_handle_value_without_authentication")
# Test variables
testhandle = self.handle
inst_readonly = EUDATHandleClient(self.url, HTTPS_verify=self.https_verify)
# Run code to be tested + check exception:
log_start_test_code()
with self.assertRaises(HandleAuthenticationError):
inst_readonly.modify_handle_value(testhandle, foo='bar')
log_end_test_code()
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:13,代码来源:handleclient_writeaccess_test.py
示例4: create
def create(args):
"""perform create action"""
try:
# load credentials
credentials = PIDClientCredentials.load_from_JSON(args.credpath)
except CredentialsFormatError:
sys.stdout.write('error')
return
except HandleSyntaxError:
sys.stdout.write('error')
return
# retrieve and set extra values
extra_config = {}
# create a handle to put. Concate the prefix with a new generated suffix
prefix = str(credentials.get_prefix())
uid = uuid.uuid1()
suffix = str(uid)
handle = prefix+"/"+suffix
try:
# setup connection to handle server
client = EUDATHandleClient.instantiate_with_credentials(
credentials,
**extra_config)
except HandleNotFoundException:
sys.stdout.write('error')
return
overwrite=False
result = create_execution(client, handle, args.location, overwrite, args.checksum, args.loc10320, args.extratype)
sys.stdout.write(result)
开发者ID:EUDAT-B2SAFE,项目名称:B2SAFE-core,代码行数:35,代码来源:epicclient2.py
示例5: _check_handle_status
def _check_handle_status(dataset_id):
"""Checks handle exists or not.
:returns: Flag indicating whether handle status is such that it requires fiurther processing
:rtype: bool
"""
# Get handle information.
handle_string = resolve_input(dataset_id)
handle_client = EUDATHandleClient.instantiate_for_read_access()
encoded_dict = handle_client.retrieve_handle_record(handle_string)
# Error if not found.
if encoded_dict is None:
raise exceptions.HandleMismatch('Dataset {} has no published pid handle'.format(dataset_id))
# Reformat handle information.
handle_record = {k.decode('utf8'): v.decode('utf8') for k, v in encoded_dict.items()}
# Error if handle has no test value.
if '_TEST' not in handle_record.keys():
logger.log_pid('Dataset handle does not have test value, assuming not test...')
# raise exceptions.HandleMismatch('TEST VALUE WAS NOT FOUND IN HANDLE, ABORTING....')
else:
# Error if handle record value.
if handle_record['_TEST'].lower() != str(config.pid.is_test).lower():
raise exceptions.HandleMismatch('Dataset {} has mismatched test status [{}] with pid connector'.format(dataset_id, handle_record['_TEST']))
开发者ID:ES-DOC,项目名称:esdoc-errata-ws,代码行数:27,代码来源:pid_sync_handles.py
示例6: test_instantiate_for_read_an_search
def test_instantiate_for_read_an_search(self):
"""Testing if instantiating with default handle server works. """
# Try to create client instance for search without a search URL:
with self.assertRaises(TypeError):
inst = EUDATHandleClient.instantiate_for_read_and_search(
None, 'johndoe', 'passywordy')
开发者ID:EUDAT-B2SAFE,项目名称:B2HANDLE,代码行数:7,代码来源:handleclient_unit_test.py
示例7: test_instantiate_wrong_search_url
def test_instantiate_wrong_search_url(self):
inst = EUDATHandleClient.instantiate_for_read_and_search(
"someurl", "someuser", "somepassword", reverselookup_baseuri="http://something_random_foo_bar"
)
self.assertIsInstance(inst, EUDATHandleClient)
开发者ID:merretbuurman,项目名称:B2HANDLE,代码行数:7,代码来源:handleclient_search_noaccess_test.py
示例8: test_instantiate_with_credentials_config
def test_instantiate_with_credentials_config(self):
"""Test instantiation of client: No exception if password wrong."""
# Test variables
credentials = MagicMock()
config_from_cred = {}
valuefoo = "foo/foo/foo/"
config_from_cred["REST_API_url_extension"] = valuefoo
credentials.get_config = MagicMock(return_value=config_from_cred)
credentials.get_username = MagicMock(return_value=self.user)
credentials.get_password = MagicMock(return_value=self.randompassword)
credentials.get_server_URL = MagicMock(return_value=self.url)
credentials.get_handleowner = MagicMock(return_value=None)
credentials.get_path_to_private_key = MagicMock(return_value=None)
credentials.get_path_to_file_certificate_only = MagicMock(return_value=None)
credentials.get_path_to_file_certificate_and_key = MagicMock(return_value=None)
self.assertEqual(
credentials.get_config()["REST_API_url_extension"], valuefoo, "Config: " + str(credentials.get_config())
)
# Run code to be tested
# Create instance with credentials
with self.assertRaises(GenericHandleError):
inst = EUDATHandleClient.instantiate_with_credentials(credentials, HTTPS_verify=self.https_verify)
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:25,代码来源:handleclient_readaccess_test.py
示例9: test_instantiate_with_username_and_password_noindex
def test_instantiate_with_username_and_password_noindex(self):
# Try to ceate client instance with username and password
with self.assertRaises(HandleSyntaxError):
inst = EUDATHandleClient.instantiate_with_username_and_password(
'someurl', 'johndoe', 'passywordy')
开发者ID:EUDAT-B2SAFE,项目名称:B2HANDLE,代码行数:7,代码来源:handleclient_unit_test.py
示例10: read
def read(args):
"""perform read action"""
try:
# load credentials
credentials = PIDClientCredentials.load_from_JSON(args.credpath)
except CredentialsFormatError:
sys.stdout.write('error')
return
except HandleSyntaxError:
sys.stdout.write('error')
return
# retrieve and set extra values
extra_config = {}
try:
# setup connection to handle server
client = EUDATHandleClient.instantiate_with_credentials(
credentials,
**extra_config)
except HandleNotFoundException:
sys.stdout.write('error')
return
if args.key is None:
result = read_execution(client, args.handle)
else:
result = read_execution(client, args.handle, args.key)
sys.stdout.write(result)
开发者ID:EUDAT-B2SAFE,项目名称:B2SAFE-core,代码行数:31,代码来源:epicclient2.py
示例11: check_issue_pid
def check_issue_pid(self):
# Checking PID HANDLE
print('checkin PIDs')
sleep(5)
handle_client = EUDATHandleClient.instantiate_for_read_access()
self.uid = self.issue['uid']
for line in self.dsets:
print('CHECKING {} ERRATA IDS'.format(line))
exists = False
dataset = line.split('#')
dset_id = dataset[0]
dset_version = dataset[1]
hash_basis = dset_id+'.v'+dset_version
hash_basis_utf8 = hash_basis.encode('utf-8')
handle_string = uuid.uuid3(uuid.NAMESPACE_URL, hash_basis_utf8)
encoded_dict = handle_client.retrieve_handle_record(prefix + str(handle_string))
if encoded_dict is not None:
handle_record = {k.decode('utf8'): v.decode('utf8') for k, v in encoded_dict.items()}
if 'ERRATA_IDS' in handle_record.keys():
for uid in str(handle_record['ERRATA_IDS']).split(';'):
if uid == self.uid:
exists = True
break
if not exists:
print('An error occurred updating handle.')
return exists
开发者ID:ES-DOC,项目名称:esdoc-errata-client,代码行数:26,代码来源:actionwords.py
示例12: test_instantiate_with_credentials_config_override
def test_instantiate_with_credentials_config_override(self):
"""Test instantiation of client: No exception if password wrong."""
# Test variables
credentials = MagicMock()
config_from_cred = {}
valuefoo = 'foo/foo/foo/'
config_from_cred['REST_API_url_extension'] = valuefoo
credentials.get_config = MagicMock(return_value=config_from_cred)
credentials.get_username = MagicMock(return_value=self.user)
credentials.get_password = MagicMock(return_value=self.randompassword)
credentials.get_server_URL = MagicMock(return_value=self.url)
self.assertEqual(credentials.get_config()['REST_API_url_extension'],valuefoo,
'Config: '+str(credentials.get_config()))
# Run code to be tested
# Create instance with credentials
inst = EUDATHandleClient.instantiate_with_credentials(
credentials,
HTTPS_verify=self.https_verify,
REST_API_url_extension='api/handles')
# If this raises an exception, it is because /foo/foo from the
# credentials config was used as path. /foo/foo should be overridden
# by the standard stuff.
# Check desired outcomes
self.assertIsInstance(inst, EUDATHandleClient)
val = self.inst.get_value_from_handle(self.handle, 'test1')
self.assertEqual(val, 'val1',
'Retrieving "test1" should lead to "val1", but it lead to: '+str(val))
开发者ID:TonyWildish,项目名称:B2HANDLE,代码行数:32,代码来源:handleclient_readaccess_test.py
示例13: test_instantiate_with_username_and_wrong_password
def test_instantiate_with_username_and_wrong_password(self):
"""Test instantiation of client: No exception if password wrong."""
# Create client instance with username and password
inst = EUDATHandleClient.instantiate_with_username_and_password(
self.url, self.user, self.randompassword, HTTPS_verify=self.https_verify
)
self.assertIsInstance(inst, EUDATHandleClient)
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:8,代码来源:handleclient_readaccess_test.py
示例14: setUp
def setUp(self):
REQUESTLOGGER.info("\n"+60*"*"+"\nsetUp of EUDATHandleClientWriteaccessTestCase")
self.inst = EUDATHandleClient.instantiate_with_username_and_password(
self.url,
self.user,
self.password,
HTTPS_verify=self.https_verify)
authstring = b2handle.utilhandle.create_authentication_string(self.user, self.password)
self.headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic '+authstring
}
list_of_all_entries = [
{
"index":111,
"type": "TEST1",
"data":{
"format":"string",
"value":"val1"
}
},
{
"index":2222,
"type": "TEST2",
"data":{
"format":"string",
"value":"val2"
}
},
{
"index":333,
"type": "TEST3",
"data":{
"format":"string",
"value":"val3"
}
},
{
"index":4,
"type": "TEST4",
"data":{
"format":"string",
"value":"val4"
}
},
]
testhandle = self.handle
url = self.connector.make_handle_URL(testhandle)
veri = self.https_verify
head = self.headers
data = json.dumps({'values':list_of_all_entries})
resp = requests.put(url, data=data, headers=head, verify=veri)
log_request_response_to_file('PUT', self.handle, url, head, veri, resp)
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:58,代码来源:handleclient_writeaccess_test.py
示例15: test_instantiate_with_username_and_password_inexistentuser
def test_instantiate_with_username_and_password_inexistentuser(self, getpatch):
# Define the replacement for the patched method:
mock_response = MockResponse(notfound=True)
getpatch.return_value = mock_response
with self.assertRaises(HandleNotFoundException):
inst = EUDATHandleClient.instantiate_with_username_and_password(
'http://someurl', '100:john/doe', 'passywordy')
开发者ID:EUDAT-B2SAFE,项目名称:B2HANDLE,代码行数:9,代码来源:handleclient_2_read_patched_unit_test.py
示例16: test_instantiate_for_read_access
def test_instantiate_for_read_access(self):
"""Testing if instantiating with default handle server works
and if a handle is correctly retrieved. """
# Create client instance with username and password
inst = EUDATHandleClient.instantiate_for_read_access(HTTPS_verify=self.https_verify)
rec = self.inst.retrieve_handle_record_json(self.handle)
self.assertIsInstance(inst, EUDATHandleClient)
self.assertIn("handle", rec, 'Response lacks "handle".')
self.assertIn("responseCode", rec, 'Response lacks "responseCode".')
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:10,代码来源:handleclient_readaccess_test.py
示例17: test_instantiate_with_nonexistent_username_and_password
def test_instantiate_with_nonexistent_username_and_password(self):
"""Test instantiation of client: Exception if username does not exist."""
testusername_inexistent = "100:" + self.inexistent_handle
# Run code to be tested + check exception:
with self.assertRaises(HandleNotFoundException):
# Create client instance with username and password
inst = EUDATHandleClient.instantiate_with_username_and_password(
self.url, testusername_inexistent, self.randompassword, HTTPS_verify=self.https_verify
)
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:11,代码来源:handleclient_readaccess_test.py
示例18: test_instantiate_with_username_and_password_wrongpw
def test_instantiate_with_username_and_password_wrongpw(self, getpatch):
# Define the replacement for the patched method:
mock_response = MockResponse(success=True)
getpatch.return_value = mock_response
inst = EUDATHandleClient.instantiate_with_username_and_password(
'http://someurl', '100:my/testhandle', 'passywordy')
self.assertIsInstance(inst, EUDATHandleClient)
开发者ID:EUDAT-B2SAFE,项目名称:B2HANDLE,代码行数:11,代码来源:handleclient_2_read_patched_unit_test.py
示例19: test_instantiate_with_username_without_index_and_password
def test_instantiate_with_username_without_index_and_password(self):
"""Test instantiation of client: Exception if username has no index."""
testusername_without_index = self.user.split(":")[1]
# Run code to be tested + check exception:
with self.assertRaises(HandleSyntaxError):
# Create client instance with username and password
inst = EUDATHandleClient.instantiate_with_username_and_password(
self.url, testusername_without_index, self.randompassword, HTTPS_verify=self.https_verify
)
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:11,代码来源:handleclient_readaccess_test.py
示例20: main
def main():
""" Main function to test the script """
client = EUDATHandleClient.instantiate_for_read_access()
value = client.get_value_from_handle("11100/33ac01fc-6850-11e5-b66e-e41f13eb32b2", "URL")
print value
result = client.search_handle("irods://data.repo.cineca.it:1247/CINECA01/home/cin_staff/rmucci00/DSI_Test/test.txt")
print result
get_pid_info(pid='11100/0beb6af8-cbe5-11e3-a9da-e41f13eb41b2')
开发者ID:EUDAT-B2STAGE,项目名称:EUDAT-Library,代码行数:12,代码来源:getpidinfo.py
注:本文中的b2handle.handleclient.EUDATHandleClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论