idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
53,000
def set_ccc ( ctx , management_key , pin ) : controller = ctx . obj [ 'controller' ] _ensure_authenticated ( ctx , controller , pin , management_key ) controller . update_ccc ( )
Generate and set a CCC on the YubiKey .
53,001
def generate_certificate ( ctx , slot , management_key , pin , public_key , subject , valid_days ) : controller = ctx . obj [ 'controller' ] _ensure_authenticated ( ctx , controller , pin , management_key , require_pin_and_key = True ) data = public_key . read ( ) public_key = serialization . load_pem_public_key ( data...
Generate a self - signed X . 509 certificate .
53,002
def change_pin ( ctx , pin , new_pin ) : controller = ctx . obj [ 'controller' ] if not pin : pin = _prompt_pin ( ctx , prompt = 'Enter your current PIN' ) if not new_pin : new_pin = click . prompt ( 'Enter your new PIN' , default = '' , hide_input = True , show_default = False , confirmation_prompt = True , err = True...
Change the PIN code .
53,003
def change_puk ( ctx , puk , new_puk ) : controller = ctx . obj [ 'controller' ] if not puk : puk = _prompt_pin ( ctx , prompt = 'Enter your current PUK' ) if not new_puk : new_puk = click . prompt ( 'Enter your new PUK' , default = '' , hide_input = True , show_default = False , confirmation_prompt = True , err = True...
Change the PUK code .
53,004
def change_management_key ( ctx , management_key , pin , new_management_key , touch , protect , generate , force ) : controller = ctx . obj [ 'controller' ] pin_verified = _ensure_authenticated ( ctx , controller , pin , management_key , require_pin_and_key = protect , mgm_key_prompt = 'Enter your current management ke...
Change the management key .
53,005
def unblock_pin ( ctx , puk , new_pin ) : controller = ctx . obj [ 'controller' ] if not puk : puk = click . prompt ( 'Enter PUK' , default = '' , show_default = False , hide_input = True , err = True ) if not new_pin : new_pin = click . prompt ( 'Enter a new PIN' , default = '' , show_default = False , hide_input = Tr...
Unblock the PIN .
53,006
def read_object ( ctx , pin , object_id ) : controller = ctx . obj [ 'controller' ] def do_read_object ( retry = True ) : try : click . echo ( controller . get_data ( object_id ) ) except APDUError as e : if e . sw == SW . NOT_FOUND : ctx . fail ( 'No data found.' ) elif e . sw == SW . SECURITY_CONDITION_NOT_SATISFIED ...
Read arbitrary PIV object .
53,007
def write_object ( ctx , pin , management_key , object_id , data ) : controller = ctx . obj [ 'controller' ] _ensure_authenticated ( ctx , controller , pin , management_key ) def do_write_object ( retry = True ) : try : controller . put_data ( object_id , data . read ( ) ) except APDUError as e : logger . debug ( 'Fail...
Write an arbitrary PIV object .
53,008
def fido ( ctx ) : dev = ctx . obj [ 'dev' ] if dev . is_fips : try : ctx . obj [ 'controller' ] = FipsU2fController ( dev . driver ) except Exception as e : logger . debug ( 'Failed to load FipsU2fController' , exc_info = e ) ctx . fail ( 'Failed to load FIDO Application.' ) else : try : ctx . obj [ 'controller' ] = F...
Manage FIDO applications .
53,009
def info ( ctx ) : controller = ctx . obj [ 'controller' ] if controller . is_fips : click . echo ( 'FIPS Approved Mode: {}' . format ( 'Yes' if controller . is_in_fips_mode else 'No' ) ) else : if controller . has_pin : try : click . echo ( 'PIN is set, with {} tries left.' . format ( controller . get_pin_retries ( ) ...
Display status of FIDO2 application .
53,010
def reset ( ctx , force ) : n_keys = len ( list ( get_descriptors ( ) ) ) if n_keys > 1 : ctx . fail ( 'Only one YubiKey can be connected to perform a reset.' ) if not force : if not click . confirm ( 'WARNING! This will delete all FIDO credentials, ' 'including FIDO U2F credentials, and restore ' 'factory settings. Pr...
Reset all FIDO applications .
53,011
def unlock ( ctx , pin ) : controller = ctx . obj [ 'controller' ] if not controller . is_fips : ctx . fail ( 'This is not a YubiKey FIPS, and therefore' ' does not support a U2F PIN.' ) if pin is None : pin = _prompt_current_pin ( 'Enter your PIN' ) _fail_if_not_valid_pin ( ctx , pin , True ) try : controller . verify...
Verify U2F PIN for YubiKey FIPS .
53,012
def get_pin_tries ( self ) : _ , sw = self . send_cmd ( INS . VERIFY , 0 , PIN , check = None ) return tries_left ( sw , self . version )
Returns the number of PIN retries left 0 PIN authentication blocked . Note that 15 is the highest value that will be returned even if remaining tries is higher .
53,013
def cli ( ctx , device , log_level , log_file , reader ) : ctx . obj = YkmanContextObject ( ) if log_level : ykman . logging_setup . setup ( log_level , log_file = log_file ) if reader and device : ctx . fail ( '--reader and --device options can\'t be combined.' ) subcmd = next ( c for c in COMMANDS if c . name == ctx ...
Configure your YubiKey via the command line .
53,014
def list_keys ( ctx , serials , readers ) : if readers : for reader in list_readers ( ) : click . echo ( reader . name ) ctx . exit ( ) all_descriptors = get_descriptors ( ) descriptors = [ d for d in all_descriptors if d . key_type != YUBIKEY . SKY ] skys = len ( all_descriptors ) - len ( descriptors ) handled_serials...
List connected YubiKeys .
53,015
def otp ( ctx , access_code ) : ctx . obj [ 'controller' ] = OtpController ( ctx . obj [ 'dev' ] . driver ) if access_code is not None : if access_code == '' : access_code = click . prompt ( 'Enter access code' , show_default = False , err = True ) try : access_code = parse_access_code_hex ( access_code ) except Except...
Manage OTP Application .
53,016
def info ( ctx ) : dev = ctx . obj [ 'dev' ] controller = ctx . obj [ 'controller' ] slot1 , slot2 = controller . slot_status click . echo ( 'Slot 1: {}' . format ( slot1 and 'programmed' or 'empty' ) ) click . echo ( 'Slot 2: {}' . format ( slot2 and 'programmed' or 'empty' ) ) if dev . is_fips : click . echo ( 'FIPS ...
Display status of YubiKey Slots .
53,017
def swap ( ctx ) : controller = ctx . obj [ 'controller' ] click . echo ( 'Swapping slots...' ) try : controller . swap_slots ( ) except YkpersError as e : _failed_to_write_msg ( ctx , e )
Swaps the two slot configurations .
53,018
def ndef ( ctx , slot , prefix ) : dev = ctx . obj [ 'dev' ] controller = ctx . obj [ 'controller' ] if not dev . config . nfc_supported : ctx . fail ( 'NFC interface not available.' ) if not controller . slot_status [ slot - 1 ] : ctx . fail ( 'Slot {} is empty.' . format ( slot ) ) try : if prefix : controller . conf...
Select slot configuration to use for NDEF .
53,019
def delete ( ctx , slot , force ) : controller = ctx . obj [ 'controller' ] if not force and not controller . slot_status [ slot - 1 ] : ctx . fail ( 'Not possible to delete an empty slot.' ) force or click . confirm ( 'Do you really want to delete' ' the configuration of slot {}?' . format ( slot ) , abort = True , er...
Deletes the configuration of a slot .
53,020
def yubiotp ( ctx , slot , public_id , private_id , key , no_enter , force , serial_public_id , generate_private_id , generate_key ) : dev = ctx . obj [ 'dev' ] controller = ctx . obj [ 'controller' ] if public_id and serial_public_id : ctx . fail ( 'Invalid options: --public-id conflicts with ' '--serial-public-id.' )...
Program a Yubico OTP credential .
53,021
def static ( ctx , slot , password , generate , length , keyboard_layout , no_enter , force ) : controller = ctx . obj [ 'controller' ] keyboard_layout = KEYBOARD_LAYOUT [ keyboard_layout ] if password and len ( password ) > 38 : ctx . fail ( 'Password too long (maximum length is 38 characters).' ) if generate and not ...
Configure a static password .
53,022
def chalresp ( ctx , slot , key , totp , touch , force , generate ) : controller = ctx . obj [ 'controller' ] if key : if generate : ctx . fail ( 'Invalid options: --generate conflicts with KEY argument.' ) elif totp : key = parse_b32_key ( key ) else : key = parse_key ( key ) else : if force and not generate : ctx . f...
Program a challenge - response credential .
53,023
def calculate ( ctx , slot , challenge , totp , digits ) : controller = ctx . obj [ 'controller' ] if not challenge and not totp : ctx . fail ( 'No challenge provided.' ) slot1 , slot2 = controller . slot_status if ( slot == 1 and not slot1 ) or ( slot == 2 and not slot2 ) : ctx . fail ( 'Cannot perform challenge-respo...
Perform a challenge - response operation .
53,024
def hotp ( ctx , slot , key , digits , counter , no_enter , force ) : controller = ctx . obj [ 'controller' ] if not key : while True : key = click . prompt ( 'Enter a secret key (base32)' , err = True ) try : key = parse_b32_key ( key ) break except Exception as e : click . echo ( e ) force or click . confirm ( 'Progr...
Program an HMAC - SHA1 OATH - HOTP credential .
53,025
def settings ( ctx , slot , new_access_code , delete_access_code , enter , pacing , force ) : controller = ctx . obj [ 'controller' ] if ( new_access_code is not None ) and delete_access_code : ctx . fail ( '--new-access-code conflicts with --delete-access-code.' ) if not controller . slot_status [ slot - 1 ] : ctx . f...
Update the settings for a slot .
53,026
def parse_private_key ( data , password ) : if is_pem ( data ) : if b'ENCRYPTED' in data : if password is None : raise TypeError ( 'No password provided for encrypted key.' ) try : return serialization . load_pem_private_key ( data , password , backend = default_backend ( ) ) except ValueError : raise except Exception ...
Identifies decrypts and returns a cryptography private key object .
53,027
def parse_certificates ( data , password ) : if is_pem ( data ) : certs = [ ] for cert in data . split ( PEM_IDENTIFIER ) : try : certs . append ( x509 . load_pem_x509_certificate ( PEM_IDENTIFIER + cert , default_backend ( ) ) ) except Exception : pass if len ( certs ) > 0 : return certs if is_pkcs12 ( data ) : try : ...
Identifies decrypts and returns list of cryptography x509 certificates .
53,028
def get_leaf_certificates ( certs ) : issuers = [ cert . issuer . get_attributes_for_oid ( x509 . NameOID . COMMON_NAME ) for cert in certs ] leafs = [ cert for cert in certs if ( cert . subject . get_attributes_for_oid ( x509 . NameOID . COMMON_NAME ) not in issuers ) ] return leafs
Extracts the leaf certificates from a list of certificates . Leaf certificates are ones whose subject does not appear as issuer among the others .
53,029
def set_lock_code ( ctx , lock_code , new_lock_code , clear , generate , force ) : dev = ctx . obj [ 'dev' ] def prompt_new_lock_code ( ) : return prompt_lock_code ( prompt = 'Enter your new lock code' ) def prompt_current_lock_code ( ) : return prompt_lock_code ( prompt = 'Enter your current lock code' ) def change_lo...
Set or change the configuration lock code .
53,030
def nfc ( ctx , enable , disable , enable_all , disable_all , list , lock_code , force ) : if not ( list or enable_all or enable or disable_all or disable ) : ctx . fail ( 'No configuration options chosen.' ) if enable_all : enable = APPLICATION . __members__ . keys ( ) if disable_all : disable = APPLICATION . __member...
Enable or disable applications over NFC .
53,031
def info ( ctx , check_fips ) : dev = ctx . obj [ 'dev' ] if dev . is_fips and check_fips : fips_status = get_overall_fips_status ( dev . serial , dev . config ) click . echo ( 'Device type: {}' . format ( dev . device_name ) ) click . echo ( 'Serial number: {}' . format ( dev . serial or 'Not set or unreadable' ) ) if...
Show general information .
53,032
def oath ( ctx , password ) : try : controller = OathController ( ctx . obj [ 'dev' ] . driver ) ctx . obj [ 'controller' ] = controller ctx . obj [ 'settings' ] = Settings ( 'oath' ) except APDUError as e : if e . sw == SW . NOT_FOUND : ctx . fail ( "The OATH application can't be found on this YubiKey." ) raise if pas...
Manage OATH Application .
53,033
def info ( ctx ) : controller = ctx . obj [ 'controller' ] version = controller . version click . echo ( 'OATH version: {}.{}.{}' . format ( version [ 0 ] , version [ 1 ] , version [ 2 ] ) ) click . echo ( 'Password protection ' + ( 'enabled' if controller . locked else 'disabled' ) ) keys = ctx . obj [ 'settings' ] . ...
Display status of OATH application .
53,034
def reset ( ctx ) : controller = ctx . obj [ 'controller' ] click . echo ( 'Resetting OATH data...' ) old_id = controller . id controller . reset ( ) settings = ctx . obj [ 'settings' ] keys = settings . setdefault ( 'keys' , { } ) if old_id in keys : del keys [ old_id ] settings . write ( ) click . echo ( 'Success! Al...
Reset all OATH data .
53,035
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 .
53,036
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 .
53,037
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 .
53,038
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 .
53,039
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 .
53,040
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 .
53,041
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 .
53,042
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 .
53,043
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 .
53,044
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 .
53,045
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 .
53,046
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 .
53,047
def remove ( self , interval ) : done = [ ] return self . remove_interval_helper ( interval , done , should_raise_error = True )
Returns self after removing the interval and balancing .
53,048
def discard ( self , interval ) : done = [ ] return self . remove_interval_helper ( interval , done , should_raise_error = False )
Returns self after removing interval and balancing .
53,049
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 .
53,050
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 .
53,051
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 .
53,052
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 .
53,053
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 .
53,054
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 .
53,055
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 .
53,056
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 .
53,057
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 .
53,058
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 .
53,059
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 .
53,060
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 .
53,061
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 .
53,062
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 .
53,063
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 .
53,064
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 .
53,065
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 .
53,066
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 .
53,067
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 .
53,068
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 .
53,069
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 .
53,070
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 .
53,071
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 .
53,072
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 .
53,073
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 .
53,074
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 ) .
53,075
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 .
53,076
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 .
53,077
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 .
53,078
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 .
53,079
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 .
53,080
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
53,081
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
53,082
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 .
53,083
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 .
53,084
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 .
53,085
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 .
53,086
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 .
53,087
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 .
53,088
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 .
53,089
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 .
53,090
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
53,091
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
53,092
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
53,093
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
53,094
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 .
53,095
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 .
53,096
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 .
53,097
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 .
53,098
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 .
53,099
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 .