<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import warnings <EOL> import functools <EOL> from . registry import class_name_dict , class_id_dict <EOL> from . exceptions import ( ClosedNodeError , NodeError , UndoRedoWarning , <EOL> PerformanceWarning ) <EOL> from . path import join_path , split_path , isvisiblepath <EOL> from . utils import lazyattr <EOL> from . undoredo import move_to_shadow <EOL> from . attributeset import AttributeSet , NotLoggedAttributeSet <EOL> import six <EOL> __docformat__ = '<STR_LIT>' <EOL> """<STR_LIT>""" <EOL> def _closedrepr ( oldmethod ) : <EOL> """<STR_LIT>""" <EOL> @ functools . wraps ( oldmethod ) <EOL> def newmethod ( self ) : <EOL> if not self . _v_isopen : <EOL> cmod = self . __class__ . __module__ <EOL> cname = self . __class__ . __name__ <EOL> addr = hex ( id ( self ) ) <EOL> return '<STR_LIT>' % ( cmod , cname , addr ) <EOL> return oldmethod ( self ) <EOL> return newmethod <EOL> class MetaNode ( type ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( class_ , name , bases , dict_ ) : <EOL> for mname in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if mname in dict_ : <EOL> dict_ [ mname ] = _closedrepr ( dict_ [ mname ] ) <EOL> return type . __new__ ( class_ , name , bases , dict_ ) <EOL> def __init__ ( class_ , name , bases , dict_ ) : <EOL> super ( MetaNode , class_ ) . __init__ ( name , bases , dict_ ) <EOL> class_name_dict [ class_ . __name__ ] = class_ <EOL> cid = getattr ( class_ , '<STR_LIT>' , None ) <EOL> if cid is not None : <EOL> for base in bases : <EOL> pcid = getattr ( base , '<STR_LIT>' , None ) <EOL> if pcid == cid : <EOL> break <EOL> else : <EOL> class_id_dict [ cid ] = class_ <EOL> class Node ( six . with_metaclass ( MetaNode , object ) ) : <EOL> """<STR_LIT>""" <EOL> _AttributeSet = AttributeSet <EOL> def _g_getparent ( self ) : <EOL> "<STR_LIT>" <EOL> ( parentpath , nodename ) = split_path ( self . _v_pathname ) <EOL> return self . _v_file . _get_node ( parentpath ) <EOL> _v_parent = property ( _g_getparent ) <EOL> @ lazyattr <EOL> def _v_attrs ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _AttributeSet ( self ) <EOL> def _g_gettitle ( self ) : <EOL> "<STR_LIT>" <EOL> if hasattr ( self . _v_attrs , '<STR_LIT>' ) : <EOL> return self . _v_attrs . TITLE <EOL> else : <EOL> return '<STR_LIT>' <EOL> def _g_settitle ( self , title ) : <EOL> self . _v_attrs . TITLE = title <EOL> _v_title = property ( _g_gettitle , _g_settitle ) <EOL> _v_isopen = False <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parentnode , name , _log = True ) : <EOL> if isinstance ( parentnode , class_name_dict [ '<STR_LIT>' ] ) : <EOL> parentnode = parentnode . dereference ( ) <EOL> self . _v_file = None <EOL> """<STR_LIT>""" <EOL> self . _v_isopen = False <EOL> """<STR_LIT>""" <EOL> self . _v_pathname = None <EOL> """<STR_LIT>""" <EOL> self . _v_name = None <EOL> """<STR_LIT>""" <EOL> self . _v_depth = None <EOL> """<STR_LIT>""" <EOL> self . _v_maxtreedepth = parentnode . _v_file . params [ '<STR_LIT>' ] <EOL> """<STR_LIT>""" <EOL> self . _v__deleting = False <EOL> """<STR_LIT>""" <EOL> self . _v_objectid = None <EOL> """<STR_LIT>""" <EOL> validate = new = self . _v_new <EOL> self . _g_check_group ( parentnode ) <EOL> parentnode . _g_check_open ( ) <EOL> file_ = parentnode . _v_file <EOL> if new : <EOL> file_ . _check_writable ( ) <EOL> if new : <EOL> parentnode . _g_refnode ( self , name , validate ) <EOL> self . _g_set_location ( parentnode , name ) <EOL> try : <EOL> self . _g_new ( parentnode , name , init = True ) <EOL> if new : <EOL> self . _v_objectid = self . _g_create ( ) <EOL> else : <EOL> self . _v_objectid = self . _g_open ( ) <EOL> if new and _log and file_ . is_undo_enabled ( ) : <EOL> self . _g_log_create ( ) <EOL> self . _g_post_init_hook ( ) <EOL> except : <EOL> self . _f_close ( ) <EOL> raise <EOL> def _g_log_create ( self ) : <EOL> self . _v_file . _log ( '<STR_LIT>' , self . _v_pathname ) <EOL> def __del__ ( self ) : <EOL> if not self . _v_isopen : <EOL> return <EOL> self . _v__deleting = True <EOL> try : <EOL> node_manager = self . _v_file . _node_manager <EOL> node_manager . drop_node ( self , check_unregistered = False ) <EOL> finally : <EOL> if self . _v_isopen : <EOL> self . _v__deleting = True <EOL> self . _f_close ( ) <EOL> def _g_pre_kill_hook ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _g_create ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _g_open ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _g_check_open ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _v_isopen : <EOL> raise ClosedNodeError ( "<STR_LIT>" ) <EOL> assert self . _v_file . isopen , "<STR_LIT>" <EOL> def _g_set_location ( self , parentnode , name ) : <EOL> """<STR_LIT>""" <EOL> file_ = parentnode . _v_file <EOL> parentdepth = parentnode . _v_depth <EOL> self . _v_file = file_ <EOL> self . _v_isopen = True <EOL> root_uep = file_ . root_uep <EOL> if name . startswith ( root_uep ) : <EOL> assert parentdepth == <NUM_LIT:0> <EOL> if root_uep == "<STR_LIT:/>" : <EOL> self . _v_pathname = name <EOL> else : <EOL> self . _v_pathname = name [ len ( root_uep ) : ] <EOL> _ , self . _v_name = split_path ( name ) <EOL> self . _v_depth = name . count ( "<STR_LIT:/>" ) - root_uep . count ( "<STR_LIT:/>" ) + <NUM_LIT:1> <EOL> else : <EOL> self . _v_name = name <EOL> self . _v_pathname = join_path ( parentnode . _v_pathname , name ) <EOL> self . _v_depth = parentdepth + <NUM_LIT:1> <EOL> if parentdepth >= self . _v_maxtreedepth : <EOL> warnings . warn ( """<STR_LIT>""" <EOL> % ( self . _v_pathname , self . _v_maxtreedepth ) , <EOL> PerformanceWarning ) <EOL> if self . _v_pathname != '<STR_LIT:/>' : <EOL> file_ . _node_manager . cache_node ( self , self . _v_pathname ) <EOL> def _g_update_location ( self , newparentpath ) : <EOL> """<STR_LIT>""" <EOL> oldpath = self . _v_pathname <EOL> newpath = join_path ( newparentpath , self . _v_name ) <EOL> newdepth = newpath . count ( '<STR_LIT:/>' ) <EOL> self . _v_pathname = newpath <EOL> self . _v_depth = newdepth <EOL> if newdepth > self . _v_maxtreedepth : <EOL> warnings . warn ( """<STR_LIT>""" <EOL> % ( self . _v_maxtreedepth , ) , PerformanceWarning ) <EOL> node_manager = self . _v_file . _node_manager <EOL> node_manager . rename_node ( oldpath , newpath ) <EOL> self . _g_update_dependent ( ) <EOL> def _g_del_location ( self ) : <EOL> """<STR_LIT>""" <EOL> node_manager = self . _v_file . _node_manager <EOL> pathname = self . _v_pathname <EOL> if not self . _v__deleting : <EOL> node_manager . drop_from_cache ( pathname ) <EOL> node_manager . registry . pop ( pathname , None ) <EOL> self . _v_file = None <EOL> self . _v_isopen = False <EOL> self . _v_pathname = None <EOL> self . _v_name = None <EOL> self . _v_depth = None <EOL> def _g_post_init_hook ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _g_update_dependent ( self ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> self . _v_attrs . _g_update_node_location ( self ) <EOL> def _f_close ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _v_isopen : <EOL> return <EOL> myDict = self . __dict__ <EOL> if '<STR_LIT>' in myDict : <EOL> self . _v_attrs . _g_close ( ) <EOL> self . _g_del_location ( ) <EOL> myDict . clear ( ) <EOL> self . _v_isopen = False <EOL> def _g_remove ( self , recursive , force ) : <EOL> """<STR_LIT>""" <EOL> parent = self . _v_parent <EOL> parent . _g_unrefnode ( self . _v_name ) <EOL> self . _f_close ( ) <EOL> self . _g_delete ( parent ) <EOL> def _f_remove ( self , recursive = False , force = False ) : <EOL> """<STR_LIT>""" <EOL> self . _g_check_open ( ) <EOL> file_ = self . _v_file <EOL> file_ . _check_writable ( ) <EOL> if file_ . is_undo_enabled ( ) : <EOL> self . _g_remove_and_log ( recursive , force ) <EOL> else : <EOL> self . _g_remove ( recursive , force ) <EOL> def _g_remove_and_log ( self , recursive , force ) : <EOL> file_ = self . _v_file <EOL> oldpathname = self . _v_pathname <EOL> file_ . _log ( '<STR_LIT>' , oldpathname ) <EOL> move_to_shadow ( file_ , oldpathname ) <EOL> def _g_move ( self , newparent , newname ) : <EOL> """<STR_LIT>""" <EOL> oldparent = self . _v_parent <EOL> oldname = self . _v_name <EOL> oldpathname = self . _v_pathname <EOL> newparent . _g_refnode ( self , newname ) <EOL> oldparent . _g_unrefnode ( oldname ) <EOL> self . _g_del_location ( ) <EOL> self . _g_set_location ( newparent , newname ) <EOL> self . _g_new ( newparent , self . _v_name , init = False ) <EOL> self . _v_parent . _g_move_node ( oldparent . _v_objectid , oldname , <EOL> newparent . _v_objectid , newname , <EOL> oldpathname , self . _v_pathname ) <EOL> self . _g_update_dependent ( ) <EOL> def _f_rename ( self , newname , overwrite = False ) : <EOL> """<STR_LIT>""" <EOL> self . _f_move ( newname = newname , overwrite = overwrite ) <EOL> def _f_move ( self , newparent = None , newname = None , <EOL> overwrite = False , createparents = False ) : <EOL> """<STR_LIT>""" <EOL> self . _g_check_open ( ) <EOL> file_ = self . _v_file <EOL> oldparent = self . _v_parent <EOL> oldname = self . _v_name <EOL> if newparent is None and newname is None : <EOL> raise NodeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if newparent is None : <EOL> newparent = oldparent <EOL> if newname is None : <EOL> newname = oldname <EOL> if hasattr ( newparent , '<STR_LIT>' ) : <EOL> newfile = newparent . _v_file <EOL> newpath = newparent . _v_pathname <EOL> elif hasattr ( newparent , '<STR_LIT>' ) : <EOL> newfile = file_ <EOL> newpath = newparent <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" <EOL> % ( newparent , ) ) <EOL> if newfile is not file_ : <EOL> raise NodeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> file_ . _check_writable ( ) <EOL> oldpath = oldparent . _v_pathname <EOL> if newpath == oldpath and newname == oldname : <EOL> return <EOL> self . _g_check_not_contains ( newpath ) <EOL> newparent = file_ . _get_or_create_path ( newparent , createparents ) <EOL> self . _g_check_group ( newparent ) <EOL> self . _g_maybe_remove ( newparent , newname , overwrite ) <EOL> oldpathname = self . _v_pathname <EOL> self . _g_move ( newparent , newname ) <EOL> if file_ . is_undo_enabled ( ) : <EOL> self . _g_log_move ( oldpathname ) <EOL> def _g_log_move ( self , oldpathname ) : <EOL> self . _v_file . _log ( '<STR_LIT>' , oldpathname , self . _v_pathname ) <EOL> def _g_copy ( self , newparent , newname , recursive , _log = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _g_copy_as_child ( self , newparent , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . _g_copy ( newparent , self . _v_name , <EOL> recursive = False , _log = False , ** kwargs ) <EOL> def _f_copy ( self , newparent = None , newname = None , <EOL> overwrite = False , recursive = False , createparents = False , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . _g_check_open ( ) <EOL> srcfile = self . _v_file <EOL> srcparent = self . _v_parent <EOL> srcname = self . _v_name <EOL> dstparent = newparent <EOL> dstname = newname <EOL> if dstparent is None and dstname is None : <EOL> raise NodeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if dstparent is None : <EOL> dstparent = srcparent <EOL> if dstname is None : <EOL> dstname = srcname <EOL> if hasattr ( dstparent , '<STR_LIT>' ) : <EOL> dstfile = dstparent . _v_file <EOL> dstpath = dstparent . _v_pathname <EOL> elif hasattr ( dstparent , '<STR_LIT>' ) : <EOL> dstfile = srcfile <EOL> dstpath = dstparent <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" <EOL> % ( dstparent , ) ) <EOL> if dstfile is srcfile : <EOL> srcpath = srcparent . _v_pathname <EOL> if dstpath == srcpath and dstname == srcname : <EOL> raise NodeError ( <EOL> "<STR_LIT>" <EOL> % self . _v_pathname ) <EOL> if recursive : <EOL> self . _g_check_not_contains ( dstpath ) <EOL> dstparent = srcfile . _get_or_create_path ( dstparent , createparents ) <EOL> self . _g_check_group ( dstparent ) <EOL> if dstfile is not srcfile and srcfile . is_undo_enabled ( ) : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> UndoRedoWarning ) <EOL> self . _g_maybe_remove ( dstparent , dstname , overwrite ) <EOL> return self . _g_copy ( dstparent , dstname , recursive , ** kwargs ) <EOL> def _f_isvisible ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _g_check_open ( ) <EOL> return isvisiblepath ( self . _v_pathname ) <EOL> def _g_check_group ( self , node ) : <EOL> if not isinstance ( node , class_name_dict [ '<STR_LIT>' ] ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> % node . _v_pathname ) <EOL> if not isinstance ( node , class_name_dict [ '<STR_LIT>' ] ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> % node . _v_pathname ) <EOL> def _g_check_not_contains ( self , pathname ) : <EOL> mypathname = self . _v_pathname <EOL> if ( mypathname == '<STR_LIT:/>' <EOL> or pathname == mypathname <EOL> or pathname . startswith ( mypathname + '<STR_LIT:/>' ) ) : <EOL> raise NodeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % mypathname ) <EOL> def _g_maybe_remove ( self , parent , name , overwrite ) : <EOL> if name in parent : <EOL> if not overwrite : <EOL> raise NodeError ( """<STR_LIT>""" % ( parent . _v_pathname , name ) ) <EOL> parent . _f_get_child ( name ) . _f_remove ( True ) <EOL> def _g_check_name ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % name ) <EOL> def _f_getattr ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( self . _v_attrs , name ) <EOL> def _f_setattr ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> setattr ( self . _v_attrs , name , value ) <EOL> def _f_delattr ( self , name ) : <EOL> """<STR_LIT>""" <EOL> delattr ( self . _v_attrs , name ) <EOL> class NotLoggedMixin : <EOL> _AttributeSet = NotLoggedAttributeSet <EOL> def _g_log_create ( self ) : <EOL> pass <EOL> def _g_log_move ( self , oldpathname ) : <EOL> pass <EOL> def _g_remove_and_log ( self , recursive , force ) : <EOL> self . _g_remove ( recursive , force ) </s>
