<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import re <EOL> import sys <EOL> import warnings <EOL> import six . moves . cPickle <EOL> import numpy <EOL> from . import hdf5extension <EOL> from . utils import SizeType <EOL> from . registry import class_name_dict <EOL> from . exceptions import ClosedNodeError , PerformanceWarning <EOL> from . path import check_attribute_name <EOL> from . undoredo import attr_to_shadow <EOL> from . filters import Filters <EOL> from six . moves import map <EOL> import six <EOL> SYS_ATTRS = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> SYS_ATTRS_PREFIXES = [ "<STR_LIT>" ] <EOL> SYS_ATTRS_NOTTOBECOPIED = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> FORCE_COPY_CLASS = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> _field_fill_re = re . compile ( '<STR_LIT>' ) <EOL> _old_filters_re = re . compile ( br'<STR_LIT>' ) <EOL> _new_filters_sub = br'<STR_LIT>' <EOL> def issysattrname ( name ) : <EOL> "<STR_LIT>" <EOL> if ( name in SYS_ATTRS or <EOL> numpy . prod ( [ name . startswith ( prefix ) <EOL> for prefix in SYS_ATTRS_PREFIXES ] ) ) : <EOL> return True <EOL> else : <EOL> return False <EOL> class AttributeSet ( hdf5extension . AttributeSet , object ) : <EOL> """<STR_LIT>""" <EOL> def _g_getnode ( self ) : <EOL> return self . _v__nodefile . _get_node ( self . _v__nodepath ) <EOL> @ property <EOL> def _v_node ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _g_getnode ( ) <EOL> def __init__ ( self , node ) : <EOL> """<STR_LIT>""" <EOL> if not node . _v_isopen : <EOL> raise ClosedNodeError ( "<STR_LIT>" ) <EOL> dict_ = self . __dict__ <EOL> self . _g_new ( node ) <EOL> dict_ [ "<STR_LIT>" ] = node . _v_file <EOL> dict_ [ "<STR_LIT>" ] = node . _v_pathname <EOL> dict_ [ "<STR_LIT>" ] = self . _g_list_attr ( node ) <EOL> dict_ [ "<STR_LIT>" ] = [ ] <EOL> try : <EOL> format_version = node . _v_file . format_version <EOL> except AttributeError : <EOL> parsed_version = None <EOL> else : <EOL> if format_version == '<STR_LIT>' : <EOL> parsed_version = None <EOL> else : <EOL> parsed_version = tuple ( map ( int , format_version . split ( '<STR_LIT:.>' ) ) ) <EOL> dict_ [ "<STR_LIT>" ] = parsed_version <EOL> dict_ [ "<STR_LIT>" ] = [ ] <EOL> dict_ [ "<STR_LIT>" ] = [ ] <EOL> for attr in self . _v_attrnames : <EOL> self . __getattr__ ( attr ) <EOL> if issysattrname ( attr ) : <EOL> self . _v_attrnamessys . append ( attr ) <EOL> else : <EOL> self . _v_attrnamesuser . append ( attr ) <EOL> self . _v_attrnames . sort ( ) <EOL> self . _v_attrnamessys . sort ( ) <EOL> self . _v_attrnamesuser . sort ( ) <EOL> def _g_update_node_location ( self , node ) : <EOL> """<STR_LIT>""" <EOL> dict_ = self . __dict__ <EOL> dict_ [ '<STR_LIT>' ] = node . _v_file <EOL> dict_ [ '<STR_LIT>' ] = node . _v_pathname <EOL> self . _g_new ( node ) <EOL> def _f_list ( self , attrset = '<STR_LIT:user>' ) : <EOL> """<STR_LIT>""" <EOL> if attrset == "<STR_LIT:user>" : <EOL> return self . _v_attrnamesuser [ : ] <EOL> elif attrset == "<STR_LIT>" : <EOL> return self . _v_attrnamessys [ : ] <EOL> elif attrset == "<STR_LIT:all>" : <EOL> return self . _v_attrnames [ : ] <EOL> def __getattr__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if not name in self . _v_attrnames : <EOL> raise AttributeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( name , self . _v__nodepath ) ) <EOL> format_version = self . _v__format_version <EOL> value = self . _g_getattr ( self . _v_node , name ) <EOL> maybe_pickled = ( <EOL> isinstance ( value , numpy . generic ) and <EOL> value . dtype . type == numpy . bytes_ and <EOL> value . itemsize > <NUM_LIT:0> and value . endswith ( b'<STR_LIT:.>' ) ) <EOL> if ( maybe_pickled and value in [ b"<STR_LIT:0>" , b"<STR_LIT>" ] ) : <EOL> retval = value <EOL> elif ( maybe_pickled and _field_fill_re . match ( name ) <EOL> and format_version == ( <NUM_LIT:1> , <NUM_LIT:5> ) ) : <EOL> try : <EOL> retval = six . moves . cPickle . loads ( value ) <EOL> retval = numpy . array ( retval ) <EOL> except ImportError : <EOL> retval = None <EOL> elif maybe_pickled and name == '<STR_LIT>' and format_version < ( <NUM_LIT:2> , <NUM_LIT:0> ) : <EOL> value = _old_filters_re . sub ( _new_filters_sub , value , <NUM_LIT:1> ) <EOL> retval = six . moves . cPickle . loads ( value ) <EOL> elif maybe_pickled : <EOL> try : <EOL> retval = six . moves . cPickle . loads ( value ) <EOL> except : <EOL> retval = value <EOL> if isinstance ( retval , six . text_type ) and retval == u'<STR_LIT>' : <EOL> retval = numpy . array ( retval ) [ ( ) ] <EOL> elif name == '<STR_LIT>' and format_version >= ( <NUM_LIT:2> , <NUM_LIT:0> ) : <EOL> retval = Filters . _unpack ( value ) <EOL> elif name == '<STR_LIT>' and not isinstance ( value , str ) : <EOL> if sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> : <EOL> retval = value <EOL> else : <EOL> retval = value . decode ( '<STR_LIT:utf-8>' ) <EOL> elif ( issysattrname ( name ) and isinstance ( value , ( bytes , six . text_type ) ) and <EOL> not isinstance ( value , str ) and not _field_fill_re . match ( name ) ) : <EOL> if sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> : <EOL> retval = value . encode ( ) <EOL> else : <EOL> retval = value . decode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> retval = value <EOL> self . __dict__ [ name ] = retval <EOL> return retval <EOL> def _g__setattr ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> stvalue = value <EOL> if issysattrname ( name ) : <EOL> if name in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> stvalue = numpy . array ( value , dtype = numpy . int32 ) <EOL> value = stvalue [ ( ) ] <EOL> elif name == "<STR_LIT>" : <EOL> stvalue = numpy . array ( value , dtype = SizeType ) <EOL> value = stvalue [ ( ) ] <EOL> elif name == "<STR_LIT>" and self . _v__format_version >= ( <NUM_LIT:2> , <NUM_LIT:0> ) : <EOL> stvalue = value . _pack ( ) <EOL> if ( stvalue is value and <EOL> type ( value ) in ( bool , bytes , int , float , complex , six . text_type , <EOL> numpy . unicode_ ) ) : <EOL> if isinstance ( value , six . text_type ) and len ( value ) == <NUM_LIT:0> : <EOL> stvalue = numpy . array ( u'<STR_LIT>' ) <EOL> else : <EOL> stvalue = numpy . array ( value ) <EOL> value = stvalue [ ( ) ] <EOL> self . _g_setattr ( self . _v_node , name , stvalue ) <EOL> self . __dict__ [ name ] = value <EOL> attrnames = self . _v_attrnames <EOL> if not name in attrnames : <EOL> attrnames . append ( name ) <EOL> attrnames . sort ( ) <EOL> if issysattrname ( name ) : <EOL> attrnamessys = self . _v_attrnamessys <EOL> attrnamessys . append ( name ) <EOL> attrnamessys . sort ( ) <EOL> else : <EOL> attrnamesuser = self . _v_attrnamesuser <EOL> attrnamesuser . append ( name ) <EOL> attrnamesuser . sort ( ) <EOL> def __setattr__ ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> nodefile = self . _v__nodefile <EOL> attrnames = self . _v_attrnames <EOL> check_attribute_name ( name ) <EOL> nodefile . _check_writable ( ) <EOL> max_node_attrs = nodefile . params [ '<STR_LIT>' ] <EOL> if len ( attrnames ) >= max_node_attrs : <EOL> warnings . warn ( """<STR_LIT>""" <EOL> % ( self . _v__nodepath , max_node_attrs ) , <EOL> PerformanceWarning ) <EOL> undo_enabled = nodefile . is_undo_enabled ( ) <EOL> if undo_enabled and ( name in attrnames ) : <EOL> self . _g_del_and_log ( name ) <EOL> self . _g__setattr ( name , value ) <EOL> if undo_enabled : <EOL> self . _g_log_add ( name ) <EOL> def _g_log_add ( self , name ) : <EOL> self . _v__nodefile . _log ( '<STR_LIT>' , self . _v__nodepath , name ) <EOL> def _g_del_and_log ( self , name ) : <EOL> nodefile = self . _v__nodefile <EOL> node_pathname = self . _v__nodepath <EOL> nodefile . _log ( '<STR_LIT>' , node_pathname , name ) <EOL> attr_to_shadow ( nodefile , node_pathname , name ) <EOL> def _g__delattr ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . _g_remove ( self . _v_node , name ) <EOL> self . _v_attrnames . remove ( name ) <EOL> if name in self . _v_attrnamessys : <EOL> self . _v_attrnamessys . remove ( name ) <EOL> else : <EOL> self . _v_attrnamesuser . remove ( name ) <EOL> del self . __dict__ [ name ] <EOL> def __delattr__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> nodefile = self . _v__nodefile <EOL> if name not in self . _v_attrnames : <EOL> raise AttributeError ( <EOL> "<STR_LIT>" <EOL> % ( name , self . _v__nodepath ) ) <EOL> nodefile . _check_writable ( ) <EOL> if nodefile . is_undo_enabled ( ) : <EOL> self . _g_del_and_log ( name ) <EOL> else : <EOL> self . _g__delattr ( name ) <EOL> def __getitem__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . __getattr__ ( name ) <EOL> except AttributeError : <EOL> raise KeyError ( <EOL> "<STR_LIT>" <EOL> % ( name , self . _v__nodepath ) ) <EOL> def __setitem__ ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> self . __setattr__ ( name , value ) <EOL> def __delitem__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . __delattr__ ( name ) <EOL> except AttributeError : <EOL> raise KeyError ( <EOL> "<STR_LIT>" <EOL> % ( name , self . _v__nodepath ) ) <EOL> def __contains__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return name in self . _v_attrnames <EOL> def _f_rename ( self , oldattrname , newattrname ) : <EOL> """<STR_LIT>""" <EOL> if oldattrname == newattrname : <EOL> return <EOL> attrvalue = getattr ( self , oldattrname ) <EOL> setattr ( self , newattrname , attrvalue ) <EOL> delattr ( self , oldattrname ) <EOL> def _g_copy ( self , newset , set_attr = None , copyclass = False ) : <EOL> """<STR_LIT>""" <EOL> copysysattrs = newset . _v__nodefile . params [ '<STR_LIT>' ] <EOL> if set_attr is None : <EOL> set_attr = newset . _g__setattr <EOL> for attrname in self . _v_attrnamesuser : <EOL> if attrname not in self . _v_unimplemented : <EOL> set_attr ( attrname , getattr ( self , attrname ) ) <EOL> if copysysattrs : <EOL> for attrname in self . _v_attrnamessys : <EOL> if ( ( attrname not in SYS_ATTRS_NOTTOBECOPIED ) and <EOL> not attrname . startswith ( "<STR_LIT>" ) ) : <EOL> set_attr ( attrname , getattr ( self , attrname ) ) <EOL> if copyclass : <EOL> for attrname in FORCE_COPY_CLASS : <EOL> if attrname in self . _v_attrnamessys : <EOL> set_attr ( attrname , getattr ( self , attrname ) ) <EOL> def _f_copy ( self , where ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( where , class_name_dict [ '<STR_LIT>' ] ) : <EOL> raise TypeError ( "<STR_LIT>" % ( where , ) ) <EOL> self . _g_copy ( where . _v_attrs , where . _v_attrs . __setattr__ ) <EOL> def _g_close ( self ) : <EOL> pass <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> pathname = self . _v__nodepath <EOL> classname = self . __class__ . __name__ <EOL> attrnumber = len ( [ n for n in self . _v_attrnames ] ) <EOL> return "<STR_LIT>" % ( pathname , classname , attrnumber ) <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> attrnames = [ n for n in self . _v_attrnames ] <EOL> if len ( attrnames ) : <EOL> rep = [ '<STR_LIT>' % ( attr , getattr ( self , attr ) ) <EOL> for attr in attrnames ] <EOL> attrlist = '<STR_LIT>' % ( '<STR_LIT>' . join ( rep ) ) <EOL> return "<STR_LIT>" % ( str ( self ) , attrlist ) <EOL> else : <EOL> return str ( self ) <EOL> class NotLoggedAttributeSet ( AttributeSet ) : <EOL> def _g_log_add ( self , name ) : <EOL> pass <EOL> def _g_del_and_log ( self , name ) : <EOL> self . _g__delattr ( name ) </s>
