rucio-clients 35.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rucio-clients might be problematic. Click here for more details.
- rucio/__init__.py +17 -0
- rucio/alembicrevision.py +15 -0
- rucio/client/__init__.py +15 -0
- rucio/client/accountclient.py +433 -0
- rucio/client/accountlimitclient.py +183 -0
- rucio/client/baseclient.py +974 -0
- rucio/client/client.py +76 -0
- rucio/client/configclient.py +126 -0
- rucio/client/credentialclient.py +59 -0
- rucio/client/didclient.py +866 -0
- rucio/client/diracclient.py +56 -0
- rucio/client/downloadclient.py +1785 -0
- rucio/client/exportclient.py +44 -0
- rucio/client/fileclient.py +50 -0
- rucio/client/importclient.py +42 -0
- rucio/client/lifetimeclient.py +90 -0
- rucio/client/lockclient.py +109 -0
- rucio/client/metaconventionsclient.py +140 -0
- rucio/client/pingclient.py +44 -0
- rucio/client/replicaclient.py +454 -0
- rucio/client/requestclient.py +125 -0
- rucio/client/rseclient.py +746 -0
- rucio/client/ruleclient.py +294 -0
- rucio/client/scopeclient.py +90 -0
- rucio/client/subscriptionclient.py +173 -0
- rucio/client/touchclient.py +82 -0
- rucio/client/uploadclient.py +955 -0
- rucio/common/__init__.py +13 -0
- rucio/common/cache.py +74 -0
- rucio/common/config.py +801 -0
- rucio/common/constants.py +159 -0
- rucio/common/constraints.py +17 -0
- rucio/common/didtype.py +189 -0
- rucio/common/exception.py +1151 -0
- rucio/common/extra.py +36 -0
- rucio/common/logging.py +420 -0
- rucio/common/pcache.py +1408 -0
- rucio/common/plugins.py +153 -0
- rucio/common/policy.py +84 -0
- rucio/common/schema/__init__.py +150 -0
- rucio/common/schema/atlas.py +413 -0
- rucio/common/schema/belleii.py +408 -0
- rucio/common/schema/domatpc.py +401 -0
- rucio/common/schema/escape.py +426 -0
- rucio/common/schema/generic.py +433 -0
- rucio/common/schema/generic_multi_vo.py +412 -0
- rucio/common/schema/icecube.py +406 -0
- rucio/common/stomp_utils.py +159 -0
- rucio/common/stopwatch.py +55 -0
- rucio/common/test_rucio_server.py +148 -0
- rucio/common/types.py +403 -0
- rucio/common/utils.py +2238 -0
- rucio/rse/__init__.py +96 -0
- rucio/rse/protocols/__init__.py +13 -0
- rucio/rse/protocols/bittorrent.py +184 -0
- rucio/rse/protocols/cache.py +122 -0
- rucio/rse/protocols/dummy.py +111 -0
- rucio/rse/protocols/gfal.py +703 -0
- rucio/rse/protocols/globus.py +243 -0
- rucio/rse/protocols/gsiftp.py +92 -0
- rucio/rse/protocols/http_cache.py +82 -0
- rucio/rse/protocols/mock.py +123 -0
- rucio/rse/protocols/ngarc.py +209 -0
- rucio/rse/protocols/posix.py +250 -0
- rucio/rse/protocols/protocol.py +594 -0
- rucio/rse/protocols/rclone.py +364 -0
- rucio/rse/protocols/rfio.py +136 -0
- rucio/rse/protocols/srm.py +338 -0
- rucio/rse/protocols/ssh.py +413 -0
- rucio/rse/protocols/storm.py +206 -0
- rucio/rse/protocols/webdav.py +550 -0
- rucio/rse/protocols/xrootd.py +301 -0
- rucio/rse/rsemanager.py +764 -0
- rucio/vcsversion.py +11 -0
- rucio/version.py +38 -0
- rucio_clients-35.7.0.data/data/etc/rse-accounts.cfg.template +25 -0
- rucio_clients-35.7.0.data/data/etc/rucio.cfg.atlas.client.template +42 -0
- rucio_clients-35.7.0.data/data/etc/rucio.cfg.template +257 -0
- rucio_clients-35.7.0.data/data/requirements.client.txt +15 -0
- rucio_clients-35.7.0.data/data/rucio_client/merge_rucio_configs.py +144 -0
- rucio_clients-35.7.0.data/scripts/rucio +2542 -0
- rucio_clients-35.7.0.data/scripts/rucio-admin +2447 -0
- rucio_clients-35.7.0.dist-info/METADATA +50 -0
- rucio_clients-35.7.0.dist-info/RECORD +88 -0
- rucio_clients-35.7.0.dist-info/WHEEL +5 -0
- rucio_clients-35.7.0.dist-info/licenses/AUTHORS.rst +97 -0
- rucio_clients-35.7.0.dist-info/licenses/LICENSE +201 -0
- rucio_clients-35.7.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Copyright European Organization for Nuclear Research (CERN) since 2012
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import enum
|
|
16
|
+
from collections import namedtuple
|
|
17
|
+
from typing import Literal, get_args
|
|
18
|
+
|
|
19
|
+
from rucio.common.config import config_get_bool
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
Constants.
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
RESERVED_KEYS = ['scope', 'name', 'account', 'did_type', 'is_open', 'monotonic', 'obsolete', 'complete',
|
|
27
|
+
'availability', 'suppressed', 'bytes', 'length', 'md5', 'adler32', 'rule_evaluation_action',
|
|
28
|
+
'rule_evaluation_required', 'expired_at', 'deleted_at', 'created_at', 'updated_at']
|
|
29
|
+
# collection_keys =
|
|
30
|
+
# file_keys =
|
|
31
|
+
|
|
32
|
+
KEY_TYPES = ['ALL', 'COLLECTION', 'FILE', 'DERIVED']
|
|
33
|
+
# all(container, dataset, file), collection(dataset or container), file, derived(compute from file for collection)
|
|
34
|
+
|
|
35
|
+
SCHEME_MAP = {'srm': ['srm', 'gsiftp'],
|
|
36
|
+
'gsiftp': ['srm', 'gsiftp'],
|
|
37
|
+
'https': ['https', 'davs', 'srm+https', 'cs3s'],
|
|
38
|
+
'davs': ['https', 'davs', 'srm+https', 'cs3s'],
|
|
39
|
+
'srm+https': ['https', 'davs', 'srm+https', 'cs3s'],
|
|
40
|
+
'cs3s': ['https', 'davs', 'srm+https', 'cs3s'],
|
|
41
|
+
'root': ['root'],
|
|
42
|
+
'scp': ['scp'],
|
|
43
|
+
'rsync': ['rsync'],
|
|
44
|
+
'rclone': ['rclone']}
|
|
45
|
+
if config_get_bool('transfers', 'srm_https_compatibility', raise_exception=False, default=False):
|
|
46
|
+
SCHEME_MAP['srm'].append('https')
|
|
47
|
+
SCHEME_MAP['https'].append('srm')
|
|
48
|
+
SCHEME_MAP['srm'].append('davs')
|
|
49
|
+
SCHEME_MAP['davs'].append('srm')
|
|
50
|
+
|
|
51
|
+
SORTING_ALGORITHMS_LITERAL = Literal['geoip', 'closeness', 'custom_table', 'dynamic', 'ranking', 'random']
|
|
52
|
+
SORTING_ALGORITHMS = list(get_args(SORTING_ALGORITHMS_LITERAL))
|
|
53
|
+
|
|
54
|
+
SUPPORTED_PROTOCOLS_LITERAL = Literal['gsiftp', 'srm', 'root', 'davs', 'http', 'https', 'file', 'storm', 'srm+https', 'scp', 'rsync', 'rclone', 'magnet']
|
|
55
|
+
SUPPORTED_PROTOCOLS: list[str] = list(get_args(SUPPORTED_PROTOCOLS_LITERAL))
|
|
56
|
+
|
|
57
|
+
RSE_SUPPORTED_PROTOCOL_DOMAINS_LITERAL = Literal['ALL', 'LAN', 'WAN']
|
|
58
|
+
|
|
59
|
+
RSE_SUPPORTED_PROTOCOL_OPERATIONS_LITERAL = Literal['read', 'write', 'delete', 'third_party_copy_read', 'third_party_copy_write']
|
|
60
|
+
RSE_SUPPORTED_PROTOCOL_OPERATIONS: list[str] = list(get_args(RSE_SUPPORTED_PROTOCOL_OPERATIONS_LITERAL))
|
|
61
|
+
|
|
62
|
+
FTS_STATE = namedtuple('FTS_STATE', ['SUBMITTED', 'READY', 'ACTIVE', 'FAILED', 'FINISHED', 'FINISHEDDIRTY', 'NOT_USED',
|
|
63
|
+
'CANCELED'])('SUBMITTED', 'READY', 'ACTIVE', 'FAILED', 'FINISHED', 'FINISHEDDIRTY',
|
|
64
|
+
'NOT_USED', 'CANCELED')
|
|
65
|
+
|
|
66
|
+
FTS_COMPLETE_STATE = namedtuple('FTS_COMPLETE_STATE', ['OK', 'ERROR'])('Ok', 'Error')
|
|
67
|
+
|
|
68
|
+
# https://gitlab.cern.ch/fts/fts3/-/blob/master/src/db/generic/Job.h#L41
|
|
69
|
+
FTS_JOB_TYPE = namedtuple('FTS_JOB_TYPE', ['MULTIPLE_REPLICA', 'MULTI_HOP', 'SESSION_REUSE', 'REGULAR'])('R', 'H', 'Y', 'N')
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# Messages constants
|
|
73
|
+
|
|
74
|
+
MAX_MESSAGE_LENGTH = 4000
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class SuspiciousAvailability(enum.Enum):
|
|
78
|
+
ALL = 0
|
|
79
|
+
EXIST_COPIES = 1
|
|
80
|
+
LAST_COPY = 2
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ReplicaState(enum.Enum):
|
|
84
|
+
# From rucio.db.sqla.constants, update that file at the same time as this
|
|
85
|
+
AVAILABLE = 'A'
|
|
86
|
+
UNAVAILABLE = 'U'
|
|
87
|
+
COPYING = 'C'
|
|
88
|
+
BEING_DELETED = 'B'
|
|
89
|
+
BAD = 'D'
|
|
90
|
+
TEMPORARY_UNAVAILABLE = 'T'
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@enum.unique
|
|
94
|
+
class HermesService(str, enum.Enum):
|
|
95
|
+
"""
|
|
96
|
+
The services supported by Hermes2.
|
|
97
|
+
"""
|
|
98
|
+
INFLUX = "INFLUX"
|
|
99
|
+
ELASTIC = "ELASTIC"
|
|
100
|
+
EMAIL = "EMAIL"
|
|
101
|
+
ACTIVEMQ = "ACTIVEMQ"
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class RseAttr:
|
|
105
|
+
|
|
106
|
+
"""
|
|
107
|
+
List of functional RSE attributes.
|
|
108
|
+
|
|
109
|
+
This class acts as a namespace containing all RSE attributes referenced in
|
|
110
|
+
the Rucio source code. Setting them affects Rucio's behaviour in some way.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
ARCHIVE_TIMEOUT = 'archive_timeout'
|
|
114
|
+
ASSOCIATED_SITES = 'associated_sites'
|
|
115
|
+
AUTO_APPROVE_BYTES = 'auto_approve_bytes'
|
|
116
|
+
AUTO_APPROVE_FILES = 'auto_approve_files'
|
|
117
|
+
BITTORRENT_TRACKER_ADDR = 'bittorrent_tracker_addr'
|
|
118
|
+
BLOCK_MANUAL_APPROVAL = 'block_manual_approval'
|
|
119
|
+
COUNTRY = 'country'
|
|
120
|
+
DECOMMISSION = 'decommission'
|
|
121
|
+
DEFAULT_ACCOUNT_LIMIT_BYTES = 'default_account_limit_bytes'
|
|
122
|
+
FTS = 'fts'
|
|
123
|
+
GLOBUS_ENDPOINT_ID = 'globus_endpoint_id'
|
|
124
|
+
GREEDYDELETION = 'greedyDeletion'
|
|
125
|
+
IS_OBJECT_STORE = 'is_object_store'
|
|
126
|
+
LFN2PFN_ALGORITHM = 'lfn2pfn_algorithm'
|
|
127
|
+
MAXIMUM_PIN_LIFETIME = 'maximum_pin_lifetime'
|
|
128
|
+
MULTIHOP_TOMBSTONE_DELAY = 'multihop_tombstone_delay'
|
|
129
|
+
NAMING_CONVENTION = 'naming_convention'
|
|
130
|
+
OIDC_BASE_PATH = 'oidc_base_path'
|
|
131
|
+
OIDC_SUPPORT = 'oidc_support'
|
|
132
|
+
PHYSGROUP = 'physgroup'
|
|
133
|
+
QBITTORRENT_MANAGEMENT_ADDRESS = 'qbittorrent_management_address'
|
|
134
|
+
RESTRICTED_READ = 'restricted_read'
|
|
135
|
+
RESTRICTED_WRITE = 'restricted_write'
|
|
136
|
+
RULE_APPROVERS = 'rule_approvers'
|
|
137
|
+
S3_URL_STYLE = 's3_url_style'
|
|
138
|
+
SIGN_URL = 'sign_url'
|
|
139
|
+
SIMULATE_MULTIRANGE = 'simulate_multirange'
|
|
140
|
+
SITE = 'site'
|
|
141
|
+
SKIP_UPLOAD_STAT = 'skip_upload_stat'
|
|
142
|
+
SOURCE_FOR_TOTAL_SPACE = 'source_for_total_space'
|
|
143
|
+
SOURCE_FOR_USED_SPACE = 'source_for_used_space'
|
|
144
|
+
STAGING_BUFFER = 'staging_buffer'
|
|
145
|
+
STAGING_REQUIRED = 'staging_required'
|
|
146
|
+
STRICT_COPY = 'strict_copy'
|
|
147
|
+
TOMBSTONE_DELAY = 'tombstone_delay'
|
|
148
|
+
TYPE = 'type'
|
|
149
|
+
USE_IPV4 = 'use_ipv4'
|
|
150
|
+
VERIFY_CHECKSUM = 'verify_checksum'
|
|
151
|
+
|
|
152
|
+
# The following RSE attributes are exclusively used in the permission layer
|
|
153
|
+
# and are likely VO-specific.
|
|
154
|
+
|
|
155
|
+
BLOCK_MANUAL_APPROVE = 'block_manual_approve'
|
|
156
|
+
CMS_TYPE = 'cms_type'
|
|
157
|
+
DEFAULT_LIMIT_FILES = 'default_limit_files'
|
|
158
|
+
QUOTA_APPROVERS = 'quota_approvers'
|
|
159
|
+
RULE_DELETERS = 'rule_deleters'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright European Organization for Nuclear Research (CERN) since 2012
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# List of authorized value types for key
|
|
16
|
+
AUTHORIZED_VALUE_TYPES = (float, int, str)
|
|
17
|
+
STRING_TYPES = (str, )
|
rucio/common/didtype.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Copyright European Organization for Nuclear Research (CERN) since 2012
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
DID type to represent a did and to simplify operations on it
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from typing import Union
|
|
20
|
+
|
|
21
|
+
from rucio.common.exception import DIDError
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DID:
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
Class used to store a DID
|
|
28
|
+
Given an object did of type DID
|
|
29
|
+
scope is stored in did.scope
|
|
30
|
+
name is stored in did.name
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
SCOPE_SEPARATOR = ':'
|
|
34
|
+
IMPLICIT_SCOPE_SEPARATOR = '.'
|
|
35
|
+
IMPLICIT_SCOPE_TO_LEN = {'user': 2, 'group': 2}
|
|
36
|
+
__slots__ = ['scope', 'name']
|
|
37
|
+
|
|
38
|
+
def __init__(self, *args, **kwargs):
|
|
39
|
+
"""
|
|
40
|
+
Constructs the DID object. Possible parameter combinations are:
|
|
41
|
+
DID()
|
|
42
|
+
DID('scope:name.did.str')
|
|
43
|
+
DID('user.implicit.scope.in.name')
|
|
44
|
+
DID('custom.scope', 'custom.name')
|
|
45
|
+
DID(['list.scope', 'list.name'])
|
|
46
|
+
DID(('tuple.scope', 'tuple.name'))
|
|
47
|
+
DID({'scope': 'dict.scope', 'name': 'dict.name'})
|
|
48
|
+
DID(scope='kw.scope')
|
|
49
|
+
DID(name='kw.name')
|
|
50
|
+
DID(name='user.kw.implicit.scope')
|
|
51
|
+
DID(scope='kw.scope', name='kw.name')
|
|
52
|
+
DID(did={'scope': 'kw.did.scope', 'name': 'kw.did.name'})
|
|
53
|
+
DID(did=['kw.list.scope', 'kw.list.name'])
|
|
54
|
+
DID(did=('kw.tuple.scope', 'kw.tuple.name'))
|
|
55
|
+
DID('arg.scope', name='kwarg.name')
|
|
56
|
+
DID('arg.name', scope='kwarg.scope')
|
|
57
|
+
"""
|
|
58
|
+
self.scope: str = ''
|
|
59
|
+
self.name: str = ''
|
|
60
|
+
|
|
61
|
+
num_args = len(args)
|
|
62
|
+
num_kwargs = len(kwargs)
|
|
63
|
+
if (num_args + num_kwargs) > 2:
|
|
64
|
+
raise DIDError('Constructor takes at most 2 arguments. Given number: {}'.format(num_args + num_kwargs))
|
|
65
|
+
|
|
66
|
+
did: Union["DID", str, tuple[str, str], list[str], dict[str, str]] = ''
|
|
67
|
+
if num_args == 1:
|
|
68
|
+
did = args[0]
|
|
69
|
+
|
|
70
|
+
if num_kwargs == 1:
|
|
71
|
+
if isinstance(did, str):
|
|
72
|
+
k, v = next(iter(kwargs.items()))
|
|
73
|
+
if k == 'scope':
|
|
74
|
+
did = (v, did)
|
|
75
|
+
elif k == 'name':
|
|
76
|
+
did = (did, v)
|
|
77
|
+
else:
|
|
78
|
+
raise DIDError('Constructor got unexpected keyword argument: {}'.format(k))
|
|
79
|
+
else:
|
|
80
|
+
raise DIDError('First argument of constructor is expected to be string type'
|
|
81
|
+
'when keyword argument is given. Given type: {}'.format(type(did)))
|
|
82
|
+
elif num_args == 0:
|
|
83
|
+
did = kwargs.get('did', kwargs)
|
|
84
|
+
else:
|
|
85
|
+
did = args
|
|
86
|
+
|
|
87
|
+
if isinstance(did, dict):
|
|
88
|
+
self.scope = did.get('scope', '')
|
|
89
|
+
self.name = did.get('name', '')
|
|
90
|
+
if not self.has_scope():
|
|
91
|
+
self.update_implicit_scope()
|
|
92
|
+
elif isinstance(did, tuple) or isinstance(did, list):
|
|
93
|
+
if len(did) != 2:
|
|
94
|
+
raise DIDError('Construction from tuple or list requires exactly 2 elements')
|
|
95
|
+
self.scope = did[0]
|
|
96
|
+
self.name = did[1]
|
|
97
|
+
elif isinstance(did, str):
|
|
98
|
+
did_parts = did.split(DID.SCOPE_SEPARATOR, 1)
|
|
99
|
+
if len(did_parts) == 1:
|
|
100
|
+
self.name = did
|
|
101
|
+
self.update_implicit_scope()
|
|
102
|
+
if not self.has_scope():
|
|
103
|
+
raise DIDError('Object construction from non-splitable string is ambigious')
|
|
104
|
+
else:
|
|
105
|
+
self.scope = did_parts[0]
|
|
106
|
+
self.name = did_parts[1]
|
|
107
|
+
elif isinstance(did, DID):
|
|
108
|
+
self.scope = did.scope
|
|
109
|
+
self.name = did.name
|
|
110
|
+
else:
|
|
111
|
+
raise DIDError('Cannot build object from: {}'.format(type(did)))
|
|
112
|
+
|
|
113
|
+
if self.name.endswith('/'):
|
|
114
|
+
self.name = self.name[:-1]
|
|
115
|
+
|
|
116
|
+
if not self.is_valid_format():
|
|
117
|
+
raise DIDError('Object has invalid format after construction: {}'.format(str(self)))
|
|
118
|
+
|
|
119
|
+
def update_implicit_scope(self) -> None:
|
|
120
|
+
"""
|
|
121
|
+
This method sets the scope if it is implicitly given in self.name
|
|
122
|
+
"""
|
|
123
|
+
did_parts = self.name.split(DID.IMPLICIT_SCOPE_SEPARATOR)
|
|
124
|
+
num_scope_parts = DID.IMPLICIT_SCOPE_TO_LEN.get(did_parts[0], 0)
|
|
125
|
+
if num_scope_parts > 0:
|
|
126
|
+
self.scope = '.'.join(did_parts[0:num_scope_parts])
|
|
127
|
+
|
|
128
|
+
def is_valid_format(self) -> bool:
|
|
129
|
+
"""
|
|
130
|
+
Method to check if the stored DID has a valid format
|
|
131
|
+
:return: bool
|
|
132
|
+
"""
|
|
133
|
+
if self.scope.count(DID.SCOPE_SEPARATOR) or self.name.count(DID.SCOPE_SEPARATOR):
|
|
134
|
+
return False
|
|
135
|
+
return True
|
|
136
|
+
|
|
137
|
+
def has_scope(self) -> bool:
|
|
138
|
+
"""
|
|
139
|
+
Method to check if the scope part was set
|
|
140
|
+
:return: bool
|
|
141
|
+
"""
|
|
142
|
+
return len(self.scope) > 0
|
|
143
|
+
|
|
144
|
+
def has_name(self) -> bool:
|
|
145
|
+
"""
|
|
146
|
+
Method to check if the name part was set
|
|
147
|
+
:return: bool
|
|
148
|
+
"""
|
|
149
|
+
return len(self.name) > 0
|
|
150
|
+
|
|
151
|
+
def __str__(self) -> str:
|
|
152
|
+
"""
|
|
153
|
+
Creates the string representation of self
|
|
154
|
+
:return: string
|
|
155
|
+
"""
|
|
156
|
+
if self.has_scope() and self.has_name():
|
|
157
|
+
return '{}{}{}'.format(self.scope, DID.SCOPE_SEPARATOR, self.name)
|
|
158
|
+
elif self.has_scope():
|
|
159
|
+
return self.scope
|
|
160
|
+
return self.name
|
|
161
|
+
|
|
162
|
+
def __eq__(self, other: Union[str, "DID"]) -> bool:
|
|
163
|
+
"""
|
|
164
|
+
Equality comparison with another object
|
|
165
|
+
:return: bool
|
|
166
|
+
"""
|
|
167
|
+
if isinstance(other, str):
|
|
168
|
+
return str(self) == other
|
|
169
|
+
elif not isinstance(other, DID):
|
|
170
|
+
try:
|
|
171
|
+
other = DID(other)
|
|
172
|
+
except DIDError:
|
|
173
|
+
return False
|
|
174
|
+
|
|
175
|
+
return self.scope == other.scope and self.name == other.name
|
|
176
|
+
|
|
177
|
+
def __ne__(self, other: Union[str, "DID"]) -> bool:
|
|
178
|
+
"""
|
|
179
|
+
Inequality comparison with another object
|
|
180
|
+
:return: bool
|
|
181
|
+
"""
|
|
182
|
+
return not self.__eq__(other)
|
|
183
|
+
|
|
184
|
+
def __hash__(self) -> int:
|
|
185
|
+
"""
|
|
186
|
+
Uses the string representation of self to create a hash
|
|
187
|
+
:return: int
|
|
188
|
+
"""
|
|
189
|
+
return hash(str(self))
|