@@ -679,7 +679,19 @@ def __getitem__(self, name, track_order=False):
679
679
tgt ._name = name
680
680
return tgt
681
681
682
- def get (self , name , default = None , getclass = False , getlink = False , track_order = False ):
682
+ def objectify_link_json (self , link_json ):
683
+ if "id" in link_json :
684
+ link_obj = HardLink (link_json ["id" ])
685
+ elif "h5path" in link_json and "h5domain" not in link_json :
686
+ link_obj = SoftLink (link_json ["h5path" ])
687
+ elif "h5path" in link_json and "h5domain" in link_json :
688
+ link_obj = ExternalLink (link_json ["h5domain" ], link_json ["h5path" ])
689
+ else :
690
+ raise ValueError ("Invalid link JSON" )
691
+
692
+ return link_obj
693
+
694
+ def get (self , name , default = None , getclass = False , getlink = False , track_order = False , ** kwds ):
683
695
""" Retrieve an item or other information.
684
696
685
697
"name" given only:
@@ -697,6 +709,21 @@ def get(self, name, default=None, getclass=False, getlink=False, track_order=Fal
697
709
Return HardLink, SoftLink and ExternalLink classes. Return
698
710
"default" if nothing with that name exists.
699
711
712
+ "limit" is an integer:
713
+ If "name" is None, this will return the first "limit" links in the group.
714
+
715
+ "marker" is a string:
716
+ If "name" is None, this will return only the links that come after the marker in the group's link ordering.
717
+
718
+ "pattern" is a string:
719
+ If "name" is None, this will return only the links that match the given pattern
720
+ in the target group (and subgroups, if follow_links is provided).
721
+ Matching is done according to Unix pathname expansion rules.
722
+
723
+ "follow_links" is True:
724
+ If "name" is None, subgroups of the target group will be recursively searched
725
+ for links that match the given names or pattern.
726
+
700
727
Example:
701
728
702
729
>>> cls = group.get('foo', getclass=True)
@@ -709,7 +736,7 @@ def get(self, name, default=None, getclass=False, getlink=False, track_order=Fal
709
736
except KeyError :
710
737
return default
711
738
712
- if name not in self :
739
+ if name is not None and name not in self :
713
740
return default
714
741
715
742
elif getclass and not getlink :
@@ -726,6 +753,52 @@ def get(self, name, default=None, getclass=False, getlink=False, track_order=Fal
726
753
raise TypeError ("Unknown object type" )
727
754
728
755
elif getlink :
756
+ if name is None :
757
+ # Get all links in target group(s)
758
+ # Retrieve "limit", "marker", and "pattern" from kwds
759
+ limit = kwds .get ("limit" , None )
760
+ marker = kwds .get ("marker" , None )
761
+ pattern = kwds .get ("pattern" , None )
762
+ follow_links = kwds .get ("follow_links" , False )
763
+
764
+ req = "/groups/" + self .id .uuid + "/links"
765
+ params = {}
766
+
767
+ if limit :
768
+ params ["Limit" ] = limit
769
+ if marker :
770
+ params ["Marker" ] = marker
771
+ if pattern :
772
+ params ["pattern" ] = pattern
773
+ if follow_links :
774
+ params ["follow_links" ] = 1
775
+ if track_order :
776
+ params ["CreateOrder" ] = 1
777
+
778
+ rsp = self .GET (req , params = params )
779
+
780
+ if "links" in rsp :
781
+ # Process list of link objects so they may be accessed by name
782
+ links = rsp ['links' ]
783
+ links_out = {}
784
+ if all ([isUUID (k ) for k in links ]):
785
+ # Multiple groups queried, links are returned under group ids
786
+ for group_id in links :
787
+ group_links = {}
788
+
789
+ for link in links [group_id ]:
790
+ group_links [link ["title" ]] = self .objectify_link_json (link )
791
+
792
+ links_out [group_id ] = group_links
793
+
794
+ else :
795
+ for link in links :
796
+ links_out [link ["title" ]] = self .objectify_link_json (link )
797
+ else :
798
+ raise ValueError ("Can't parse server response to links query" )
799
+
800
+ return links_out
801
+
729
802
parent_uuid , link_json = self ._get_link_json (name )
730
803
typecode = link_json ['class' ]
731
804
@@ -740,7 +813,7 @@ def get(self, name, default=None, getclass=False, getlink=False, track_order=Fal
740
813
741
814
return ExternalLink (link_json ['h5domain' ], link_json ['h5path' ])
742
815
elif typecode == 'H5L_TYPE_HARD' :
743
- return HardLink if getclass else HardLink ()
816
+ return HardLink if getclass else HardLink (link_json [ 'id' ] )
744
817
else :
745
818
raise TypeError ("Unknown link type" )
746
819
@@ -1214,8 +1287,16 @@ class HardLink(object):
1214
1287
Represents a hard link in an HDF5 file. Provided only so that
1215
1288
Group.get works in a sensible way. Has no other function.
1216
1289
"""
1290
+ @property
1291
+ # The uuid of the target object
1292
+ def id (self ):
1293
+ return self ._id
1217
1294
1218
- pass
1295
+ def __init__ (self , id = None ):
1296
+ self ._id = id
1297
+
1298
+ def __repr__ (self ):
1299
+ return f'<HardLink to "{ self .id } ">'
1219
1300
1220
1301
1221
1302
# TODO: implement equality testing for these
0 commit comments