<s> from __future__ import with_statement <EOL> from __future__ import unicode_literals <EOL> import os , sys <EOL> from datetime import datetime , timedelta <EOL> import re <EOL> import struct <EOL> import threading <EOL> import winxpgui as win32gui <EOL> from winsys . _compat import * <EOL> if sys . version_info >= ( <NUM_LIT:3> , ) : <EOL> def from_pytime ( pytime ) : <EOL> return pytime <EOL> else : <EOL> def from_pytime ( pytime ) : <EOL> try : <EOL> return datetime . fromtimestamp ( int ( pytime ) ) <EOL> except ValueError : <EOL> return None <EOL> def signed_to_unsigned ( signed ) : <EOL> """<STR_LIT>""" <EOL> unsigned , = struct . unpack ( b"<STR_LIT:L>" , struct . pack ( b"<STR_LIT:l>" , signed ) ) <EOL> return unsigned <EOL> def mask_as_string ( mask , length = <NUM_LIT:32> ) : <EOL> return "<STR_LIT>" . join ( "<STR_LIT>" [ bool ( mask & ( <NUM_LIT:1> << i ) ) ] for i in range ( length ) [ : : - <NUM_LIT:1> ] ) <EOL> def mask_as_list ( mask , length = <NUM_LIT:32> ) : <EOL> return [ i for i in range ( length ) if ( ( <NUM_LIT:1> << i ) & mask ) ] <EOL> def _longword ( lo , hi ) : <EOL> return lo + ( hi * <NUM_LIT:1> << <NUM_LIT:32> ) <EOL> def _set ( obj , attr , value ) : <EOL> obj . __dict__ [ attr ] = value <EOL> def secs_as_string ( secs ) : <EOL> """<STR_LIT>""" <EOL> d = timedelta ( seconds = secs ) <EOL> days = d . days <EOL> minutes , seconds = divmod ( d . seconds , <NUM_LIT> ) <EOL> hours , minutes = divmod ( minutes , <NUM_LIT> ) <EOL> return "<STR_LIT>" . join ( [ <EOL> "<STR_LIT>" % days if days else "<STR_LIT>" , <EOL> "<STR_LIT>" % hours if hours else "<STR_LIT>" , <EOL> "<STR_LIT>" % minutes if minutes else "<STR_LIT>" , <EOL> '<STR_LIT>' % seconds if seconds else "<STR_LIT>" <EOL> ] ) <EOL> def size_as_mb ( n_bytes ) : <EOL> """<STR_LIT>""" <EOL> n_kb , n_b = divmod ( n_bytes , <NUM_LIT> ) <EOL> n_mb , n_kb = divmod ( n_kb , <NUM_LIT> ) <EOL> n_gb , n_mb = divmod ( n_mb , <NUM_LIT> ) <EOL> if n_gb > <NUM_LIT:0> : <EOL> return "<STR_LIT>" % ( n_bytes / <NUM_LIT> / <NUM_LIT> / <NUM_LIT> ) <EOL> elif n_mb > <NUM_LIT:0> : <EOL> return "<STR_LIT>" % ( n_bytes / <NUM_LIT> / <NUM_LIT> ) <EOL> elif n_kb > <NUM_LIT:0> : <EOL> return "<STR_LIT>" % ( n_bytes / <NUM_LIT> ) <EOL> else : <EOL> return "<STR_LIT>" % n_bytes <EOL> def indented ( text , level , indent = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT:\n>" . join ( "<STR_LIT>" % ( level * indent * "<STR_LIT:U+0020>" , s ) for s in text . splitlines ( ) ) <EOL> def dumped ( text , level , indent = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> return indented ( "<STR_LIT>" % indented ( text , level + <NUM_LIT:1> , indent ) or "<STR_LIT:None>" , level , indent ) <EOL> def dumped_list ( l , level , indent = <NUM_LIT:2> ) : <EOL> return dumped ( "<STR_LIT:\n>" . join ( unicode ( i ) for i in l ) , level , indent ) <EOL> def dumped_dict ( d , level , indent = <NUM_LIT:2> ) : <EOL> return dumped ( "<STR_LIT:\n>" . join ( "<STR_LIT>" % ( k , v ) for ( k , v ) in d . items ( ) ) , level , indent ) <EOL> def dumped_flags ( f , lookups , level , indent = <NUM_LIT:2> ) : <EOL> return dumped ( "<STR_LIT:\n>" . join ( lookups . names_from_value ( f ) ) or "<STR_LIT:None>" , level , indent ) <EOL> def pythonised ( string ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT:_>" . join ( s . lower ( ) for s in re . findall ( r"<STR_LIT>" , string ) ) <EOL> def string_as_pointer ( string ) : <EOL> """<STR_LIT>""" <EOL> address , length = win32gui . PyGetBufferAddressAndLen ( string ) <EOL> return address <EOL> def pointer_as_string ( pointer , length = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return win32gui . PyGetString ( pointer , length ) <EOL> def relative_to ( path1 , path0 ) : <EOL> """<STR_LIT>""" <EOL> path1 = unicode ( path1 ) . lower ( ) <EOL> path0 = unicode ( path0 ) . lower ( ) <EOL> if path1 . startswith ( path0 ) : <EOL> return path1 [ len ( path0 ) : ] <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" % ( path1 , path0 ) ) </s>
