/usr/lib/python3/dist-packages/h5netcdf/attrs.py is in python3-h5netcdf 0.5.0-1.
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 | from collections import MutableMapping
import numpy as np
_HIDDEN_ATTRS = frozenset(['REFERENCE_LIST', 'CLASS', 'DIMENSION_LIST', 'NAME',
'_Netcdf4Dimid', '_Netcdf4Coordinates',
'_nc3_strict', '_NCProperties'])
class Attributes(MutableMapping):
def __init__(self, h5attrs, check_dtype):
self._h5attrs = h5attrs
self._check_dtype = check_dtype
def __getitem__(self, key):
if key in _HIDDEN_ATTRS:
raise KeyError(key)
return self._h5attrs[key]
def __setitem__(self, key, value):
if key in _HIDDEN_ATTRS:
raise AttributeError('cannot write attribute with reserved name %r'
% key)
if hasattr(value, 'dtype'):
dtype = value.dtype
else:
dtype = np.asarray(value).dtype
self._check_dtype(dtype)
self._h5attrs[key] = value
def __delitem__(self, key):
del self._h5attrs[key]
def __iter__(self):
for key in self._h5attrs:
if key not in _HIDDEN_ATTRS:
yield key
def __len__(self):
hidden_count = sum(1 if attr in self._h5attrs else 0
for attr in _HIDDEN_ATTRS)
return len(self._h5attrs) - hidden_count
def __repr__(self):
return '\n'.join(['%r' % type(self)] +
['%s: %r' % (k, v) for k, v in self.items()])
|