[h5py] 117/455: Minor improvements to h5o, h5g

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit 4c72c1fce9fdc64e101ea8e9d1302ba87fd60895
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue Sep 16 19:44:55 2008 +0000

    Minor improvements to h5o, h5g
---
 h5py/h5g.pyx | 39 +++++++++++++++++++++++----------------
 h5py/h5o.pyx | 51 +++++++++++++++++++++++++++++++++------------------
 2 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index 2d247fe..b3739f0 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -52,12 +52,27 @@ cdef class GroupStat:
         *"Uniquely identifying" means unique among currently open files, 
         not universally unique.
     """
-    cdef readonly object fileno  # will be a 2-tuple
-    cdef readonly object objno   # will be a 2-tuple
-    cdef readonly unsigned int nlink
-    cdef readonly int type
-    cdef readonly time_t mtime
-    cdef readonly size_t linklen
+    cdef H5G_stat_t infostruct
+    cdef object __weakref__
+
+    property fileno:
+        def __get__(self):
+            return (self.infostruct.fileno[0], self.infostruct.fileno[1])
+    property objno:
+        def __get__(self):
+            return (self.infostruct.objno[0], self.infostruct.objno[1])
+    property nlink:
+        def __get__(self):
+            return self.infostruct.nlink
+    property type:
+        def __get__(self):
+            return self.infostruct.type
+    property mtime:
+        def __get__(self):
+            return self.infostruct.mtime
+    property linklen:
+        def __get__(self):
+            return self.infostruct.linklen
 
     def __str__(self):
         return \
@@ -181,20 +196,12 @@ def get_objinfo(ObjectID obj not None, object name='.', int follow_link=1):
         the information returned describes its target.  Otherwise the 
         information describes the link itself.
     """
-    cdef H5G_stat_t stat
     cdef GroupStat statobj
+    statobj = GroupStat()
     cdef char* _name
     _name = name
 
-    H5Gget_objinfo(obj.id, _name, follow_link, &stat)
-
-    statobj = GroupStat()
-    statobj.fileno = (stat.fileno[0], stat.fileno[1])
-    statobj.objno = (stat.objno[0], stat.objno[1])
-    statobj.nlink = stat.nlink
-    statobj.type = stat.type
-    statobj.mtime = stat.mtime
-    statobj.linklen = stat.linklen
+    H5Gget_objinfo(obj.id, _name, follow_link, &statobj.infostruct)
 
     return statobj
 
diff --git a/h5py/h5o.pyx b/h5py/h5o.pyx
index 32d954c..2877cf5 100644
--- a/h5py/h5o.pyx
+++ b/h5py/h5o.pyx
@@ -21,6 +21,9 @@ import h5
 
 cdef class ObjInfo:
 
+    cdef H5O_info_t infostruct
+    cdef object __weakref__
+
     property fileno:
         def __get__(self):
             return self.infostruct.fileno
@@ -34,8 +37,6 @@ cdef class ObjInfo:
         def __get__(self):
             return self.infostruct.rc
 
-    cdef H5O_info_t infostruct
-
     def __copy__(self):
         cdef ObjInfo newcopy
         newcopy = ObjInfo()
@@ -52,31 +53,36 @@ def get_info(ObjectID obj not None):
     H5Oget_info(obj.id, &info.infostruct)
     return info
 
-cdef class _Triplet:
+cdef class _CBWrapper:
 
     cdef object func
     cdef object exc
+    cdef object retval
     cdef ObjInfo objinfo
 
     def __init__(self, func):
         self.func = func
         self.exc = None
+        self.retval = None
         self.objinfo = ObjInfo()
 
-cdef herr_t iter_cb(hid_t obj, char* name, H5O_info_t *info, void* data):
+cdef herr_t visit_cb(hid_t obj, char* name, H5O_info_t *info, void* data):
 
-    cdef _Triplet triplet
-    triplet = <_Triplet>data
+    cdef _CBWrapper wrapper
+    wrapper = <_CBWrapper>data
 
-    triplet.objinfo.infostruct = info[0]
+    wrapper.objinfo.infostruct = info[0]
 
     try:
-        retval = triplet.func(name, triplet.objinfo)
-    except BaseException, e:   # The exception MUST be propagated
-        triplet.exc = e
+        retval = wrapper.func(name, wrapper.objinfo)
+    except StopIteration:
+        return 1
+    except BaseException, e:   # The exception MUST be trapped, including SystemExit
+        wrapper.exc = e
         return 1
 
     if retval is not None:
+        wrapper.retval = retval
         return 1
 
     return 0
@@ -94,19 +100,28 @@ def visit(ObjectID obj not None, object func, int idx_type=H5_INDEX_NAME,
         where "name" is (a) name relative to the starting group, and "info" is
         an ObjInfo instance describing each object.  Please note the same
         ObjInfo instance is provided call to call, with its values mutated.
-        Don't store references to it; use the copy module instead:
+        Don't store references to it; use the copy module instead.
+
+        Your callable should also conform to the following behavior:
+
+        1. Return None for normal iteration; raise StopIteration to cancel
+           and return None from h5o.visit.
+
+        2. Returning a value other than None cancels iteration and immediately
+           returns that value from h5o.visit.
 
-            mylist.append(info)             # WRONG
-            mylist.append(copy.copy(info))  # RIGHT
+        3. Raising any other exception aborts iteration; the exception will
+           be correctly propagated.
     """
-    cdef _Triplet triplet
-    triplet = _Triplet(func)
+    cdef _CBWrapper wrapper
+    wrapper = _CBWrapper(func)
 
-    H5Ovisit(obj.id, <H5_index_t>idx_type, <H5_iter_order_t>order, iter_cb, <void*>triplet)
+    H5Ovisit(obj.id, <H5_index_t>idx_type, <H5_iter_order_t>order, visit_cb, <void*>wrapper)
 
-    if triplet.exc is not None:
-        raise triplet.exc
+    if wrapper.exc is not None:
+        raise wrapper.exc
 
+    return wrapper.retval  # None or custom value
     
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git



More information about the debian-science-commits mailing list