[h5py] 390/455: Dump .file database logic
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:53 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 9980a8f3701401195bcaca559b2aed5a8eee7e24
Author: andrewcollette <andrew.collette at gmail.com>
Date: Mon Feb 8 01:43:28 2010 +0000
Dump .file database logic
---
h5py/highlevel.py | 101 +++++++++++++++++++++---------------------
h5py/tests/__init__.py | 1 +
h5py/tests/high/test_file.py | 10 ++++-
h5py/tests/high/test_links.py | 10 +++--
4 files changed, 67 insertions(+), 55 deletions(-)
diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index d70bd73..fe90d02 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -103,24 +103,28 @@ class HLObject(object):
identity.
"""
- _files_dct = weakref.WeakValueDictionary()
-
- @classmethod
- def _reg_file(cls, fileobj):
- """ Register a high-level File object """
- fileno = h5g.get_objinfo(fileobj.fid, '.').fileno
- cls._files_dct[fileno] = fileobj
-
- @classmethod
- def _get_file(cls, oid):
- """ Retrieve the File object appropriate for this object """
- fileno = h5g.get_objinfo(oid, '.').fileno
- try:
- return cls._files_dct[fileno]
- except KeyError:
- fid = h5i.get_file_id(oid)
- fileobj = File(None, bind=fid)
- return cls._files_dct.setdefault(fileno, fileobj)
+ @property
+ def file(self):
+ """Return a File instance associated with this object"""
+ fid = h5i.get_file_id(self.id)
+ return File(None, bind=fid)
+
+ @property
+ def _lapl(self):
+ """Default link access property list (1.8)"""
+
+ lapl = h5p.create(h5p.LINK_ACCESS)
+ fapl = h5p.create(h5p.FILE_ACCESS)
+ fapl.set_fclose_degree(h5f.CLOSE_STRONG)
+ lapl.set_elink_fapl(fapl)
+ return lapl
+
+ @property
+ def _lcpl(self):
+ """Default link creation property list (1.8)"""
+ lcpl = h5p.create(h5p.LINK_CREATE)
+ lcpl.set_create_intermediate_group(True)
+ return lcpl
@property
def id(self):
@@ -138,11 +142,6 @@ class HLObject(object):
return AttributeManager(self)
@property
- def file(self):
- """Return a File instance associated with this object"""
- return self._file
-
- @property
def parent(self):
"""Return the parent group of this object.
@@ -159,7 +158,7 @@ class HLObject(object):
def __init__(self, oid):
""" Setup this object, given its low-level identifier """
- self._file = self._get_file(oid)
+ #self._file = self._get_file(oid)
self._id = oid
def __nonzero__(self):
@@ -277,7 +276,6 @@ class Group(HLObject, _DictCompat):
def _set18(self, name, obj):
""" HDF5 1.8 __setitem__. PHIL should already be held. """
plists = {'lcpl': self._lcpl, 'lapl': self._lapl}
-
if isinstance(obj, HLObject):
h5o.link(obj.id, self.id, name, **plists)
@@ -339,6 +337,20 @@ class Group(HLObject, _DictCompat):
else:
self._set16(name, obj)
+ def _get18(self, name):
+ """ HDF5 1.8 __getitem__ """
+
+ objinfo = h5o.get_info(self.id, name, lapl=self._lapl)
+
+ cls = {h5o.TYPE_GROUP: Group, h5o.TYPE_DATASET: Dataset,
+ h5o.TYPE_NAMED_DATATYPE: Datatype}.get(objinfo.type)
+ if cls is None:
+ raise TypeError("Unknown object type")
+
+ oid = h5o.open(self.id, name, lapl=self._lapl)
+ return cls(self, None, _rawid=oid)
+
+
def __getitem__(self, name):
""" Open an object attached to this group.
"""
@@ -358,6 +370,9 @@ class Group(HLObject, _DictCompat):
raise ValueError("Unrecognized reference object type")
+ if config.API_18:
+ return self._get18(name)
+
info = h5g.get_objinfo(self.id, name)
if info.type == h5g.DATASET:
@@ -690,6 +705,8 @@ class File(Group):
memb_size: Maximum file size (default is 2**31-1).
"""
+ _modes = weakref.WeakKeyDictionary()
+
@property
def filename(self):
"""File name on disk"""
@@ -709,15 +726,15 @@ class File(Group):
def file(self):
return self
- @cproperty('_mode')
+ @property
def mode(self):
"""Python mode used to open file"""
- if not config.API_18:
- return None
- intent = self.fid.get_intent()
- return {h5f.ACC_RDONLY: 'r', h5f.ACC_RDWR: 'r+'}.get(intent)
+ mode = self._modes.get(self)
+ if mode is None and config.API_18:
+ mode = {h5f.ACC_RDONLY: 'r', h5f.ACC_RDWR: 'r+'}.get(self.fid.get_intent())
+ return mode
- @cproperty('_driver')
+ @property
def driver(self):
"""Low-level HDF5 file driver used to open file"""
drivers = {h5fd.SEC2: 'sec2', h5fd.STDIO: 'stdio',
@@ -725,23 +742,6 @@ class File(Group):
h5fd.WINDOWS: 'windows'}
return drivers.get(self.fid.get_access_plist().get_driver(), 'unknown')
- @cproperty('_xlapl')
- def _lapl(self):
- """Default link access property list (1.8)"""
-
- lapl = h5p.create(h5p.LINK_ACCESS)
- fapl = h5p.create(h5p.FILE_ACCESS)
- fapl.set_fclose_degree(h5f.CLOSE_STRONG)
- lapl.set_elink_fapl(fapl)
- return lapl
-
- @cproperty('_xlcpl')
- def _lcpl(self):
- """Default link creation property list (1.8)"""
- lcpl = h5p.create(h5p.LINK_CREATE)
- lcpl.set_create_intermediate_group(True)
- return lcpl
-
# --- Public interface (File) ---------------------------------------------
def __init__(self, name, mode=None, driver=None, **kwds):
@@ -775,10 +775,9 @@ class File(Group):
plist = self._generate_access_plist(driver, **kwds)
self.fid = self._generate_fid(name, mode, plist)
- self._mode = mode
+ self._modes[self] = mode
- gid = h5g.open(self.fid, '/')
- self._reg_file(self)
+ gid = h5o.open(self.fid, '/', lapl=self._lapl)
Group.__init__(self, None, None, _rawid=gid)
def _generate_access_plist(self, driver, **kwds):
diff --git a/h5py/tests/__init__.py b/h5py/tests/__init__.py
index 36b7b76..86ea954 100644
--- a/h5py/tests/__init__.py
+++ b/h5py/tests/__init__.py
@@ -95,6 +95,7 @@ class HTest(unittest.TestCase):
newcount = h5py.h5f.get_obj_count()
if newcount != objcount:
print "WARNING: LEAKED %d IDs (total %d)" % (newcount-objcount, newcount)
+ print h5py.h5f.get_obj_ids()
if 0:
ids = h5py.h5f.get_obj_ids()
for id_ in ids:
diff --git a/h5py/tests/high/test_file.py b/h5py/tests/high/test_file.py
index d0864c2..cd00adf 100644
--- a/h5py/tests/high/test_file.py
+++ b/h5py/tests/high/test_file.py
@@ -220,8 +220,16 @@ class TestProps(FileBase):
lapl = self.f._lapl
self.assertIsInstance(lapl, h5py.h5p.PropLAID)
+class TestMode(FileBase):
-
+ def test_mode(self):
+ """ (File) Mode works properly with .file attribute """
+ self.name = mktemp()
+ self.f = h5py.File(self.name, 'a')
+ g = self.f.create_group('g')
+ self.assertEqual(g.file.mode, self.f.mode)
+ self.assertEqual(self.f.mode, 'a')
+
diff --git a/h5py/tests/high/test_links.py b/h5py/tests/high/test_links.py
index 50dbb6d..577d963 100644
--- a/h5py/tests/high/test_links.py
+++ b/h5py/tests/high/test_links.py
@@ -72,9 +72,13 @@ class TestExternal(Base):
os.unlink(self.ename)
@tests.require(api=18)
- @tests.fixme("Leaks IDs by using incorrect FAPL")
+ def test_create_only(self):
+ """ (Links) Create external link """
+ self.f['ext'] = h5py.ExternalLink(self.ename, '/external')
+
+ @tests.require(api=18)
def test_create(self):
- """ (Links) Create and access external link """
+ """ (Links) Access external link """
self.f['ext'] = h5py.ExternalLink(self.ename, '/external')
g = self.f['ext']
self.assert_(g)
@@ -92,7 +96,7 @@ class TestExternal(Base):
self.f['ext'] = h5py.ExternalLink('misssing.hdf5', '/missing')
self.assertRaises(IOError, self.f.__getitem__, 'ext')
- @tests.fixme("Leaks IDs by using incorrect FAPL")
+ @tests.require(api=18)
def test_file(self):
""" (Links) File attribute works correctly on external links """
self.f['ext'] = h5py.ExternalLink(self.ename, '/external')
--
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