idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
244,600
def error_string ( self ) : if self . has_correct_call_count ( ) : return '' return '{} instead of {} {} ' . format ( self . _restriction_string ( ) , self . count , pluralize ( 'time' , self . count ) )
Returns a well formed error message
244,601
def patch_for ( self , path ) : if path not in self . _patches : self . _patches [ path ] = Patch ( path ) return self . _patches [ path ]
Returns the Patch for the target path creating it if necessary .
244,602
def proxy_for ( self , obj ) : obj_id = id ( obj ) if obj_id not in self . _proxies : self . _proxies [ obj_id ] = Proxy ( obj ) return self . _proxies [ obj_id ]
Returns the Proxy for the target object creating it if necessary .
244,603
def teardown ( self ) : for proxy in self . _proxies . values ( ) : proxy . restore_original_object ( ) for patch in self . _patches . values ( ) : patch . restore_original_object ( )
Restores all doubled objects to their original state .
244,604
def verify ( self ) : if self . _is_verified : return for proxy in self . _proxies . values ( ) : proxy . verify ( ) self . _is_verified = True
Verifies expectations on all doubled objects .
244,605
def restore_original_method ( self ) : if self . _target . is_class_or_module ( ) : setattr ( self . _target . obj , self . _method_name , self . _original_method ) if self . _method_name == '__new__' and sys . version_info >= ( 3 , 0 ) : _restore__new__ ( self . _target . obj , self . _original_method ) else : setattr...
Replaces the proxy method on the target object with its original value .
244,606
def _hijack_target ( self ) : if self . _target . is_class_or_module ( ) : setattr ( self . _target . obj , self . _method_name , self ) elif self . _attr . kind == 'property' : proxy_property = ProxyProperty ( double_name ( self . _method_name ) , self . _original_method , ) setattr ( self . _target . obj . __class__ ...
Replaces the target method on the target object with the proxy method .
244,607
def _raise_exception ( self , args , kwargs ) : error_message = ( "Received unexpected call to '{}' on {!r}. The supplied arguments " "{} do not match any available allowances." ) raise UnallowedMethodCallError ( error_message . format ( self . _method_name , self . _target . obj , build_argument_repr_string ( args , ...
Raises an UnallowedMethodCallError with a useful message .
244,608
def method_double_for ( self , method_name ) : if method_name not in self . _method_doubles : self . _method_doubles [ method_name ] = MethodDouble ( method_name , self . _target ) return self . _method_doubles [ method_name ]
Returns the method double for the provided method name creating one if necessary .
244,609
def _get_doubles_target ( module , class_name , path ) : try : doubles_target = getattr ( module , class_name ) if isinstance ( doubles_target , ObjectDouble ) : return doubles_target . _doubles_target if not isclass ( doubles_target ) : raise VerifyingDoubleImportError ( 'Path does not point to a class: {}.' . format ...
Validate and return the class to be doubled .
244,610
def and_raise ( self , exception , * args , ** kwargs ) : def proxy_exception ( * proxy_args , ** proxy_kwargs ) : raise exception self . _return_value = proxy_exception return self
Causes the double to raise the provided exception when called .
244,611
def and_raise_future ( self , exception ) : future = _get_future ( ) future . set_exception ( exception ) return self . and_return ( future )
Similar to and_raise but the doubled method returns a future .
244,612
def and_return_future ( self , * return_values ) : futures = [ ] for value in return_values : future = _get_future ( ) future . set_result ( value ) futures . append ( future ) return self . and_return ( * futures )
Similar to and_return but the doubled method returns a future .
244,613
def and_return ( self , * return_values ) : if not return_values : raise TypeError ( 'and_return() expected at least 1 return value' ) return_values = list ( return_values ) final_value = return_values . pop ( ) self . and_return_result_of ( lambda : return_values . pop ( 0 ) if return_values else final_value ) return ...
Set a return value for an allowance
244,614
def and_return_result_of ( self , return_value ) : if not check_func_takes_args ( return_value ) : self . _return_value = lambda * args , ** kwargs : return_value ( ) else : self . _return_value = return_value return self
Causes the double to return the result of calling the provided value .
244,615
def with_args ( self , * args , ** kwargs ) : self . args = args self . kwargs = kwargs self . verify_arguments ( ) return self
Declares that the double can only be called with the provided arguments .
244,616
def with_args_validator ( self , matching_function ) : self . args = None self . kwargs = None self . _custom_matcher = matching_function return self
Define a custom function for testing arguments
244,617
def satisfy_exact_match ( self , args , kwargs ) : if self . args is None and self . kwargs is None : return False elif self . args is _any and self . kwargs is _any : return True elif args == self . args and kwargs == self . kwargs : return True elif len ( args ) != len ( self . args ) or len ( kwargs ) != len ( self ...
Returns a boolean indicating whether or not the stub will accept the provided arguments .
244,618
def satisfy_custom_matcher ( self , args , kwargs ) : if not self . _custom_matcher : return False try : return self . _custom_matcher ( * args , ** kwargs ) except Exception : return False
Return a boolean indicating if the args satisfy the stub
244,619
def return_value ( self , * args , ** kwargs ) : self . _called ( ) return self . _return_value ( * args , ** kwargs )
Extracts the real value to be returned from the wrapping callable .
244,620
def verify_arguments ( self , args = None , kwargs = None ) : args = self . args if args is None else args kwargs = self . kwargs if kwargs is None else kwargs try : verify_arguments ( self . _target , self . _method_name , args , kwargs ) except VerifyingBuiltinDoubleArgumentError : if doubles . lifecycle . ignore_bui...
Ensures that the arguments specified match the signature of the real method .
244,621
def raise_failure_exception ( self , expect_or_allow = 'Allowed' ) : raise MockExpectationError ( "{} '{}' to be called {}on {!r} with {}, but was not. ({}:{})" . format ( expect_or_allow , self . _method_name , self . _call_counter . error_string ( ) , self . _target . obj , self . _expected_argument_string ( ) , self...
Raises a MockExpectationError with a useful message .
244,622
def _expected_argument_string ( self ) : if self . args is _any and self . kwargs is _any : return 'any args' elif self . _custom_matcher : return "custom matcher: '{}'" . format ( self . _custom_matcher . __name__ ) else : return build_argument_repr_string ( self . args , self . kwargs )
Generates a string describing what arguments the double expected .
244,623
def is_class_or_module ( self ) : if isinstance ( self . obj , ObjectDouble ) : return self . obj . is_class return isclass ( self . doubled_obj ) or ismodule ( self . doubled_obj )
Determines if the object is a class or a module
244,624
def _determine_doubled_obj ( self ) : if isinstance ( self . obj , ObjectDouble ) : return self . obj . _doubles_target else : return self . obj
Return the target object .
244,625
def _generate_attrs ( self ) : attrs = { } if ismodule ( self . doubled_obj ) : for name , func in getmembers ( self . doubled_obj , is_callable ) : attrs [ name ] = Attribute ( func , 'toplevel' , self . doubled_obj ) else : for attr in classify_class_attrs ( self . doubled_obj_type ) : attrs [ attr . name ] = attr re...
Get detailed info about target object .
244,626
def hijack_attr ( self , attr_name ) : if not self . _original_attr ( attr_name ) : setattr ( self . obj . __class__ , attr_name , _proxy_class_method_to_instance ( getattr ( self . obj . __class__ , attr_name , None ) , attr_name ) , )
Hijack an attribute on the target object .
244,627
def restore_attr ( self , attr_name ) : original_attr = self . _original_attr ( attr_name ) if self . _original_attr ( attr_name ) : setattr ( self . obj . __class__ , attr_name , original_attr )
Restore an attribute back onto the target object .
244,628
def _original_attr ( self , attr_name ) : try : return getattr ( getattr ( self . obj . __class__ , attr_name ) , '_doubles_target_method' , None ) except AttributeError : return None
Return the original attribute off of the proxy on the target object .
244,629
def get_callable_attr ( self , attr_name ) : if not hasattr ( self . doubled_obj , attr_name ) : return None func = getattr ( self . doubled_obj , attr_name ) if not is_callable ( func ) : return None attr = Attribute ( func , 'attribute' , self . doubled_obj if self . is_class_or_module ( ) else self . doubled_obj_typ...
Used to double methods added to an object after creation
244,630
def get_attr ( self , method_name ) : return self . attrs . get ( method_name ) or self . get_callable_attr ( method_name )
Get attribute from the target object
244,631
def add_allowance ( self , caller ) : allowance = Allowance ( self . _target , self . _method_name , caller ) self . _allowances . insert ( 0 , allowance ) return allowance
Adds a new allowance for the method .
244,632
def add_expectation ( self , caller ) : expectation = Expectation ( self . _target , self . _method_name , caller ) self . _expectations . insert ( 0 , expectation ) return expectation
Adds a new expectation for the method .
244,633
def _find_matching_allowance ( self , args , kwargs ) : for allowance in self . _allowances : if allowance . satisfy_exact_match ( args , kwargs ) : return allowance for allowance in self . _allowances : if allowance . satisfy_custom_matcher ( args , kwargs ) : return allowance for allowance in self . _allowances : if ...
Return a matching allowance .
244,634
def _find_matching_double ( self , args , kwargs ) : expectation = self . _find_matching_expectation ( args , kwargs ) if expectation : return expectation allowance = self . _find_matching_allowance ( args , kwargs ) if allowance : return allowance
Returns the first matching expectation or allowance .
244,635
def _find_matching_expectation ( self , args , kwargs ) : for expectation in self . _expectations : if expectation . satisfy_exact_match ( args , kwargs ) : return expectation for expectation in self . _expectations : if expectation . satisfy_custom_matcher ( args , kwargs ) : return expectation for expectation in self...
Return a matching expectation .
244,636
def _verify_method ( self ) : class_level = self . _target . is_class_or_module ( ) verify_method ( self . _target , self . _method_name , class_level = class_level )
Verify that a method may be doubled .
244,637
def verify_method ( target , method_name , class_level = False ) : attr = target . get_attr ( method_name ) if not attr : raise VerifyingDoubleError ( method_name , target . doubled_obj ) . no_matching_method ( ) if attr . kind == 'data' and not isbuiltin ( attr . object ) and not is_callable ( attr . object ) : raise ...
Verifies that the provided method exists on the target object .
244,638
def verify_arguments ( target , method_name , args , kwargs ) : if method_name == '_doubles__new__' : return _verify_arguments_of_doubles__new__ ( target , args , kwargs ) attr = target . get_attr ( method_name ) method = attr . object if attr . kind in ( 'data' , 'attribute' , 'toplevel' , 'class method' , 'static met...
Verifies that the provided arguments match the signature of the provided method .
244,639
def allow_constructor ( target ) : if not isinstance ( target , ClassDouble ) : raise ConstructorDoubleError ( 'Cannot allow_constructor of {} since it is not a ClassDouble.' . format ( target ) , ) return allow ( target ) . _doubles__new__
Set an allowance on a ClassDouble constructor
244,640
def patch ( target , value ) : patch = current_space ( ) . patch_for ( target ) patch . set_value ( value ) return patch
Replace the specified object
244,641
def get_path_components ( path ) : path_segments = path . split ( '.' ) module_path = '.' . join ( path_segments [ : - 1 ] ) if module_path == '' : raise VerifyingDoubleImportError ( 'Invalid import path: {}.' . format ( path ) ) class_name = path_segments [ - 1 ] return module_path , class_name
Extract the module name and class name out of the fully qualified path to the class .
244,642
def expect_constructor ( target ) : if not isinstance ( target , ClassDouble ) : raise ConstructorDoubleError ( 'Cannot allow_constructor of {} since it is not a ClassDouble.' . format ( target ) , ) return expect ( target ) . _doubles__new__
Set an expectation on a ClassDouble constructor
244,643
def write_table ( self ) : with self . _logger : self . _verify_property ( ) self . __write_chapter ( ) self . _write_table ( ) if self . is_write_null_line_after_table : self . write_null_line ( )
|write_table| with Markdown table format .
244,644
def write_table ( self ) : tags = _get_tags_module ( ) with self . _logger : self . _verify_property ( ) self . _preprocess ( ) if typepy . is_not_null_string ( self . table_name ) : self . _table_tag = tags . table ( id = sanitize_python_var_name ( self . table_name ) ) self . _table_tag += tags . caption ( MultiByteS...
|write_table| with HTML table format .
244,645
def dump ( self , output , close_after_write = True ) : try : output . write self . stream = output except AttributeError : self . stream = io . open ( output , "w" , encoding = "utf-8" ) try : self . write_table ( ) finally : if close_after_write : self . stream . close ( ) self . stream = sys . stdout
Write data to the output with tabular format .
244,646
def dumps ( self ) : old_stream = self . stream try : self . stream = six . StringIO ( ) self . write_table ( ) tabular_text = self . stream . getvalue ( ) finally : self . stream = old_stream return tabular_text
Get rendered tabular text from the table data .
244,647
def open ( self , file_path ) : if self . is_opened ( ) and self . workbook . file_path == file_path : self . _logger . logger . debug ( "workbook already opened: {}" . format ( self . workbook . file_path ) ) return self . close ( ) self . _open ( file_path )
Open an Excel workbook file .
244,648
def from_tabledata ( self , value , is_overwrite_table_name = True ) : super ( ExcelTableWriter , self ) . from_tabledata ( value ) if self . is_opened ( ) : self . make_worksheet ( self . table_name )
Set following attributes from |TableData|
244,649
def make_worksheet ( self , sheet_name = None ) : if sheet_name is None : sheet_name = self . table_name if not sheet_name : sheet_name = "" self . _stream = self . workbook . add_worksheet ( sheet_name ) self . _current_data_row = self . _first_data_row
Make a worksheet to the current workbook .
244,650
def dump ( self , output , close_after_write = True ) : self . open ( output ) try : self . make_worksheet ( self . table_name ) self . write_table ( ) finally : if close_after_write : self . close ( )
Write a worksheet to the current workbook .
244,651
def open ( self , file_path ) : from simplesqlite import SimpleSQLite if self . is_opened ( ) : if self . stream . database_path == abspath ( file_path ) : self . _logger . logger . debug ( "database already opened: {}" . format ( self . stream . database_path ) ) return self . close ( ) self . _stream = SimpleSQLite (...
Open a SQLite database file .
244,652
def set_style ( self , column , style ) : column_idx = None while len ( self . headers ) > len ( self . __style_list ) : self . __style_list . append ( None ) if isinstance ( column , six . integer_types ) : column_idx = column elif isinstance ( column , six . string_types ) : try : column_idx = self . headers . index ...
Set |Style| for a specific column .
244,653
def close ( self ) : if self . stream is None : return try : self . stream . isatty ( ) if self . stream . name in [ "<stdin>" , "<stdout>" , "<stderr>" ] : return except AttributeError : pass except ValueError : pass try : from _pytest . compat import CaptureIO from _pytest . capture import EncodedFile if isinstance (...
Close the current |stream| .
244,654
def _ids ( self ) : for pk in self . _pks : yield getattr ( self , pk ) for pk in self . _pks : try : yield str ( getattr ( self , pk ) ) except ValueError : pass
The list of primary keys to validate against .
244,655
def upgrade ( self , name , params = None ) : if ':' not in name : name = '{0}:{1}' . format ( self . type , name ) r = self . _h . _http_resource ( method = 'PUT' , resource = ( 'apps' , self . app . name , 'addons' , quote ( name ) ) , params = params , data = ' ' ) r . raise_for_status ( ) return self . app . addons...
Upgrades an addon to the given tier .
244,656
def new ( self , name = None , stack = 'cedar' , region = None ) : payload = { } if name : payload [ 'app[name]' ] = name if stack : payload [ 'app[stack]' ] = stack if region : payload [ 'app[region]' ] = region r = self . _h . _http_resource ( method = 'POST' , resource = ( 'apps' , ) , data = payload ) name = json ....
Creates a new app .
244,657
def collaborators ( self ) : return self . _h . _get_resources ( resource = ( 'apps' , self . name , 'collaborators' ) , obj = Collaborator , app = self )
The collaborators for this app .
244,658
def domains ( self ) : return self . _h . _get_resources ( resource = ( 'apps' , self . name , 'domains' ) , obj = Domain , app = self )
The domains for this app .
244,659
def releases ( self ) : return self . _h . _get_resources ( resource = ( 'apps' , self . name , 'releases' ) , obj = Release , app = self )
The releases for this app .
244,660
def processes ( self ) : return self . _h . _get_resources ( resource = ( 'apps' , self . name , 'ps' ) , obj = Process , app = self , map = ProcessListResource )
The proccesses for this app .
244,661
def config ( self ) : return self . _h . _get_resource ( resource = ( 'apps' , self . name , 'config_vars' ) , obj = ConfigVars , app = self )
The envs for this app .
244,662
def info ( self ) : return self . _h . _get_resource ( resource = ( 'apps' , self . name ) , obj = App , )
Returns current info for this app .
244,663
def rollback ( self , release ) : r = self . _h . _http_resource ( method = 'POST' , resource = ( 'apps' , self . name , 'releases' ) , data = { 'rollback' : release } ) return self . releases [ - 1 ]
Rolls back the release to the given version .
244,664
def rename ( self , name ) : r = self . _h . _http_resource ( method = 'PUT' , resource = ( 'apps' , self . name ) , data = { 'app[name]' : name } ) return r . ok
Renames app to given name .
244,665
def transfer ( self , user ) : r = self . _h . _http_resource ( method = 'PUT' , resource = ( 'apps' , self . name ) , data = { 'app[transfer_owner]' : user } ) return r . ok
Transfers app to given username s account .
244,666
def maintenance ( self , on = True ) : r = self . _h . _http_resource ( method = 'POST' , resource = ( 'apps' , self . name , 'server' , 'maintenance' ) , data = { 'maintenance_mode' : int ( on ) } ) return r . ok
Toggles maintenance mode .
244,667
def destroy ( self ) : r = self . _h . _http_resource ( method = 'DELETE' , resource = ( 'apps' , self . name ) ) return r . ok
Destoys the app . Do be careful .
244,668
def logs ( self , num = None , source = None , ps = None , tail = False ) : payload = { 'logplex' : 'true' } if num : payload [ 'num' ] = num if source : payload [ 'source' ] = source if ps : payload [ 'ps' ] = ps if tail : payload [ 'tail' ] = 1 r = self . _h . _http_resource ( method = 'GET' , resource = ( 'apps' , s...
Returns the requested log .
244,669
def delete ( self ) : r = self . _h . _http_resource ( method = 'DELETE' , resource = ( 'user' , 'keys' , self . id ) ) r . raise_for_status ( )
Deletes the key .
244,670
def restart ( self , all = False ) : if all : data = { 'type' : self . type } else : data = { 'ps' : self . process } r = self . _h . _http_resource ( method = 'POST' , resource = ( 'apps' , self . app . name , 'ps' , 'restart' ) , data = data ) r . raise_for_status ( )
Restarts the given process .
244,671
def scale ( self , quantity ) : r = self . _h . _http_resource ( method = 'POST' , resource = ( 'apps' , self . app . name , 'ps' , 'scale' ) , data = { 'type' : self . type , 'qty' : quantity } ) r . raise_for_status ( ) try : return self . app . processes [ self . type ] except KeyError : return ProcessListResource (...
Scales the given process to the given number of dynos .
244,672
def is_collection ( obj ) : col = getattr ( obj , '__getitem__' , False ) val = False if ( not col ) else True if isinstance ( obj , basestring ) : val = False return val
Tests if an object is a collection .
244,673
def to_python ( obj , in_dict , str_keys = None , date_keys = None , int_keys = None , object_map = None , bool_keys = None , dict_keys = None , ** kwargs ) : d = dict ( ) if str_keys : for in_key in str_keys : d [ in_key ] = in_dict . get ( in_key ) if date_keys : for in_key in date_keys : in_date = in_dict . get ( in...
Extends a given object for API Consumption .
244,674
def to_api ( in_dict , int_keys = None , date_keys = None , bool_keys = None ) : if int_keys : for in_key in int_keys : if ( in_key in in_dict ) and ( in_dict . get ( in_key , None ) is not None ) : in_dict [ in_key ] = int ( in_dict [ in_key ] ) if date_keys : for in_key in date_keys : if ( in_key in in_dict ) and ( i...
Extends a given object for API Production .
244,675
def clear ( self ) : r = self . _h . _http_resource ( method = 'DELETE' , resource = ( 'user' , 'keys' ) , ) return r . ok
Removes all SSH keys from a user s system .
244,676
def authenticate ( self , api_key ) : self . _api_key = api_key self . _session . auth = ( '' , self . _api_key ) return self . _verify_api_key ( )
Logs user into Heroku with given api_key .
244,677
def _get_resource ( self , resource , obj , params = None , ** kwargs ) : r = self . _http_resource ( 'GET' , resource , params = params ) item = self . _resource_deserialize ( r . content . decode ( "utf-8" ) ) return obj . new_from_dict ( item , h = self , ** kwargs )
Returns a mapped object from an HTTP resource .
244,678
def _get_resources ( self , resource , obj , params = None , map = None , ** kwargs ) : r = self . _http_resource ( 'GET' , resource , params = params ) d_items = self . _resource_deserialize ( r . content . decode ( "utf-8" ) ) items = [ obj . new_from_dict ( item , h = self , ** kwargs ) for item in d_items ] if map ...
Returns a list of mapped objects from an HTTP resource .
244,679
def from_key ( api_key , ** kwargs ) : h = Heroku ( ** kwargs ) h . authenticate ( api_key ) return h
Returns an authenticated Heroku instance via API Key .
244,680
def abbrev ( self , dev_suffix = "" ) : return '.' . join ( str ( el ) for el in self . release ) + ( dev_suffix if self . commit_count > 0 or self . dirty else "" )
Abbreviated string representation optionally declaring whether it is a development version .
244,681
def verify ( self , string_version = None ) : if string_version and string_version != str ( self ) : raise Exception ( "Supplied string version does not match current version." ) if self . dirty : raise Exception ( "Current working directory is dirty." ) if self . release != self . expected_release : raise Exception ( ...
Check that the version information is consistent with the VCS before doing a release . If supplied with a string version this is also checked against the current version . Should be called from setup . py with the declared package version before releasing to PyPI .
244,682
def _check_time_fn ( self , time_instance = False ) : if time_instance and not isinstance ( self . time_fn , param . Time ) : raise AssertionError ( "%s requires a Time object" % self . __class__ . __name__ ) if self . time_dependent : global_timefn = self . time_fn is param . Dynamic . time_fn if global_timefn and not...
If time_fn is the global time function supplied by param . Dynamic . time_fn make sure Dynamic parameters are using this time function to control their behaviour .
244,683
def _rational ( self , val ) : I32 = 4294967296 if isinstance ( val , int ) : numer , denom = val , 1 elif isinstance ( val , fractions . Fraction ) : numer , denom = val . numerator , val . denominator elif hasattr ( val , 'numer' ) : ( numer , denom ) = ( int ( val . numer ( ) ) , int ( val . denom ( ) ) ) else : par...
Convert the given value to a rational if necessary .
244,684
def _initialize_random_state ( self , seed = None , shared = True , name = None ) : if seed is None : seed = random . Random ( ) . randint ( 0 , 1000000 ) suffix = '' else : suffix = str ( seed ) if self . time_dependent or not shared : self . random_generator = type ( self . random_generator ) ( seed ) if not shared :...
Initialization method to be called in the constructor of subclasses to initialize the random state correctly .
244,685
def _verify_constrained_hash ( self ) : changed_params = dict ( self . param . get_param_values ( onlychanged = True ) ) if self . time_dependent and ( 'name' not in changed_params ) : self . param . warning ( "Default object name used to set the seed: " "random values conditional on object instantiation order." )
Warn if the object name is not explicitly set .
244,686
def get_setup_version ( reponame ) : from param . version import Version return Version . setup_version ( os . path . dirname ( __file__ ) , reponame , archive_commit = "$Format:%h$" )
Use autover to get up to date version .
244,687
def get_param_info ( self , obj , include_super = True ) : params = dict ( obj . param . objects ( 'existing' ) ) if isinstance ( obj , type ) : changed = [ ] val_dict = dict ( ( k , p . default ) for ( k , p ) in params . items ( ) ) self_class = obj else : changed = [ name for ( name , _ ) in obj . param . get_param_...
Get the parameter dictionary the list of modifed parameters and the dictionary or parameter values . If include_super is True parameters are also collected from the super classes .
244,688
def _build_table ( self , info , order , max_col_len = 40 , only_changed = False ) : info_dict , bounds_dict = { } , { } ( params , val_dict , changed ) = info col_widths = dict ( ( k , 0 ) for k in order ) for name , p in params . items ( ) : if only_changed and not ( name in changed ) : continue constant = 'C' if p ....
Collect the information about parameters needed to build a properly formatted table and then tabulate it .
244,689
def _tabulate ( self , info_dict , col_widths , changed , order , bounds_dict ) : contents , tail = [ ] , [ ] column_set = set ( k for row in info_dict . values ( ) for k in row ) columns = [ col for col in order if col in column_set ] title_row = [ ] for i , col in enumerate ( columns ) : width = col_widths [ col ] + ...
Returns the supplied information as a table suitable for printing or paging .
244,690
def is_ordered_dict ( d ) : py3_ordered_dicts = ( sys . version_info . major == 3 ) and ( sys . version_info . minor >= 6 ) vanilla_odicts = ( sys . version_info . major > 3 ) or py3_ordered_dicts return isinstance ( d , ( OrderedDict ) ) or ( vanilla_odicts and isinstance ( d , dict ) )
Predicate checking for ordered dictionaries . OrderedDict is always ordered and vanilla Python dictionaries are ordered for Python 3 . 6 +
244,691
def named_objs ( objlist , namesdict = None ) : objs = OrderedDict ( ) if namesdict is not None : objtoname = { hashable ( v ) : k for k , v in namesdict . items ( ) } for obj in objlist : if namesdict is not None and hashable ( obj ) in objtoname : k = objtoname [ hashable ( obj ) ] elif hasattr ( obj , "name" ) : k =...
Given a list of objects returns a dictionary mapping from string name for the object to the object itself . Accepts an optional name obj dictionary which will override any other name if that item is present in the dictionary .
244,692
def guess_param_types ( ** kwargs ) : params = { } for k , v in kwargs . items ( ) : kws = dict ( default = v , constant = True ) if isinstance ( v , Parameter ) : params [ k ] = v elif isinstance ( v , dt_types ) : params [ k ] = Date ( ** kws ) elif isinstance ( v , bool ) : params [ k ] = Boolean ( ** kws ) elif isi...
Given a set of keyword literals promote to the appropriate parameter type based on some simple heuristics .
244,693
def guess_bounds ( params , ** overrides ) : guessed = { } for name , p in params . items ( ) : new_param = copy . copy ( p ) if isinstance ( p , ( Integer , Number ) ) : if name in overrides : minv , maxv = overrides [ name ] else : minv , maxv , _ = _get_min_max_value ( None , None , value = p . default ) new_param ....
Given a dictionary of Parameter instances return a corresponding set of copies with the bounds appropriately set .
244,694
def _initialize_generator ( self , gen , obj = None ) : if hasattr ( obj , "_Dynamic_time_fn" ) : gen . _Dynamic_time_fn = obj . _Dynamic_time_fn gen . _Dynamic_last = None gen . _Dynamic_time = - 1 gen . _saved_Dynamic_last = [ ] gen . _saved_Dynamic_time = [ ]
Add last time and last value attributes to the generator .
244,695
def _produce_value ( self , gen , force = False ) : if hasattr ( gen , "_Dynamic_time_fn" ) : time_fn = gen . _Dynamic_time_fn else : time_fn = self . time_fn if ( time_fn is None ) or ( not self . time_dependent ) : value = produce_value ( gen ) gen . _Dynamic_last = value else : time = time_fn ( ) if force or time !=...
Return a value from gen .
244,696
def _inspect ( self , obj , objtype = None ) : gen = super ( Dynamic , self ) . __get__ ( obj , objtype ) if hasattr ( gen , '_Dynamic_last' ) : return gen . _Dynamic_last else : return gen
Return the last generated value for this parameter .
244,697
def _force ( self , obj , objtype = None ) : gen = super ( Dynamic , self ) . __get__ ( obj , objtype ) if hasattr ( gen , '_Dynamic_last' ) : return self . _produce_value ( gen , force = True ) else : return gen
Force a new value to be generated and return it .
244,698
def set_in_bounds ( self , obj , val ) : if not callable ( val ) : bounded_val = self . crop_to_bounds ( val ) else : bounded_val = val super ( Number , self ) . __set__ ( obj , bounded_val )
Set to the given value but cropped to be within the legal bounds . All objects are accepted and no exceptions will be raised . See crop_to_bounds for details on how cropping is done .
244,699
def crop_to_bounds ( self , val ) : if _is_number ( val ) : if self . bounds is None : return val vmin , vmax = self . bounds if vmin is not None : if val < vmin : return vmin if vmax is not None : if val > vmax : return vmax elif self . allow_None and val is None : return val else : return self . default return val
Return the given value cropped to be within the hard bounds for this parameter .