@@ -123,16 +123,44 @@ def __hash__(self):
123123 return hash ((self .access_name , iRODSPath (self .path ), self .user_name , self .user_zone ))
124124
125125 def copy (self , decanonicalize = False , implied_zone = '' ):
126+ """
127+ Create a copy of the object, possibly in a normalized form.
128+
129+ Args:
130+ decanonicalize: Whether to modify to access_name field to a more human (1/True) or more standard (-1) form
131+ If the former, then one-word style is favored, ie "read" and "write". If the latter, the new access_name
132+ will be more machine-friendly for operators __lt__ (for sorting) and __eq__ (for equivalence or use with 'in').
133+ implied_zone: If a nonzero-length name, compare this against the zone_name field of the old object and force the zone_name to
134+ zero-length in the new object.
135+
136+ Returns:
137+ The new copy
138+ """
126139 other = copy .deepcopy (self )
127140
128- if decanonicalize :
129- replacement_string = {
141+ access_name = self .access_name
142+
143+ if decanonicalize == 1 :
144+ if (new_access_name := {
130145 "read object" : "read" ,
131146 "read_object" : "read" ,
132147 "modify object" : "write" ,
133148 "modify_object" : "write" ,
134- }.get (self .access_name )
135- other .access_name = replacement_string if replacement_string is not None else self .access_name
149+ }.get (access_name )) != None : access_name = new_access_name
150+ elif decanonicalize == - 1 :
151+ # Canonicalize, ie. change out old access_name for an unambiguous "standard" value.
152+ access_name = access_name .replace (" " ,"_" )
153+ if (new_access_name := {
154+ "read" : "read_object" ,
155+ "write" : "modify_object" ,
156+ }.get (access_name )) != None : access_name = new_access_name
157+ elif decanonicalize == 0 :
158+ pass
159+ else :
160+ msg = "Improper value for 'decanonicalize' parameter"
161+ raise RuntimerError (msg )
162+
163+ other .access_name = access_name
136164
137165 # Useful if we wish to force an explicitly specified local zone to an implicit zone spec in the copy, for equality testing:
138166 if '' != implied_zone == other .user_zone :
@@ -203,6 +231,9 @@ def __repr__(self):
203231 ** {key : iRODSAccess .codes [_ichmod_synonym_mapping [key ]] for key in _ichmod_synonym_mapping },
204232}
205233
234+ canonical_permissions = dict (
235+ (k ,v ) for k ,v in all_permissions .items () if ' ' not in k and k not in ('read' ,'write' )
236+ )
206237
207238class _deprecated :
208239 class _iRODSAccess_pre_4_3_0 (_iRODSAccess_base ):
0 commit comments