<s> from __future__ import absolute_import , division , print_function <EOL> import abc <EOL> import binascii <EOL> import inspect <EOL> import struct <EOL> import sys <EOL> import warnings <EOL> DeprecatedIn10 = DeprecationWarning <EOL> def read_only_property ( name ) : <EOL> return property ( lambda self : getattr ( self , name ) ) <EOL> def register_interface ( iface ) : <EOL> def register_decorator ( klass ) : <EOL> verify_interface ( iface , klass ) <EOL> iface . register ( klass ) <EOL> return klass <EOL> return register_decorator <EOL> if hasattr ( int , "<STR_LIT>" ) : <EOL> int_from_bytes = int . from_bytes <EOL> else : <EOL> def int_from_bytes ( data , byteorder , signed = False ) : <EOL> assert byteorder == '<STR_LIT>' <EOL> assert not signed <EOL> if len ( data ) % <NUM_LIT:4> != <NUM_LIT:0> : <EOL> data = ( b'<STR_LIT:\x00>' * ( <NUM_LIT:4> - ( len ( data ) % <NUM_LIT:4> ) ) ) + data <EOL> result = <NUM_LIT:0> <EOL> while len ( data ) > <NUM_LIT:0> : <EOL> digit , = struct . unpack ( '<STR_LIT>' , data [ : <NUM_LIT:4> ] ) <EOL> result = ( result << <NUM_LIT:32> ) + digit <EOL> data = data [ <NUM_LIT:4> : ] <EOL> return result <EOL> def int_to_bytes ( integer , length = None ) : <EOL> hex_string = '<STR_LIT>' % integer <EOL> if length is None : <EOL> n = len ( hex_string ) <EOL> else : <EOL> n = length * <NUM_LIT:2> <EOL> return binascii . unhexlify ( hex_string . zfill ( n + ( n & <NUM_LIT:1> ) ) ) <EOL> class InterfaceNotImplemented ( Exception ) : <EOL> pass <EOL> if hasattr ( inspect , "<STR_LIT>" ) : <EOL> signature = inspect . signature <EOL> else : <EOL> signature = inspect . getargspec <EOL> def verify_interface ( iface , klass ) : <EOL> for method in iface . __abstractmethods__ : <EOL> if not hasattr ( klass , method ) : <EOL> raise InterfaceNotImplemented ( <EOL> "<STR_LIT>" . format ( klass , method ) <EOL> ) <EOL> if isinstance ( getattr ( iface , method ) , abc . abstractproperty ) : <EOL> continue <EOL> sig = signature ( getattr ( iface , method ) ) <EOL> actual = signature ( getattr ( klass , method ) ) <EOL> if sig != actual : <EOL> raise InterfaceNotImplemented ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( <EOL> klass , method , sig , actual <EOL> ) <EOL> ) <EOL> if sys . version_info >= ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> def bit_length ( x ) : <EOL> return x . bit_length ( ) <EOL> else : <EOL> def bit_length ( x ) : <EOL> return len ( bin ( x ) ) - ( <NUM_LIT:2> + ( x <= <NUM_LIT:0> ) ) <EOL> class _DeprecatedValue ( object ) : <EOL> def __init__ ( self , value , message , warning_class ) : <EOL> self . value = value <EOL> self . message = message <EOL> self . warning_class = warning_class <EOL> class _ModuleWithDeprecations ( object ) : <EOL> def __init__ ( self , module ) : <EOL> self . __dict__ [ "<STR_LIT>" ] = module <EOL> def __getattr__ ( self , attr ) : <EOL> obj = getattr ( self . _module , attr ) <EOL> if isinstance ( obj , _DeprecatedValue ) : <EOL> warnings . warn ( obj . message , obj . warning_class , stacklevel = <NUM_LIT:2> ) <EOL> obj = obj . value <EOL> return obj <EOL> def __setattr__ ( self , attr , value ) : <EOL> setattr ( self . _module , attr , value ) <EOL> def __delattr__ ( self , attr ) : <EOL> obj = getattr ( self . _module , attr ) <EOL> if isinstance ( obj , _DeprecatedValue ) : <EOL> warnings . warn ( obj . message , obj . warning_class , stacklevel = <NUM_LIT:2> ) <EOL> delattr ( self . _module , attr ) <EOL> def __dir__ ( self ) : <EOL> return [ "<STR_LIT>" ] + dir ( self . _module ) <EOL> def deprecated ( value , module_name , message , warning_class ) : <EOL> module = sys . modules [ module_name ] <EOL> if not isinstance ( module , _ModuleWithDeprecations ) : <EOL> sys . modules [ module_name ] = module = _ModuleWithDeprecations ( module ) <EOL> return _DeprecatedValue ( value , message , warning_class ) </s>
