idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
241,900
def add ( ctx , secret , name , issuer , period , oath_type , digits , touch , algorithm , counter , force ) : oath_type = OATH_TYPE [ oath_type ] algorithm = ALGO [ algorithm ] digits = int ( digits ) if not secret : while True : secret = click . prompt ( 'Enter a secret key (base32)' , err = True ) try : secret = par...
Add a new credential .
241,901
def uri ( ctx , uri , touch , force ) : if not uri : while True : uri = click . prompt ( 'Enter an OATH URI' , err = True ) try : uri = CredentialData . from_uri ( uri ) break except Exception as e : click . echo ( e ) ensure_validated ( ctx ) data = uri if data . digits == 5 and data . issuer == 'Steam' : data . digit...
Add a new credential from URI .
241,902
def list ( ctx , show_hidden , oath_type , period ) : ensure_validated ( ctx ) controller = ctx . obj [ 'controller' ] creds = [ cred for cred in controller . list ( ) if show_hidden or not cred . is_hidden ] creds . sort ( ) for cred in creds : click . echo ( cred . printable_key , nl = False ) if oath_type : click . ...
List all credentials .
241,903
def code ( ctx , show_hidden , query , single ) : ensure_validated ( ctx ) controller = ctx . obj [ 'controller' ] creds = [ ( cr , c ) for ( cr , c ) in controller . calculate_all ( ) if show_hidden or not cr . is_hidden ] creds = _search ( creds , query ) if len ( creds ) == 1 : cred , code = creds [ 0 ] if cred . to...
Generate codes .
241,904
def delete ( ctx , query , force ) : ensure_validated ( ctx ) controller = ctx . obj [ 'controller' ] creds = controller . list ( ) hits = _search ( creds , query ) if len ( hits ) == 0 : click . echo ( 'No matches, nothing to be done.' ) elif len ( hits ) == 1 : cred = hits [ 0 ] if force or ( click . confirm ( u'Dele...
Delete a credential .
241,905
def set_password ( ctx , new_password , remember ) : ensure_validated ( ctx , prompt = 'Enter your current password' ) if not new_password : new_password = click . prompt ( 'Enter your new password' , hide_input = True , confirmation_prompt = True , err = True ) controller = ctx . obj [ 'controller' ] settings = ctx . ...
Password protect the OATH credentials .
241,906
def remember_password ( ctx , forget , clear_all ) : controller = ctx . obj [ 'controller' ] settings = ctx . obj [ 'settings' ] keys = settings . setdefault ( 'keys' , { } ) if clear_all : del settings [ 'keys' ] settings . write ( ) click . echo ( 'All passwords have been cleared.' ) elif forget : if controller . id ...
Manage local password storage .
241,907
def refresh_balance ( self ) : left_depth = self . left_node . depth if self . left_node else 0 right_depth = self . right_node . depth if self . right_node else 0 self . depth = 1 + max ( left_depth , right_depth ) self . balance = right_depth - left_depth
Recalculate self . balance and self . depth based on child node values .
241,908
def compute_depth ( self ) : left_depth = self . left_node . compute_depth ( ) if self . left_node else 0 right_depth = self . right_node . compute_depth ( ) if self . right_node else 0 return 1 + max ( left_depth , right_depth )
Recursively computes true depth of the subtree . Should only be needed for debugging . Unless something is wrong the depth field should reflect the correct depth of the subtree .
241,909
def rotate ( self ) : self . refresh_balance ( ) if abs ( self . balance ) < 2 : return self my_heavy = self . balance > 0 child_heavy = self [ my_heavy ] . balance > 0 if my_heavy == child_heavy or self [ my_heavy ] . balance == 0 : return self . srotate ( ) else : return self . drotate ( )
Does rotating if necessary to balance this node and returns the new top node .
241,910
def srotate ( self ) : heavy = self . balance > 0 light = not heavy save = self [ heavy ] self [ heavy ] = save [ light ] save [ light ] = self . rotate ( ) promotees = [ iv for iv in save [ light ] . s_center if save . center_hit ( iv ) ] if promotees : for iv in promotees : save [ light ] = save [ light ] . remove ( ...
Single rotation . Assumes that balance is + - 2 .
241,911
def add ( self , interval ) : if self . center_hit ( interval ) : self . s_center . add ( interval ) return self else : direction = self . hit_branch ( interval ) if not self [ direction ] : self [ direction ] = Node . from_interval ( interval ) self . refresh_balance ( ) return self else : self [ direction ] = self [ ...
Returns self after adding the interval and balancing .
241,912
def remove ( self , interval ) : done = [ ] return self . remove_interval_helper ( interval , done , should_raise_error = True )
Returns self after removing the interval and balancing .
241,913
def discard ( self , interval ) : done = [ ] return self . remove_interval_helper ( interval , done , should_raise_error = False )
Returns self after removing interval and balancing .
241,914
def remove_interval_helper ( self , interval , done , should_raise_error ) : if self . center_hit ( interval ) : if not should_raise_error and interval not in self . s_center : done . append ( 1 ) return self try : self . s_center . remove ( interval ) except : self . print_structure ( ) raise KeyError ( interval ) if ...
Returns self after removing interval and balancing . If interval doesn t exist raise ValueError .
241,915
def search_overlap ( self , point_list ) : result = set ( ) for j in point_list : self . search_point ( j , result ) return result
Returns all intervals that overlap the point_list .
241,916
def search_point ( self , point , result ) : for k in self . s_center : if k . begin <= point < k . end : result . add ( k ) if point < self . x_center and self [ 0 ] : return self [ 0 ] . search_point ( point , result ) elif point > self . x_center and self [ 1 ] : return self [ 1 ] . search_point ( point , result ) r...
Returns all intervals that contain point .
241,917
def prune ( self ) : if not self [ 0 ] or not self [ 1 ] : direction = not self [ 0 ] result = self [ direction ] return result else : heir , self [ 0 ] = self [ 0 ] . pop_greatest_child ( ) ( heir [ 0 ] , heir [ 1 ] ) = ( self [ 0 ] , self [ 1 ] ) heir . refresh_balance ( ) heir = heir . rotate ( ) return heir
On a subtree where the root node s s_center is empty return a new subtree with no empty s_centers .
241,918
def contains_point ( self , p ) : for iv in self . s_center : if iv . contains_point ( p ) : return True branch = self [ p > self . x_center ] return branch and branch . contains_point ( p )
Returns whether this node or a child overlaps p .
241,919
def print_structure ( self , indent = 0 , tostring = False ) : nl = '\n' sp = indent * ' ' rlist = [ str ( self ) + nl ] if self . s_center : for iv in sorted ( self . s_center ) : rlist . append ( sp + ' ' + repr ( iv ) + nl ) if self . left_node : rlist . append ( sp + '<: ' ) rlist . append ( self . left_node . ...
For debugging .
241,920
def from_tuples ( cls , tups ) : ivs = [ Interval ( * t ) for t in tups ] return IntervalTree ( ivs )
Create a new IntervalTree from an iterable of 2 - or 3 - tuples where the tuple lists begin end and optionally data .
241,921
def _add_boundaries ( self , interval ) : begin = interval . begin end = interval . end if begin in self . boundary_table : self . boundary_table [ begin ] += 1 else : self . boundary_table [ begin ] = 1 if end in self . boundary_table : self . boundary_table [ end ] += 1 else : self . boundary_table [ end ] = 1
Records the boundaries of the interval in the boundary table .
241,922
def _remove_boundaries ( self , interval ) : begin = interval . begin end = interval . end if self . boundary_table [ begin ] == 1 : del self . boundary_table [ begin ] else : self . boundary_table [ begin ] -= 1 if self . boundary_table [ end ] == 1 : del self . boundary_table [ end ] else : self . boundary_table [ en...
Removes the boundaries of the interval from the boundary table .
241,923
def add ( self , interval ) : if interval in self : return if interval . is_null ( ) : raise ValueError ( "IntervalTree: Null Interval objects not allowed in IntervalTree:" " {0}" . format ( interval ) ) if not self . top_node : self . top_node = Node . from_interval ( interval ) else : self . top_node = self . top_nod...
Adds an interval to the tree if not already present .
241,924
def remove ( self , interval ) : if interval not in self : raise ValueError self . top_node = self . top_node . remove ( interval ) self . all_intervals . remove ( interval ) self . _remove_boundaries ( interval )
Removes an interval from the tree if present . If not raises ValueError .
241,925
def discard ( self , interval ) : if interval not in self : return self . all_intervals . discard ( interval ) self . top_node = self . top_node . discard ( interval ) self . _remove_boundaries ( interval )
Removes an interval from the tree if present . If not does nothing .
241,926
def difference ( self , other ) : ivs = set ( ) for iv in self : if iv not in other : ivs . add ( iv ) return IntervalTree ( ivs )
Returns a new tree comprising all intervals in self but not in other .
241,927
def intersection ( self , other ) : ivs = set ( ) shorter , longer = sorted ( [ self , other ] , key = len ) for iv in shorter : if iv in longer : ivs . add ( iv ) return IntervalTree ( ivs )
Returns a new tree of all intervals common to both self and other .
241,928
def intersection_update ( self , other ) : ivs = list ( self ) for iv in ivs : if iv not in other : self . remove ( iv )
Removes intervals from self unless they also exist in other .
241,929
def symmetric_difference ( self , other ) : if not isinstance ( other , set ) : other = set ( other ) me = set ( self ) ivs = me . difference ( other ) . union ( other . difference ( me ) ) return IntervalTree ( ivs )
Return a tree with elements only in self or other but not both .
241,930
def symmetric_difference_update ( self , other ) : other = set ( other ) ivs = list ( self ) for iv in ivs : if iv in other : self . remove ( iv ) other . remove ( iv ) self . update ( other )
Throws out all intervals except those only in self or other not both .
241,931
def remove_overlap ( self , begin , end = None ) : hitlist = self . at ( begin ) if end is None else self . overlap ( begin , end ) for iv in hitlist : self . remove ( iv )
Removes all intervals overlapping the given point or range .
241,932
def remove_envelop ( self , begin , end ) : hitlist = self . envelop ( begin , end ) for iv in hitlist : self . remove ( iv )
Removes all intervals completely enveloped in the given range .
241,933
def find_nested ( self ) : result = { } def add_if_nested ( ) : if parent . contains_interval ( child ) : if parent not in result : result [ parent ] = set ( ) result [ parent ] . add ( child ) long_ivs = sorted ( self . all_intervals , key = Interval . length , reverse = True ) for i , parent in enumerate ( long_ivs )...
Returns a dictionary mapping parent intervals to sets of intervals overlapped by and contained in the parent .
241,934
def overlaps ( self , begin , end = None ) : if end is not None : return self . overlaps_range ( begin , end ) elif isinstance ( begin , Number ) : return self . overlaps_point ( begin ) else : return self . overlaps_range ( begin . begin , begin . end )
Returns whether some interval in the tree overlaps the given point or range .
241,935
def overlaps_point ( self , p ) : if self . is_empty ( ) : return False return bool ( self . top_node . contains_point ( p ) )
Returns whether some interval in the tree overlaps p .
241,936
def overlaps_range ( self , begin , end ) : if self . is_empty ( ) : return False elif begin >= end : return False elif self . overlaps_point ( begin ) : return True return any ( self . overlaps_point ( bound ) for bound in self . boundary_table if begin < bound < end )
Returns whether some interval in the tree overlaps the given range . Returns False if given a null interval over which to test .
241,937
def split_overlaps ( self ) : if not self : return if len ( self . boundary_table ) == 2 : return bounds = sorted ( self . boundary_table ) new_ivs = set ( ) for lbound , ubound in zip ( bounds [ : - 1 ] , bounds [ 1 : ] ) : for iv in self [ lbound ] : new_ivs . add ( Interval ( lbound , ubound , iv . data ) ) self . _...
Finds all intervals with overlapping ranges and splits them along the range boundaries .
241,938
def at ( self , p ) : root = self . top_node if not root : return set ( ) return root . search_point ( p , set ( ) )
Returns the set of all intervals that contain p .
241,939
def envelop ( self , begin , end = None ) : root = self . top_node if not root : return set ( ) if end is None : iv = begin return self . envelop ( iv . begin , iv . end ) elif begin >= end : return set ( ) result = root . search_point ( begin , set ( ) ) boundary_table = self . boundary_table bound_begin = boundary_ta...
Returns the set of all intervals fully contained in the range [ begin end ) .
241,940
def defnoun ( self , singular , plural ) : self . checkpat ( singular ) self . checkpatplural ( plural ) self . pl_sb_user_defined . extend ( ( singular , plural ) ) self . si_sb_user_defined . extend ( ( plural , singular ) ) return 1
Set the noun plural of singular to plural .
241,941
def defverb ( self , s1 , p1 , s2 , p2 , s3 , p3 ) : self . checkpat ( s1 ) self . checkpat ( s2 ) self . checkpat ( s3 ) self . checkpatplural ( p1 ) self . checkpatplural ( p2 ) self . checkpatplural ( p3 ) self . pl_v_user_defined . extend ( ( s1 , p1 , s2 , p2 , s3 , p3 ) ) return 1
Set the verb plurals for s1 s2 and s3 to p1 p2 and p3 respectively .
241,942
def defadj ( self , singular , plural ) : self . checkpat ( singular ) self . checkpatplural ( plural ) self . pl_adj_user_defined . extend ( ( singular , plural ) ) return 1
Set the adjective plural of singular to plural .
241,943
def defa ( self , pattern ) : self . checkpat ( pattern ) self . A_a_user_defined . extend ( ( pattern , "a" ) ) return 1
Define the indefinate article as a for words matching pattern .
241,944
def defan ( self , pattern ) : self . checkpat ( pattern ) self . A_a_user_defined . extend ( ( pattern , "an" ) ) return 1
Define the indefinate article as an for words matching pattern .
241,945
def checkpat ( self , pattern ) : if pattern is None : return try : re . match ( pattern , "" ) except re . error : print3 ( "\nBad user-defined singular pattern:\n\t%s\n" % pattern ) raise BadUserDefinedPatternError
check for errors in a regex pattern
241,946
def classical ( self , ** kwargs ) : classical_mode = list ( def_classical . keys ( ) ) if not kwargs : self . classical_dict = all_classical . copy ( ) return if "all" in kwargs : if kwargs [ "all" ] : self . classical_dict = all_classical . copy ( ) else : self . classical_dict = no_classical . copy ( ) for k , v in ...
turn classical mode on and off for various categories
241,947
def num ( self , count = None , show = None ) : if count is not None : try : self . persistent_count = int ( count ) except ValueError : raise BadNumValueError if ( show is None ) or show : return str ( count ) else : self . persistent_count = None return ""
Set the number to be used in other method calls .
241,948
def _get_value_from_ast ( self , obj ) : if isinstance ( obj , ast . Num ) : return obj . n elif isinstance ( obj , ast . Str ) : return obj . s elif isinstance ( obj , ast . List ) : return [ self . _get_value_from_ast ( e ) for e in obj . elts ] elif isinstance ( obj , ast . Tuple ) : return tuple ( [ self . _get_val...
Return the value of the ast object .
241,949
def _string_to_substitute ( self , mo , methods_dict ) : matched_text , f_name = mo . groups ( ) if f_name not in methods_dict : return matched_text a_tree = ast . parse ( matched_text ) args_list = [ self . _get_value_from_ast ( a ) for a in a_tree . body [ 0 ] . value . args ] kwargs_list = { kw . arg : self . _get_v...
Return the string to be substituted for the match .
241,950
def inflect ( self , text ) : save_persistent_count = self . persistent_count methods_dict = { "plural" : self . plural , "plural_adj" : self . plural_adj , "plural_noun" : self . plural_noun , "plural_verb" : self . plural_verb , "singular_noun" : self . singular_noun , "a" : self . a , "an" : self . a , "no" : self ....
Perform inflections in a string .
241,951
def plural ( self , text , count = None ) : pre , word , post = self . partition_word ( text ) if not word : return text plural = self . postprocess ( word , self . _pl_special_adjective ( word , count ) or self . _pl_special_verb ( word , count ) or self . _plnoun ( word , count ) , ) return "{}{}{}" . format ( pre , ...
Return the plural of text .
241,952
def plural_noun ( self , text , count = None ) : pre , word , post = self . partition_word ( text ) if not word : return text plural = self . postprocess ( word , self . _plnoun ( word , count ) ) return "{}{}{}" . format ( pre , plural , post )
Return the plural of text where text is a noun .
241,953
def plural_verb ( self , text , count = None ) : pre , word , post = self . partition_word ( text ) if not word : return text plural = self . postprocess ( word , self . _pl_special_verb ( word , count ) or self . _pl_general_verb ( word , count ) , ) return "{}{}{}" . format ( pre , plural , post )
Return the plural of text where text is a verb .
241,954
def plural_adj ( self , text , count = None ) : pre , word , post = self . partition_word ( text ) if not word : return text plural = self . postprocess ( word , self . _pl_special_adjective ( word , count ) or word ) return "{}{}{}" . format ( pre , plural , post )
Return the plural of text where text is an adjective .
241,955
def compare ( self , word1 , word2 ) : return ( self . _plequal ( word1 , word2 , self . plural_noun ) or self . _plequal ( word1 , word2 , self . plural_verb ) or self . _plequal ( word1 , word2 , self . plural_adj ) )
compare word1 and word2 for equality regardless of plurality
241,956
def compare_nouns ( self , word1 , word2 ) : return self . _plequal ( word1 , word2 , self . plural_noun )
compare word1 and word2 for equality regardless of plurality word1 and word2 are to be treated as nouns
241,957
def compare_verbs ( self , word1 , word2 ) : return self . _plequal ( word1 , word2 , self . plural_verb )
compare word1 and word2 for equality regardless of plurality word1 and word2 are to be treated as verbs
241,958
def compare_adjs ( self , word1 , word2 ) : return self . _plequal ( word1 , word2 , self . plural_adj )
compare word1 and word2 for equality regardless of plurality word1 and word2 are to be treated as adjectives
241,959
def singular_noun ( self , text , count = None , gender = None ) : pre , word , post = self . partition_word ( text ) if not word : return text sing = self . _sinoun ( word , count = count , gender = gender ) if sing is not False : plural = self . postprocess ( word , self . _sinoun ( word , count = count , gender = ge...
Return the singular of text where text is a plural noun .
241,960
def a ( self , text , count = 1 ) : mo = re . search ( r"\A(\s*)(?:an?\s+)?(.+?)(\s*)\Z" , text , re . IGNORECASE ) if mo : word = mo . group ( 2 ) if not word : return text pre = mo . group ( 1 ) post = mo . group ( 3 ) result = self . _indef_article ( word , count ) return "{}{}{}" . format ( pre , result , post ) re...
Return the appropriate indefinite article followed by text .
241,961
def no ( self , text , count = None ) : if count is None and self . persistent_count is not None : count = self . persistent_count if count is None : count = 0 mo = re . search ( r"\A(\s*)(.+?)(\s*)\Z" , text ) pre = mo . group ( 1 ) word = mo . group ( 2 ) post = mo . group ( 3 ) if str ( count ) . lower ( ) in pl_cou...
If count is 0 no zero or nil return no followed by the plural of text .
241,962
def present_participle ( self , word ) : plv = self . plural_verb ( word , 2 ) for pat , repl in ( ( r"ie$" , r"y" ) , ( r"ue$" , r"u" ) , ( r"([auy])e$" , r"\g<1>" ) , ( r"ski$" , r"ski" ) , ( r"[^b]i$" , r"" ) , ( r"^(are|were)$" , r"be" ) , ( r"^(had)$" , r"hav" ) , ( r"^(hoe)$" , r"\g<1>" ) , ( r"([^e])e$" , r"\g<1...
Return the present participle for word .
241,963
def ordinal ( self , num ) : if re . match ( r"\d" , str ( num ) ) : try : num % 2 n = num except TypeError : if "." in str ( num ) : try : n = int ( num [ - 1 ] ) except ValueError : n = int ( num [ : - 1 ] ) else : n = int ( num ) try : post = nth [ n % 100 ] except KeyError : post = nth [ n % 10 ] return "{}{}" . fo...
Return the ordinal of num .
241,964
def join ( self , words , sep = None , sep_spaced = True , final_sep = None , conj = "and" , conj_spaced = True , ) : if not words : return "" if len ( words ) == 1 : return words [ 0 ] if conj_spaced : if conj == "" : conj = " " else : conj = " %s " % conj if len ( words ) == 2 : return "{}{}{}" . format ( words [ 0 ]...
Join words into a list .
241,965
def _int ( int_or_str : Any ) -> int : "return an integer where a single character string may be expected" if isinstance ( int_or_str , str ) : return ord ( int_or_str ) if isinstance ( int_or_str , bytes ) : return int_or_str [ 0 ] return int ( int_or_str )
return an integer where a single character string may be expected
241,966
def _console ( console : Any ) -> Any : try : return console . console_c except AttributeError : warnings . warn ( ( "Falsy console parameters are deprecated, " "always use the root console instance returned by " "console_init_root." ) , DeprecationWarning , stacklevel = 3 , ) return ffi . NULL
Return a cffi console .
241,967
def _new_from_cdata ( cls , cdata : Any ) -> "Color" : return cls ( cdata . r , cdata . g , cdata . b )
new in libtcod - cffi
241,968
def _describe_bitmask ( bits : int , table : Dict [ Any , str ] , default : str = "0" ) -> str : result = [ ] for bit , name in table . items ( ) : if bit & bits : result . append ( name ) if not result : return default return "|" . join ( result )
Returns a bitmask in human readable form .
241,969
def _pixel_to_tile ( x : float , y : float ) -> Tuple [ float , float ] : xy = tcod . ffi . new ( "double[2]" , ( x , y ) ) tcod . lib . TCOD_sys_pixel_to_tile ( xy , xy + 1 ) return xy [ 0 ] , xy [ 1 ]
Convert pixel coordinates to tile coordinates .
241,970
def get ( ) -> Iterator [ Any ] : sdl_event = tcod . ffi . new ( "SDL_Event*" ) while tcod . lib . SDL_PollEvent ( sdl_event ) : if sdl_event . type in _SDL_TO_CLASS_TABLE : yield _SDL_TO_CLASS_TABLE [ sdl_event . type ] . from_sdl_event ( sdl_event ) else : yield Undefined . from_sdl_event ( sdl_event )
Return an iterator for all pending events .
241,971
def wait ( timeout : Optional [ float ] = None ) -> Iterator [ Any ] : if timeout is not None : tcod . lib . SDL_WaitEventTimeout ( tcod . ffi . NULL , int ( timeout * 1000 ) ) else : tcod . lib . SDL_WaitEvent ( tcod . ffi . NULL ) return get ( )
Block until events exist then return an event iterator .
241,972
def get_mouse_state ( ) -> MouseState : xy = tcod . ffi . new ( "int[2]" ) buttons = tcod . lib . SDL_GetMouseState ( xy , xy + 1 ) x , y = _pixel_to_tile ( * xy ) return MouseState ( ( xy [ 0 ] , xy [ 1 ] ) , ( int ( x ) , int ( y ) ) , buttons )
Return the current state of the mouse .
241,973
def deprecate ( message : str , category : Any = DeprecationWarning , stacklevel : int = 0 ) -> Callable [ [ F ] , F ] : def decorator ( func : F ) -> F : if not __debug__ : return func @ functools . wraps ( func ) def wrapper ( * args , ** kargs ) : warnings . warn ( message , category , stacklevel = stacklevel + 2 ) ...
Return a decorator which adds a warning to functions .
241,974
def pending_deprecate ( message : str = "This function may be deprecated in the future." " Consider raising an issue on GitHub if you need this feature." , category : Any = PendingDeprecationWarning , stacklevel : int = 0 , ) -> Callable [ [ F ] , F ] : return deprecate ( message , category , stacklevel )
Like deprecate but the default parameters are filled out for a generic pending deprecation warning .
241,975
def _format_char ( char ) : if char is None : return - 1 if isinstance ( char , _STRTYPES ) and len ( char ) == 1 : return ord ( char ) try : return int ( char ) except : raise TypeError ( 'char single character string, integer, or None\nReceived: ' + repr ( char ) )
Prepares a single character for passing to ctypes calls needs to return an integer but can also pass None which will keep the current character instead of overwriting it .
241,976
def _format_str ( string ) : if isinstance ( string , _STRTYPES ) : if _IS_PYTHON3 : array = _array . array ( 'I' ) array . frombytes ( string . encode ( _utf32_codec ) ) else : if isinstance ( string , unicode ) : array = _array . array ( b'I' ) array . fromstring ( string . encode ( _utf32_codec ) ) else : array = _a...
Attempt fast string handing by decoding directly into an array .
241,977
def _getImageSize ( filename ) : result = None file = open ( filename , 'rb' ) if file . read ( 8 ) == b'\x89PNG\r\n\x1a\n' : while 1 : length , = _struct . unpack ( '>i' , file . read ( 4 ) ) chunkID = file . read ( 4 ) if chunkID == '' : break if chunkID == b'IHDR' : result = _struct . unpack ( '>ii' , file . read ( ...
Try to get the width and height of a bmp of png image file
241,978
def init ( width , height , title = None , fullscreen = False , renderer = 'SDL' ) : RENDERERS = { 'GLSL' : 0 , 'OPENGL' : 1 , 'SDL' : 2 } global _rootinitialized , _rootConsoleRef if not _fontinitialized : set_font ( _os . path . join ( __path__ [ 0 ] , 'terminal8x8.png' ) , None , None , True , True ) if renderer . u...
Start the main console with the given width and height and return the root console .
241,979
def screenshot ( path = None ) : if not _rootinitialized : raise TDLError ( 'Initialize first with tdl.init' ) if isinstance ( path , str ) : _lib . TCOD_sys_save_screenshot ( _encodeString ( path ) ) elif path is None : filelist = _os . listdir ( '.' ) n = 1 filename = 'screenshot%.3i.png' % n while filename in fileli...
Capture the screen and save it as a png file .
241,980
def _normalizePoint ( self , x , y ) : x = int ( x ) y = int ( y ) assert ( - self . width <= x < self . width ) and ( - self . height <= y < self . height ) , ( '(%i, %i) is an invalid postition on %s' % ( x , y , self ) ) return ( x % self . width , y % self . height )
Check if a point is in bounds and make minor adjustments .
241,981
def _normalizeRect ( self , x , y , width , height ) : x , y = self . _normalizePoint ( x , y ) assert width is None or isinstance ( width , _INTTYPES ) , 'width must be an integer or None, got %s' % repr ( width ) assert height is None or isinstance ( height , _INTTYPES ) , 'height must be an integer or None, got %s' ...
Check if the rectangle is in bounds and make minor adjustments . raise AssertionError s for any problems
241,982
def _normalizeCursor ( self , x , y ) : width , height = self . get_size ( ) assert width != 0 and height != 0 , 'can not print on a console with a width or height of zero' while x >= width : x -= width y += 1 while y >= height : if self . _scrollMode == 'scroll' : y -= 1 self . scroll ( 0 , - 1 ) elif self . _scrollMo...
return the normalized the cursor position .
241,983
def set_mode ( self , mode ) : MODES = [ 'error' , 'scroll' ] if mode . lower ( ) not in MODES : raise TDLError ( 'mode must be one of %s, got %s' % ( MODES , repr ( mode ) ) ) self . _scrollMode = mode . lower ( )
Configure how this console will react to the cursor writing past the end if the console .
241,984
def print_str ( self , string ) : x , y = self . _cursor for char in string : if char == '\n' : x = 0 y += 1 continue if char == '\r' : x = 0 continue x , y = self . _normalizeCursor ( x , y ) self . draw_char ( x , y , char , self . _fg , self . _bg ) x += 1 self . _cursor = ( x , y )
Print a string at the virtual cursor .
241,985
def write ( self , string ) : x , y = self . _normalizeCursor ( * self . _cursor ) width , height = self . get_size ( ) wrapper = _textwrap . TextWrapper ( initial_indent = ( ' ' * x ) , width = width ) writeLines = [ ] for line in string . split ( '\n' ) : if line : writeLines += wrapper . wrap ( line ) wrapper . init...
This method mimics basic file - like behaviour .
241,986
def draw_char ( self , x , y , char , fg = Ellipsis , bg = Ellipsis ) : _put_char_ex ( self . console_c , x , y , _format_char ( char ) , _format_color ( fg , self . _fg ) , _format_color ( bg , self . _bg ) , 1 )
Draws a single character .
241,987
def draw_str ( self , x , y , string , fg = Ellipsis , bg = Ellipsis ) : x , y = self . _normalizePoint ( x , y ) fg , bg = _format_color ( fg , self . _fg ) , _format_color ( bg , self . _bg ) width , height = self . get_size ( ) def _drawStrGen ( x = x , y = y , string = string , width = width , height = height ) : f...
Draws a string starting at x and y .
241,988
def draw_rect ( self , x , y , width , height , string , fg = Ellipsis , bg = Ellipsis ) : x , y , width , height = self . _normalizeRect ( x , y , width , height ) fg , bg = _format_color ( fg , self . _fg ) , _format_color ( bg , self . _bg ) char = _format_char ( string ) grid = _itertools . product ( ( x for x in r...
Draws a rectangle starting from x and y and extending to width and height .
241,989
def blit ( self , source , x = 0 , y = 0 , width = None , height = None , srcX = 0 , srcY = 0 , fg_alpha = 1.0 , bg_alpha = 1.0 ) : assert isinstance ( source , ( Console , Window ) ) , "source muse be a Window or Console instance" x , y , width , height = self . _normalizeRect ( x , y , width , height ) srcX , srcY , ...
Blit another console or Window onto the current console .
241,990
def get_cursor ( self ) : x , y = self . _cursor width , height = self . parent . get_size ( ) while x >= width : x -= width y += 1 if y >= height and self . scrollMode == 'scroll' : y = height - 1 return x , y
Return the virtual cursor position .
241,991
def move ( self , x , y ) : self . _cursor = self . _normalizePoint ( x , y )
Move the virtual cursor .
241,992
def scroll ( self , x , y ) : assert isinstance ( x , _INTTYPES ) , "x must be an integer, got %s" % repr ( x ) assert isinstance ( y , _INTTYPES ) , "y must be an integer, got %s" % repr ( x ) def getSlide ( x , length ) : if x > 0 : srcx = 0 length -= x elif x < 0 : srcx = abs ( x ) x = 0 length -= srcx else : srcx =...
Scroll the contents of the console in the direction of x y .
241,993
def _newConsole ( cls , console ) : self = cls . __new__ ( cls ) _BaseConsole . __init__ ( self ) self . console_c = console self . console = self self . width = _lib . TCOD_console_get_width ( console ) self . height = _lib . TCOD_console_get_height ( console ) return self
Make a Console instance from a console ctype
241,994
def _root_unhook ( self ) : global _rootinitialized , _rootConsoleRef if ( _rootConsoleRef and _rootConsoleRef ( ) is self ) : unhooked = _lib . TCOD_console_new ( self . width , self . height ) _lib . TCOD_console_blit ( self . console_c , 0 , 0 , self . width , self . height , unhooked , 0 , 0 , 1 , 1 ) _rootinitiali...
Change this root console into a normal Console object and delete the root console from TCOD
241,995
def _set_char ( self , x , y , char , fg = None , bg = None , bgblend = _lib . TCOD_BKGND_SET ) : return _put_char_ex ( self . console_c , x , y , char , fg , bg , bgblend )
Sets a character . This is called often and is designed to be as fast as possible .
241,996
def _set_batch ( self , batch , fg , bg , bgblend = 1 , nullChar = False ) : for ( x , y ) , char in batch : self . _set_char ( x , y , char , fg , bg , bgblend )
Try to perform a batch operation otherwise fall back to _set_char . If fg and bg are defined then this is faster but not by very much .
241,997
def _translate ( self , x , y ) : return self . parent . _translate ( ( x + self . x ) , ( y + self . y ) )
Convertion x and y to their position on the root Console
241,998
def _pycall_path_old ( x1 : int , y1 : int , x2 : int , y2 : int , handle : Any ) -> float : func , userData = ffi . from_handle ( handle ) return func ( x1 , y1 , x2 , y2 , userData )
libtcodpy style callback needs to preserve the old userData issue .
241,999
def _pycall_path_simple ( x1 : int , y1 : int , x2 : int , y2 : int , handle : Any ) -> float : return ffi . from_handle ( handle ) ( x1 , y1 , x2 , y2 )
Does less and should run faster just calls the handle function .