55from irods .path import iRODSPath
66
77
8+ _ichmod_listed_permissions = (
9+ "own" ,
10+ "delete_object" ,
11+ "write" ,
12+ "modify_object" ,
13+ "create_object" ,
14+ "delete_metadata" ,
15+ "modify_metadata" ,
16+ "create_metadata" ,
17+ "read" ,
18+ "read_object" ,
19+ "read_metadata" ,
20+ "null" ,
21+ )
22+
23+
824class _Access_LookupMeta (type ):
925 def __getitem__ (self , key ):
1026 return self .codes [key ]
@@ -28,6 +44,7 @@ def to_int(cls, key):
2844 def to_string (cls , key ):
2945 return cls .strings [key ]
3046
47+ # noqa: RUF012 - Cannot change in minor release
3148 codes = collections .OrderedDict (
3249 (key_ , value_ )
3350 for key_ , value_ in sorted (
@@ -55,24 +72,10 @@ def to_string(cls, key):
5572 ).items (),
5673 key = lambda _ : _ [1 ],
5774 )
58- if key_
59- in (
60- # These are copied from ichmod help text.
61- "own" ,
62- "delete_object" ,
63- "write" ,
64- "modify_object" ,
65- "create_object" ,
66- "delete_metadata" ,
67- "modify_metadata" ,
68- "create_metadata" ,
69- "read" ,
70- "read_object" ,
71- "read_metadata" ,
72- "null" ,
73- )
75+ if key_ in _ichmod_listed_permissions
7476 )
7577
78+ # noqa: RUF012 - Cannot change in minor release
7679 strings = collections .OrderedDict ((number , string ) for string , number in codes .items ())
7780
7881 def __init__ (self , access_name , path , user_name = "" , user_zone = "" , user_type = None ):
@@ -91,6 +94,14 @@ def __init__(self, access_name, path, user_name="", user_zone="", user_type=None
9194 self .user_zone = user_zone
9295 self .user_type = user_type
9396
97+ def __lt__ (self , other ):
98+ return (self .access_name , self .user_name , self .user_zone , iRODSPath (self .path )) < (
99+ other .access_name ,
100+ other .user_name ,
101+ other .user_zone ,
102+ iRODSPath (other .path ),
103+ )
104+
94105 def __eq__ (self , other ):
95106 return (
96107 self .access_name == other .access_name
@@ -102,8 +113,9 @@ def __eq__(self, other):
102113 def __hash__ (self ):
103114 return hash ((self .access_name , iRODSPath (self .path ), self .user_name , self .user_zone ))
104115
105- def copy (self , decanonicalize = False , ref_zone = '' ):
116+ def copy (self , decanonicalize = False , implied_zone = '' ):
106117 other = copy .deepcopy (self )
118+
107119 if decanonicalize :
108120 replacement_string = {
109121 "read object" : "read" ,
@@ -112,8 +124,10 @@ def copy(self, decanonicalize=False, ref_zone=''):
112124 "modify_object" : "write" ,
113125 }.get (self .access_name )
114126 other .access_name = replacement_string if replacement_string is not None else self .access_name
115- if '' != ref_zone == other .user_zone :
116- other .user_zone = ''
127+
128+ # Useful if we wish to force an explicitly specified local zone to an implicit zone spec in the copy, for equality testing:
129+ if '' != implied_zone == other .user_zone :
130+ other .user_zone = ''
117131
118132 return other
119133
@@ -124,6 +138,56 @@ def __repr__(self):
124138 return f"<iRODSAccess { access_name } { self .path } { self .user_name } { user_type_hint } { self .user_zone } >"
125139
126140
141+ class ACLOperation (iRODSAccess ):
142+ def __init__ (self , access_name : str , user_name : str = "" , user_zone : str = "" ):
143+ super ().__init__ (
144+ access_name = access_name ,
145+ path = "" ,
146+ user_name = user_name ,
147+ user_zone = user_zone ,
148+ )
149+
150+ def __eq__ (self , other ):
151+ return (
152+ self .access_name ,
153+ self .user_name ,
154+ self .user_zone ,
155+ ) == (
156+ other .access_name ,
157+ other .user_name ,
158+ other .user_zone ,
159+ )
160+
161+ def __lt__ (self , other ):
162+ return (
163+ self .access_name ,
164+ self .user_name ,
165+ self .user_zone ,
166+ ) < (
167+ other .access_name ,
168+ other .user_name ,
169+ other .user_zone ,
170+ )
171+
172+ def __repr__ (self ):
173+ return f"<ACLOperation { self .access_name } { self .user_name } { self .user_zone } >"
174+
175+
176+ (
177+ _ichmod_synonym_mapping := {
178+ # syn : canonical
179+ "write" : "modify_object" ,
180+ "read" : "read_object" ,
181+ }
182+ ).update ((key .replace ("_" , " " ), key ) for key in iRODSAccess .codes .keys ())
183+
184+
185+ all_permissions = {
186+ ** iRODSAccess .codes ,
187+ ** {key : iRODSAccess .codes [_ichmod_synonym_mapping [key ]] for key in _ichmod_synonym_mapping },
188+ }
189+
190+
127191class _iRODSAccess_pre_4_3_0 (iRODSAccess ):
128192 codes = collections .OrderedDict (
129193 (key .replace ("_" , " " ), value )
0 commit comments