Get the attribute named "name".
(self, name: str)
| 306 | ) |
| 307 | |
| 308 | def __getattr__(self, name: str) -> Any: |
| 309 | """Get the attribute named "name".""" |
| 310 | # If attribute does not exist, raise AttributeError |
| 311 | if name not in self._v_attrnames: |
| 312 | raise AttributeError( |
| 313 | f"Attribute {name!r} does not exist " |
| 314 | f"in node: {self._v__nodepath!r}" |
| 315 | ) |
| 316 | |
| 317 | # Read the attribute from disk. This is an optimization to read |
| 318 | # quickly system attributes that are _string_ values, but it |
| 319 | # takes care of other types as well as for example NROWS for |
| 320 | # Tables and EXTDIM for EArrays |
| 321 | format_version = self._v__format_version |
| 322 | value = self._g_getattr(self._v_node, name) |
| 323 | |
| 324 | # Check whether the value is pickled |
| 325 | # Pickled values always seems to end with a "." |
| 326 | maybe_pickled = ( |
| 327 | isinstance(value, np.generic) # NumPy scalar? |
| 328 | and value.dtype.type == np.bytes_ # string type? |
| 329 | and value.itemsize > 0 |
| 330 | and value.endswith(b".") |
| 331 | ) |
| 332 | |
| 333 | if maybe_pickled and value in [b"0", b"0."]: |
| 334 | # Workaround for a bug in many versions of Python (starting |
| 335 | # somewhere after Python 2.6.1). See ticket #253. |
| 336 | retval = value |
| 337 | elif ( |
| 338 | maybe_pickled |
| 339 | and _field_fill_re.match(name) |
| 340 | and format_version == (1, 5) |
| 341 | ): |
| 342 | # This format was used during the first 1.2 releases, just |
| 343 | # for string defaults. |
| 344 | try: |
| 345 | retval = pickle.loads(value) |
| 346 | retval = np.array(retval) |
| 347 | except ImportError: |
| 348 | retval = None # signal error avoiding exception |
| 349 | elif ( |
| 350 | maybe_pickled |
| 351 | and name == "FILTERS" |
| 352 | and format_version is not None |
| 353 | and format_version < (2, 0) |
| 354 | ): |
| 355 | # This is a big hack, but we don't have other way to recognize |
| 356 | # pickled filters of PyTables 1.x files. |
| 357 | value = _old_filters_re.sub(_new_filters_sub, value, 1) |
| 358 | retval = pickle.loads(value) # pass unpickling errors through |
| 359 | elif maybe_pickled: |
| 360 | try: |
| 361 | retval = pickle.loads(value) |
| 362 | # except cPickle.UnpicklingError: |
| 363 | # It seems that pickle may raise other errors than UnpicklingError |
| 364 | # Perhaps it would be better just an "except:" clause? |
| 365 | # except (cPickle.UnpicklingError, ImportError): |
no test coverage detected