Skip to content

Commit

Permalink
[irods#558] iRODSAccess: Handle non-str types in constructor
Browse files Browse the repository at this point in the history
This change enables the iRODSAccess constructor to handle iRODSCollection and
iRODSDataObject types in addition to str-like types for the 'path' parameter.
A TypeError is now raised when an unsupported type is used for this parameter.
  • Loading branch information
alanking committed Jul 30, 2024
1 parent afc3ff0 commit 858bac8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion irods/access.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import collections
import copy
import six
from irods.collection import iRODSCollection
from irods.data_object import iRODSDataObject
from irods.path import iRODSPath

class _Access_LookupMeta(type):
Expand Down Expand Up @@ -59,7 +61,15 @@ def to_string(cls,key):

def __init__(self, access_name, path, user_name='', user_zone='', user_type=None):
self.access_name = access_name
self.path = path
if isinstance(path, (iRODSCollection, iRODSDataObject)):
self.path = path.path
elif isinstance(path, str):
# This should cover irods.path.iRODSPath as well as it is a descendant type of str.
self.path = path
else:
raise TypeError(
"'path' parameter must be of type 'str', 'irods.collection.iRODSCollection', "
"'irods.data_object.iRODSDataObject', or 'irods.path.iRODSPath'.")
self.user_name = user_name
self.user_zone = user_zone
self.user_type = user_type
Expand Down

0 comments on commit 858bac8

Please sign in to comment.