/usr/lib/python2.7/dist-packages/h5py/h5r.pyx is in python-h5py 2.2.1-1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | # This file is part of h5py, a Python interface to the HDF5 library.
#
# http://www.h5py.org
#
# Copyright 2008-2013 Andrew Collette and contributors
#
# License: Standard 3-clause BSD; see "license.txt" for full license terms
# and contributor agreement.
"""
H5R API for object and region references.
"""
# Pyrex compile-time imports
from _objects cimport ObjectID
# === Public constants and data structures ====================================
OBJECT = H5R_OBJECT
DATASET_REGION = H5R_DATASET_REGION
# === Reference API ===========================================================
def create(ObjectID loc not None, char* name, int ref_type, ObjectID space=None):
"""(ObjectID loc, STRING name, INT ref_type, SpaceID space=None)
=> ReferenceObject ref
Create a new reference. The value of ref_type detemines the kind
of reference created:
OBJECT
Reference to an object in an HDF5 file. Parameters "loc"
and "name" identify the object; "space" is unused.
DATASET_REGION
Reference to a dataset region. Parameters "loc" and
"name" identify the dataset; the selection on "space"
identifies the region.
"""
cdef hid_t space_id
cdef Reference ref
if ref_type == H5R_OBJECT:
ref = Reference()
elif ref_type == H5R_DATASET_REGION:
if space is None: # work around segfault in HDF5
raise ValueError("Dataspace required for region reference")
ref = RegionReference()
else:
raise ValueError("Unknown reference typecode")
if space is None:
space_id = -1
else:
space_id = space.id
H5Rcreate(&ref.ref, loc.id, name, <H5R_type_t>ref_type, space_id)
return ref
def dereference(Reference ref not None, ObjectID id not None):
"""(Reference ref, ObjectID id) => ObjectID or None
Open the object pointed to by the reference and return its
identifier. The file identifier (or the identifier for any object
in the file) must also be provided. Returns None if the reference
is zero-filled.
The reference may be either Reference or RegionReference.
"""
import h5i
if not ref:
return None
return h5i.wrap_identifier(H5Rdereference(id.id, <H5R_type_t>ref.typecode, &ref.ref))
def get_region(RegionReference ref not None, ObjectID id not None):
"""(Reference ref, ObjectID id) => SpaceID or None
Retrieve the dataspace selection pointed to by the reference.
Returns a copy of the dataset's dataspace, with the appropriate
elements selected. The file identifier or the identifier of any
object in the file (including the dataset itself) must also be
provided.
The reference object must be a RegionReference. If it is zero-filled,
returns None.
"""
import h5s
if ref.typecode != H5R_DATASET_REGION or not ref:
return None
return h5s.SpaceID.open(H5Rget_region(id.id, <H5R_type_t>ref.typecode, &ref.ref))
def get_obj_type(Reference ref not None, ObjectID id not None):
"""(Reference ref, ObjectID id) => INT obj_code or None
Determine what type of object the reference points to. The
reference may be a Reference or RegionReference. The file
identifier or the identifier of any object in the file must also
be provided.
The return value is one of:
- h5g.LINK
- h5g.GROUP
- h5g.DATASET
- h5g.TYPE
If the reference is zero-filled, returns None.
"""
if not ref:
return None
return <int>H5Rget_obj_type(id.id, <H5R_type_t>ref.typecode, &ref.ref)
def get_name(Reference ref not None, ObjectID loc not None):
"""(Reference ref, ObjectID loc) => STRING name
Determine the name of the object pointed to by this reference.
Requires the HDF5 1.8 API.
"""
cdef ssize_t namesize = 0
cdef char* namebuf = NULL
namesize = H5Rget_name(loc.id, <H5R_type_t>ref.typecode, &ref.ref, NULL, 0)
if namesize > 0:
namebuf = <char*>malloc(namesize+1)
try:
namesize = H5Rget_name(loc.id, <H5R_type_t>ref.typecode, &ref.ref, namebuf, namesize+1)
return namebuf
finally:
free(namebuf)
cdef class Reference:
"""
Opaque representation of an HDF5 reference.
Objects of this class are created exclusively by the library and
cannot be modified. The read-only attribute "typecode" determines
whether the reference is to an object in an HDF5 file (OBJECT)
or a dataset region (DATASET_REGION).
The object's truth value indicates whether it contains a nonzero
reference. This does not guarantee that is valid, but is useful
for rejecting "background" elements in a dataset.
"""
def __cinit__(self, *args, **kwds):
self.typecode = H5R_OBJECT
self.typesize = sizeof(hobj_ref_t)
def __nonzero__(self):
cdef int i
for i from 0<=i<self.typesize:
if (<unsigned char*>&self.ref)[i] != 0: return True
return False
def __repr__(self):
return "<HDF5 object reference%s>" % ("" if self else " (null)")
cdef class RegionReference(Reference):
"""
Opaque representation of an HDF5 region reference.
This is a subclass of Reference which exists mainly for programming
convenience.
"""
def __cinit__(self, *args, **kwds):
self.typecode = H5R_DATASET_REGION
self.typesize = sizeof(hdset_reg_ref_t)
def __repr__(self):
return "<HDF5 region reference%s>" % ("" if self else " (null")
|