<s> __author__ = '<STR_LIT>' <EOL> import os <EOL> import sys <EOL> from pyorient . exceptions import PyOrientConnectionException , PyOrientDatabaseException <EOL> from pyorient . otypes import OrientRecordLink <EOL> def is_debug_active ( ) : <EOL> if '<STR_LIT>' in os . environ : <EOL> if os . environ [ '<STR_LIT>' ] . lower ( ) in ( '<STR_LIT:1>' , '<STR_LIT:true>' ) : <EOL> return True <EOL> return False <EOL> def is_debug_verbose ( ) : <EOL> if '<STR_LIT>' in os . environ : <EOL> if is_debug_active ( ) and os . environ [ '<STR_LIT>' ] . lower ( ) in ( '<STR_LIT:1>' , '<STR_LIT:true>' ) : <EOL> return True <EOL> return False <EOL> def dlog ( msg ) : <EOL> if is_debug_active ( ) : <EOL> print ( "<STR_LIT>" % msg ) <EOL> class Singleton ( type ) : <EOL> _instances = { } <EOL> def __call__ ( cls , * args , ** kwargs ) : <EOL> if cls not in cls . _instances : <EOL> cls . _instances [ cls ] = super ( Singleton , cls ) . __call__ ( * args , ** kwargs ) <EOL> return cls . _instances [ cls ] <EOL> def need_connected ( wrap ) : <EOL> def wrap_function ( * args , ** kwargs ) : <EOL> if not args [ <NUM_LIT:0> ] . is_connected ( ) : <EOL> raise PyOrientConnectionException ( <EOL> "<STR_LIT>" , [ ] ) <EOL> return wrap ( * args , ** kwargs ) <EOL> return wrap_function <EOL> def need_db_opened ( wrap ) : <EOL> @ need_connected <EOL> def wrap_function ( * args , ** kwargs ) : <EOL> if args [ <NUM_LIT:0> ] . database_opened ( ) is None : <EOL> raise PyOrientDatabaseException ( <EOL> "<STR_LIT>" , [ ] ) <EOL> return wrap ( * args , ** kwargs ) <EOL> return wrap_function <EOL> def parse_cluster_id ( cluster_id ) : <EOL> try : <EOL> if isinstance ( cluster_id , str ) : <EOL> pass <EOL> elif isinstance ( cluster_id , int ) : <EOL> cluster_id = str ( cluster_id ) <EOL> elif isinstance ( cluster_id , bytes ) : <EOL> cluster_id = cluster_id . decode ( "<STR_LIT:utf-8>" ) <EOL> elif isinstance ( cluster_id , OrientRecordLink ) : <EOL> cluster_id = cluster_id . get ( ) <EOL> elif sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> and isinstance ( cluster_id , unicode ) : <EOL> cluster_id = cluster_id . encode ( '<STR_LIT:utf-8>' ) <EOL> _cluster_id , _position = cluster_id . split ( '<STR_LIT::>' ) <EOL> if _cluster_id [ <NUM_LIT:0> ] is '<STR_LIT:#>' : <EOL> _cluster_id = _cluster_id [ <NUM_LIT:1> : ] <EOL> except ( AttributeError , ValueError ) : <EOL> _cluster_id = cluster_id <EOL> return _cluster_id <EOL> def parse_cluster_position ( _cluster_position ) : <EOL> try : <EOL> if isinstance ( _cluster_position , str ) : <EOL> pass <EOL> elif isinstance ( _cluster_position , int ) : <EOL> _cluster_position = str ( _cluster_position ) <EOL> elif isinstance ( _cluster_position , bytes ) : <EOL> _cluster_position = _cluster_position . decode ( "<STR_LIT:utf-8>" ) <EOL> elif isinstance ( _cluster_position , OrientRecordLink ) : <EOL> _cluster_position = _cluster_position . get ( ) <EOL> _cluster , _position = _cluster_position . split ( '<STR_LIT::>' ) <EOL> except ( AttributeError , ValueError ) : <EOL> _position = _cluster_position <EOL> return _position <EOL> if sys . version < '<STR_LIT:3>' : <EOL> import codecs <EOL> def u ( x ) : <EOL> return codecs . unicode_escape_decode ( x ) [ <NUM_LIT:0> ] <EOL> def to_unicode ( x ) : <EOL> return str ( x ) . decode ( '<STR_LIT:utf-8>' ) <EOL> def to_str ( x ) : <EOL> return unicode ( x ) . encode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> def u ( x ) : <EOL> return x <EOL> def to_str ( x ) : <EOL> return str ( x ) <EOL> def to_unicode ( x ) : <EOL> return str ( x ) </s>
