idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
19,200
def get_keybindings ( self , mode ) : globalmaps , modemaps = { } , { } bindings = self . _bindings if mode in bindings . sections : for key in bindings [ mode ] . scalars : value = bindings [ mode ] [ key ] if isinstance ( value , list ) : value = ',' . join ( value ) modemaps [ key ] = value for key in bindings . scalars : if key not in modemaps : value = bindings [ key ] if isinstance ( value , list ) : value = ',' . join ( value ) if value and value != '' : globalmaps [ key ] = value for k , v in list ( modemaps . items ( ) ) : if not v : del modemaps [ k ] return globalmaps , modemaps
look up keybindings from MODE - maps sections
19,201
def get_keybinding ( self , mode , key ) : cmdline = None bindings = self . _bindings if key in bindings . scalars : cmdline = bindings [ key ] if mode in bindings . sections : if key in bindings [ mode ] . scalars : value = bindings [ mode ] [ key ] if value : cmdline = value else : cmdline = None if isinstance ( cmdline , list ) : cmdline = ',' . join ( cmdline ) return cmdline
look up keybinding from MODE - maps sections
19,202
def computed ( self ) : return ( self . _computed and self . solver . computed and ( self . kernel is None or not self . kernel . dirty ) )
Has the processes been computed since the last update of the kernel?
19,203
def parse_samples ( self , t ) : t = np . atleast_1d ( t ) if len ( t . shape ) == 1 : t = np . atleast_2d ( t ) . T if len ( t . shape ) != 2 or ( self . kernel is not None and t . shape [ 1 ] != self . kernel . ndim ) : raise ValueError ( "Dimension mismatch" ) return t
Parse a list of samples to make sure that it has the correct dimensions .
19,204
def compute ( self , x , yerr = 0.0 , ** kwargs ) : self . _x = self . parse_samples ( x ) self . _x = np . ascontiguousarray ( self . _x , dtype = np . float64 ) try : self . _yerr2 = float ( yerr ) ** 2 * np . ones ( len ( x ) ) except TypeError : self . _yerr2 = self . _check_dimensions ( yerr ) ** 2 self . _yerr2 = np . ascontiguousarray ( self . _yerr2 , dtype = np . float64 ) self . solver = self . solver_type ( self . kernel , ** ( self . solver_kwargs ) ) yerr = np . sqrt ( self . _yerr2 + np . exp ( self . _call_white_noise ( self . _x ) ) ) self . solver . compute ( self . _x , yerr , ** kwargs ) self . _const = - 0.5 * ( len ( self . _x ) * np . log ( 2 * np . pi ) + self . solver . log_determinant ) self . computed = True self . _alpha = None
Pre - compute the covariance matrix and factorize it for a set of times and uncertainties .
19,205
def recompute ( self , quiet = False , ** kwargs ) : if not self . computed : if not ( hasattr ( self , "_x" ) and hasattr ( self , "_yerr2" ) ) : raise RuntimeError ( "You need to compute the model first" ) try : self . compute ( self . _x , np . sqrt ( self . _yerr2 ) , ** kwargs ) except ( ValueError , LinAlgError ) : if quiet : return False raise return True
Re - compute a previously computed model . You might want to do this if the kernel parameters change and the kernel is labeled as dirty .
19,206
def sample ( self , t = None , size = 1 ) : if t is None : self . recompute ( ) n , _ = self . _x . shape results = self . solver . apply_sqrt ( np . random . randn ( size , n ) ) results += self . _call_mean ( self . _x ) return results [ 0 ] if size == 1 else results x = self . parse_samples ( t ) cov = self . get_matrix ( x ) cov [ np . diag_indices_from ( cov ) ] += TINY return multivariate_gaussian_samples ( cov , size , mean = self . _call_mean ( x ) )
Draw samples from the prior distribution .
19,207
def get_matrix ( self , x1 , x2 = None ) : x1 = self . parse_samples ( x1 ) if x2 is None : return self . kernel . get_value ( x1 ) x2 = self . parse_samples ( x2 ) return self . kernel . get_value ( x1 , x2 )
Get the covariance matrix at a given set or two of independent coordinates .
19,208
def has_library ( compiler , libname ) : with tempfile . NamedTemporaryFile ( "w" , suffix = ".cpp" ) as srcfile : srcfile . write ( "int main (int argc, char **argv) { return 0; }" ) srcfile . flush ( ) outfn = srcfile . name + ".so" try : compiler . link_executable ( [ srcfile . name ] , outfn , libraries = [ libname ] , ) except setuptools . distutils . errors . LinkError : return False if not os . path . exists ( outfn ) : return False os . remove ( outfn ) return True
Return a boolean indicating whether a library is found .
19,209
def compute ( self , x , yerr ) : K = self . kernel . get_value ( x ) K [ np . diag_indices_from ( K ) ] += yerr ** 2 self . _factor = ( cholesky ( K , overwrite_a = True , lower = False ) , False ) self . log_determinant = 2 * np . sum ( np . log ( np . diag ( self . _factor [ 0 ] ) ) ) self . computed = True
Compute and factorize the covariance matrix .
19,210
def apply_inverse ( self , y , in_place = False ) : r return cho_solve ( self . _factor , y , overwrite_b = in_place )
r Apply the inverse of the covariance matrix to the input by solving
19,211
def get_inverse ( self ) : return self . apply_inverse ( np . eye ( len ( self . _factor [ 0 ] ) ) , in_place = True )
Get the dense inverse covariance matrix . This is used for computing gradients but it is not recommended in general .
19,212
def get_parameter_dict ( self , include_frozen = False ) : return OrderedDict ( zip ( self . get_parameter_names ( include_frozen = include_frozen ) , self . get_parameter_vector ( include_frozen = include_frozen ) , ) )
Get an ordered dictionary of the parameters
19,213
def get_parameter_names ( self , include_frozen = False ) : if include_frozen : return self . parameter_names return tuple ( p for p , f in zip ( self . parameter_names , self . unfrozen_mask ) if f )
Get a list of the parameter names
19,214
def get_parameter_bounds ( self , include_frozen = False ) : if include_frozen : return self . parameter_bounds return list ( p for p , f in zip ( self . parameter_bounds , self . unfrozen_mask ) if f )
Get a list of the parameter bounds
19,215
def get_parameter_vector ( self , include_frozen = False ) : if include_frozen : return self . parameter_vector return self . parameter_vector [ self . unfrozen_mask ]
Get an array of the parameter values in the correct order
19,216
def set_parameter_vector ( self , vector , include_frozen = False ) : v = self . parameter_vector if include_frozen : v [ : ] = vector else : v [ self . unfrozen_mask ] = vector self . parameter_vector = v self . dirty = True
Set the parameter values to the given vector
19,217
def freeze_parameter ( self , name ) : i = self . get_parameter_names ( include_frozen = True ) . index ( name ) self . unfrozen_mask [ i ] = False
Freeze a parameter by name
19,218
def thaw_parameter ( self , name ) : i = self . get_parameter_names ( include_frozen = True ) . index ( name ) self . unfrozen_mask [ i ] = True
Thaw a parameter by name
19,219
def get_parameter ( self , name ) : i = self . get_parameter_names ( include_frozen = True ) . index ( name ) return self . get_parameter_vector ( include_frozen = True ) [ i ]
Get a parameter value by name
19,220
def set_parameter ( self , name , value ) : i = self . get_parameter_names ( include_frozen = True ) . index ( name ) v = self . get_parameter_vector ( include_frozen = True ) v [ i ] = value self . set_parameter_vector ( v , include_frozen = True )
Set a parameter value by name
19,221
def log_prior ( self ) : for p , b in zip ( self . parameter_vector , self . parameter_bounds ) : if b [ 0 ] is not None and p < b [ 0 ] : return - np . inf if b [ 1 ] is not None and p > b [ 1 ] : return - np . inf return 0.0
Compute the log prior probability of the current parameters
19,222
def multivariate_gaussian_samples ( matrix , N , mean = None ) : if mean is None : mean = np . zeros ( len ( matrix ) ) samples = np . random . multivariate_normal ( mean , matrix , N ) if N == 1 : return samples [ 0 ] return samples
Generate samples from a multidimensional Gaussian with a given covariance .
19,223
def nd_sort_samples ( samples ) : assert len ( samples . shape ) == 2 tree = cKDTree ( samples ) d , i = tree . query ( samples [ 0 ] , k = len ( samples ) ) return i
Sort an N - dimensional list of samples using a KDTree .
19,224
def lookup_function ( val ) : "Look-up and return a pretty-printer that can print va." type = val . type if type . code == gdb . TYPE_CODE_REF : type = type . target ( ) type = type . unqualified ( ) . strip_typedefs ( ) typename = type . tag if typename == None : return None for function in pretty_printers_dict : if function . search ( typename ) : return pretty_printers_dict [ function ] ( val ) return None
Look - up and return a pretty - printer that can print va .
19,225
def serve_static ( request , path , insecure = False , ** kwargs ) : if not django_settings . DEBUG and not insecure : raise ImproperlyConfigured ( "The staticfiles view can only be used in " "debug mode or if the --insecure " "option of 'runserver' is used" ) if not settings . PIPELINE_ENABLED and settings . PIPELINE_COLLECTOR_ENABLED : default_collector . collect ( request , files = [ path ] ) return serve ( request , path , document_root = django_settings . STATIC_ROOT , ** kwargs )
Collect and serve static files .
19,226
def compress_js ( self , paths , templates = None , ** kwargs ) : js = self . concatenate ( paths ) if templates : js = js + self . compile_templates ( templates ) if not settings . DISABLE_WRAPPER : js = settings . JS_WRAPPER % js compressor = self . js_compressor if compressor : js = getattr ( compressor ( verbose = self . verbose ) , 'compress_js' ) ( js ) return js
Concatenate and compress JS files
19,227
def compress_css ( self , paths , output_filename , variant = None , ** kwargs ) : css = self . concatenate_and_rewrite ( paths , output_filename , variant ) compressor = self . css_compressor if compressor : css = getattr ( compressor ( verbose = self . verbose ) , 'compress_css' ) ( css ) if not variant : return css elif variant == "datauri" : return self . with_data_uri ( css ) else : raise CompressorError ( "\"%s\" is not a valid variant" % variant )
Concatenate and compress CSS files
19,228
def template_name ( self , path , base ) : if not base : path = os . path . basename ( path ) if path == base : base = os . path . dirname ( path ) name = re . sub ( r"^%s[\/\\]?(.*)%s$" % ( re . escape ( base ) , re . escape ( settings . TEMPLATE_EXT ) ) , r"\1" , path ) return re . sub ( r"[\/\\]" , settings . TEMPLATE_SEPARATOR , name )
Find out the name of a JS template
19,229
def concatenate_and_rewrite ( self , paths , output_filename , variant = None ) : stylesheets = [ ] for path in paths : def reconstruct ( match ) : quote = match . group ( 1 ) or '' asset_path = match . group ( 2 ) if NON_REWRITABLE_URL . match ( asset_path ) : return "url(%s%s%s)" % ( quote , asset_path , quote ) asset_url = self . construct_asset_path ( asset_path , path , output_filename , variant ) return "url(%s)" % asset_url content = self . read_text ( path ) content = re . sub ( URL_DETECTOR , reconstruct , content ) stylesheets . append ( content ) return '\n' . join ( stylesheets )
Concatenate together files and rewrite urls
19,230
def construct_asset_path ( self , asset_path , css_path , output_filename , variant = None ) : public_path = self . absolute_path ( asset_path , os . path . dirname ( css_path ) . replace ( '\\' , '/' ) ) if self . embeddable ( public_path , variant ) : return "__EMBED__%s" % public_path if not posixpath . isabs ( asset_path ) : asset_path = self . relative_path ( public_path , output_filename ) return asset_path
Return a rewritten asset URL for a stylesheet
19,231
def embeddable ( self , path , variant ) : name , ext = os . path . splitext ( path ) font = ext in FONT_EXTS if not variant : return False if not ( re . search ( settings . EMBED_PATH , path . replace ( '\\' , '/' ) ) and self . storage . exists ( path ) ) : return False if ext not in EMBED_EXTS : return False if not ( font or len ( self . encoded_content ( path ) ) < settings . EMBED_MAX_IMAGE_SIZE ) : return False return True
Is the asset embeddable ?
19,232
def encoded_content ( self , path ) : if path in self . __class__ . asset_contents : return self . __class__ . asset_contents [ path ] data = self . read_bytes ( path ) self . __class__ . asset_contents [ path ] = force_text ( base64 . b64encode ( data ) ) return self . __class__ . asset_contents [ path ]
Return the base64 encoded contents
19,233
def mime_type ( self , path ) : name , ext = os . path . splitext ( path ) return MIME_TYPES [ ext ]
Get mime - type from filename
19,234
def absolute_path ( self , path , start ) : if posixpath . isabs ( path ) : path = posixpath . join ( staticfiles_storage . location , path ) else : path = posixpath . join ( start , path ) return posixpath . normpath ( path )
Return the absolute public path for an asset given the path of the stylesheet that contains it .
19,235
def relative_path ( self , absolute_path , output_filename ) : absolute_path = posixpath . join ( settings . PIPELINE_ROOT , absolute_path ) output_path = posixpath . join ( settings . PIPELINE_ROOT , posixpath . dirname ( output_filename ) ) return relpath ( absolute_path , output_path )
Rewrite paths relative to the output stylesheet path
19,236
def read_bytes ( self , path ) : file = staticfiles_storage . open ( path ) content = file . read ( ) file . close ( ) return content
Read file content in binary mode
19,237
def set_std_streams_blocking ( ) : if not fcntl : return for f in ( sys . __stdout__ , sys . __stderr__ ) : fileno = f . fileno ( ) flags = fcntl . fcntl ( fileno , fcntl . F_GETFL ) fcntl . fcntl ( fileno , fcntl . F_SETFL , flags & ~ os . O_NONBLOCK )
Set stdout and stderr to be blocking .
19,238
def execute_command ( self , command , cwd = None , stdout_captured = None ) : argument_list = [ ] for flattening_arg in command : if isinstance ( flattening_arg , string_types ) : argument_list . append ( flattening_arg ) else : argument_list . extend ( flattening_arg ) argument_list = list ( filter ( None , argument_list ) ) stdout = None try : temp_file_container = cwd or os . path . dirname ( stdout_captured or "" ) or os . getcwd ( ) with NamedTemporaryFile ( delete = False , dir = temp_file_container ) as stdout : compiling = subprocess . Popen ( argument_list , cwd = cwd , stdout = stdout , stderr = subprocess . PIPE ) _ , stderr = compiling . communicate ( ) set_std_streams_blocking ( ) if compiling . returncode != 0 : stdout_captured = None raise CompilerError ( "{0!r} exit code {1}\n{2}" . format ( argument_list , compiling . returncode , stderr ) , command = argument_list , error_output = stderr ) if self . verbose : with open ( stdout . name ) as out : print ( out . read ( ) ) print ( stderr ) except OSError as e : stdout_captured = None raise CompilerError ( e , command = argument_list , error_output = text_type ( e ) ) finally : if stdout : if stdout_captured : shutil . move ( stdout . name , os . path . join ( cwd or os . curdir , stdout_captured ) ) else : os . remove ( stdout . name )
Execute a command at cwd saving its normal output at stdout_captured . Errors defined as nonzero return code or a failure to start execution will raise a CompilerError exception with a description of the cause . They do not write output .
19,239
def _get_css_files ( cls , extra_files ) : packager = Packager ( ) css_packages = getattr ( cls , 'css_packages' , { } ) return dict ( ( media_target , cls . _get_media_files ( packager = packager , media_packages = media_packages , media_type = 'css' , extra_files = extra_files . get ( media_target , [ ] ) ) ) for media_target , media_packages in six . iteritems ( css_packages ) )
Return all CSS files from the Media class .
19,240
def _get_js_files ( cls , extra_files ) : return cls . _get_media_files ( packager = Packager ( ) , media_packages = getattr ( cls , 'js_packages' , { } ) , media_type = 'js' , extra_files = extra_files )
Return all JavaScript files from the Media class .
19,241
def _get_media_files ( cls , packager , media_packages , media_type , extra_files ) : source_files = list ( extra_files ) if ( not settings . PIPELINE_ENABLED and settings . PIPELINE_COLLECTOR_ENABLED ) : default_collector . collect ( ) for media_package in media_packages : package = packager . package_for ( media_type , media_package ) if settings . PIPELINE_ENABLED : source_files . append ( staticfiles_storage . url ( package . output_filename ) ) else : source_files += packager . compile ( package . paths ) return source_files
Return source or output media files for a list of packages .
19,242
def render_compressed ( self , package , package_name , package_type ) : if settings . PIPELINE_ENABLED : return self . render_compressed_output ( package , package_name , package_type ) else : return self . render_compressed_sources ( package , package_name , package_type )
Render HTML for the package .
19,243
def render_compressed_output ( self , package , package_name , package_type ) : method = getattr ( self , 'render_{0}' . format ( package_type ) ) return method ( package , package . output_filename )
Render HTML for using the package s output file .
19,244
def render_compressed_sources ( self , package , package_name , package_type ) : if settings . PIPELINE_COLLECTOR_ENABLED : default_collector . collect ( self . request ) packager = Packager ( ) method = getattr ( self , 'render_individual_{0}' . format ( package_type ) ) try : paths = packager . compile ( package . paths ) except CompilerError as e : if settings . SHOW_ERRORS_INLINE : method = getattr ( self , 'render_error_{0}' . format ( package_type ) ) return method ( package_name , e ) else : raise templates = packager . pack_templates ( package ) return method ( package , paths , templates = templates )
Render HTML for using the package s list of source files .
19,245
def find ( self , path , all = False ) : matches = [ ] for elem in chain ( settings . STYLESHEETS . values ( ) , settings . JAVASCRIPT . values ( ) ) : if normpath ( elem [ 'output_filename' ] ) == normpath ( path ) : match = safe_join ( settings . PIPELINE_ROOT , path ) if not all : return match matches . append ( match ) return matches
Looks for files in PIPELINE . STYLESHEETS and PIPELINE . JAVASCRIPT
19,246
def find ( self , path , all = False ) : try : start , _ , extn = path . rsplit ( '.' , 2 ) except ValueError : return [ ] path = '.' . join ( ( start , extn ) ) return find ( path , all = all ) or [ ]
Work out the uncached name of the file and look that up instead
19,247
def get ( cls , attachment_public_uuid , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) endpoint_url = cls . _ENDPOINT_URL_READ . format ( attachment_public_uuid ) response_raw = api_client . get ( endpoint_url , { } , custom_headers ) return BunqResponseAttachmentPublic . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_GET ) )
Get a specific attachment s metadata through its UUID . The Content - Type header of the response will describe the MIME type of the attachment file .
19,248
def get ( cls , tab_uuid , tab_attachment_tab_id , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) endpoint_url = cls . _ENDPOINT_URL_READ . format ( tab_uuid , tab_attachment_tab_id ) response_raw = api_client . get ( endpoint_url , { } , custom_headers ) return BunqResponseTabAttachmentTab . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_GET ) )
Get a specific attachment . The header of the response contains the content - type of the attachment .
19,249
def create ( cls , amount , counterparty_alias , description , monetary_account_id = None , attachment = None , merchant_reference = None , allow_bunqto = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_AMOUNT : amount , cls . FIELD_COUNTERPARTY_ALIAS : counterparty_alias , cls . FIELD_DESCRIPTION : description , cls . FIELD_ATTACHMENT : attachment , cls . FIELD_MERCHANT_REFERENCE : merchant_reference , cls . FIELD_ALLOW_BUNQTO : allow_bunqto } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Create a new Payment .
19,250
def create ( cls , second_line , name_on_card , alias = None , type_ = None , pin_code_assignment = None , monetary_account_id_fallback = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_SECOND_LINE : second_line , cls . FIELD_NAME_ON_CARD : name_on_card , cls . FIELD_ALIAS : alias , cls . FIELD_TYPE : type_ , cls . FIELD_PIN_CODE_ASSIGNMENT : pin_code_assignment , cls . FIELD_MONETARY_ACCOUNT_ID_FALLBACK : monetary_account_id_fallback } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) request_bytes = security . encrypt ( cls . _get_api_context ( ) , request_bytes , custom_headers ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseCardDebit . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_POST ) )
Create a new debit card request .
19,251
def create ( cls , card_id , type_ = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_TYPE : type_ } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) request_bytes = security . encrypt ( cls . _get_api_context ( ) , request_bytes , custom_headers ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , card_id ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Generate a new CVC2 code for a card .
19,252
def create ( cls , card_id , name_on_card = None , pin_code = None , second_line = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_NAME_ON_CARD : name_on_card , cls . FIELD_PIN_CODE : pin_code , cls . FIELD_SECOND_LINE : second_line } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) request_bytes = security . encrypt ( cls . _get_api_context ( ) , request_bytes , custom_headers ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , card_id ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Request a card replacement .
19,253
def update ( cls , card_id , pin_code = None , activation_code = None , status = None , card_limit = None , card_limit_atm = None , limit = None , mag_stripe_permission = None , country_permission = None , pin_code_assignment = None , primary_account_numbers_virtual = None , monetary_account_id_fallback = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_map = { cls . FIELD_PIN_CODE : pin_code , cls . FIELD_ACTIVATION_CODE : activation_code , cls . FIELD_STATUS : status , cls . FIELD_CARD_LIMIT : card_limit , cls . FIELD_CARD_LIMIT_ATM : card_limit_atm , cls . FIELD_LIMIT : limit , cls . FIELD_MAG_STRIPE_PERMISSION : mag_stripe_permission , cls . FIELD_COUNTRY_PERMISSION : country_permission , cls . FIELD_PIN_CODE_ASSIGNMENT : pin_code_assignment , cls . FIELD_PRIMARY_ACCOUNT_NUMBERS_VIRTUAL : primary_account_numbers_virtual , cls . FIELD_MONETARY_ACCOUNT_ID_FALLBACK : monetary_account_id_fallback } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) request_bytes = request_map_string . encode ( ) request_bytes = security . encrypt ( cls . _get_api_context ( ) , request_bytes , custom_headers ) endpoint_url = cls . _ENDPOINT_URL_UPDATE . format ( cls . _determine_user_id ( ) , card_id ) response_raw = api_client . put ( endpoint_url , request_bytes , custom_headers ) return BunqResponseCard . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_PUT ) )
Update the card details . Allow to change pin code status limits country permissions and the monetary account connected to the card . When the card has been received it can be also activated through this endpoint .
19,254
def get ( cls , card_id , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) endpoint_url = cls . _ENDPOINT_URL_READ . format ( cls . _determine_user_id ( ) , card_id ) response_raw = api_client . get ( endpoint_url , { } , custom_headers ) return BunqResponseCard . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_GET ) )
Return the details of a specific card .
19,255
def create ( cls , name , status , avatar_uuid , monetary_account_id = None , location = None , notification_filters = None , tab_text_waiting_screen = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_NAME : name , cls . FIELD_STATUS : status , cls . FIELD_AVATAR_UUID : avatar_uuid , cls . FIELD_LOCATION : location , cls . FIELD_NOTIFICATION_FILTERS : notification_filters , cls . FIELD_TAB_TEXT_WAITING_SCREEN : tab_text_waiting_screen } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Create a new CashRegister . Only an UserCompany can create a CashRegisters . They need to be created with status PENDING_APPROVAL an bunq admin has to approve your CashRegister before you can use it . In the sandbox testing environment an CashRegister will be automatically approved immediately after creation .
19,256
def create ( cls , cash_register_id , description , status , amount_total , monetary_account_id = None , allow_amount_higher = None , allow_amount_lower = None , want_tip = None , minimum_age = None , require_address = None , redirect_url = None , visibility = None , expiration = None , tab_attachment = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_DESCRIPTION : description , cls . FIELD_STATUS : status , cls . FIELD_AMOUNT_TOTAL : amount_total , cls . FIELD_ALLOW_AMOUNT_HIGHER : allow_amount_higher , cls . FIELD_ALLOW_AMOUNT_LOWER : allow_amount_lower , cls . FIELD_WANT_TIP : want_tip , cls . FIELD_MINIMUM_AGE : minimum_age , cls . FIELD_REQUIRE_ADDRESS : require_address , cls . FIELD_REDIRECT_URL : redirect_url , cls . FIELD_VISIBILITY : visibility , cls . FIELD_EXPIRATION : expiration , cls . FIELD_TAB_ATTACHMENT : tab_attachment } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) , cash_register_id ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseStr . cast_from_bunq_response ( cls . _process_for_uuid ( response_raw ) )
Create a TabUsageMultiple . On creation the status must be set to OPEN
19,257
def get ( cls , device_server_id , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) endpoint_url = cls . _ENDPOINT_URL_READ . format ( device_server_id ) response_raw = api_client . get ( endpoint_url , { } , custom_headers ) return BunqResponseDeviceServer . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_GET ) )
Get one of your DeviceServers .
19,258
def get ( cls , device_id , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) endpoint_url = cls . _ENDPOINT_URL_READ . format ( device_id ) response_raw = api_client . get ( endpoint_url , { } , custom_headers ) return BunqResponseDevice . cast_from_bunq_response ( cls . _from_json ( response_raw ) )
Get a single Device . A Device is either a DevicePhone or a DeviceServer .
19,259
def create ( cls , entries , number_of_required_accepts , monetary_account_id = None , status = None , previous_updated_timestamp = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_STATUS : status , cls . FIELD_ENTRIES : entries , cls . FIELD_PREVIOUS_UPDATED_TIMESTAMP : previous_updated_timestamp , cls . FIELD_NUMBER_OF_REQUIRED_ACCEPTS : number_of_required_accepts } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Create a new DraftPayment .
19,260
def update ( cls , draft_share_invite_api_key_id , status = None , sub_status = None , expiration = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_map = { cls . FIELD_STATUS : status , cls . FIELD_SUB_STATUS : sub_status , cls . FIELD_EXPIRATION : expiration } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_UPDATE . format ( cls . _determine_user_id ( ) , draft_share_invite_api_key_id ) response_raw = api_client . put ( endpoint_url , request_bytes , custom_headers ) return BunqResponseDraftShareInviteApiKey . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_PUT ) )
Update a draft share invite . When sending status CANCELLED it is possible to cancel the draft share invite .
19,261
def create ( cls , request_inquiries , total_amount_inquired , monetary_account_id = None , status = None , event_id = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_REQUEST_INQUIRIES : request_inquiries , cls . FIELD_STATUS : status , cls . FIELD_TOTAL_AMOUNT_INQUIRED : total_amount_inquired , cls . FIELD_EVENT_ID : event_id } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Create a request batch by sending an array of single request objects that will become part of the batch .
19,262
def create ( cls , amount_inquired , counterparty_alias , description , allow_bunqme , monetary_account_id = None , attachment = None , merchant_reference = None , status = None , minimum_age = None , require_address = None , want_tip = None , allow_amount_lower = None , allow_amount_higher = None , redirect_url = None , event_id = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_AMOUNT_INQUIRED : amount_inquired , cls . FIELD_COUNTERPARTY_ALIAS : counterparty_alias , cls . FIELD_DESCRIPTION : description , cls . FIELD_ATTACHMENT : attachment , cls . FIELD_MERCHANT_REFERENCE : merchant_reference , cls . FIELD_STATUS : status , cls . FIELD_MINIMUM_AGE : minimum_age , cls . FIELD_REQUIRE_ADDRESS : require_address , cls . FIELD_WANT_TIP : want_tip , cls . FIELD_ALLOW_AMOUNT_LOWER : allow_amount_lower , cls . FIELD_ALLOW_AMOUNT_HIGHER : allow_amount_higher , cls . FIELD_ALLOW_BUNQME : allow_bunqme , cls . FIELD_REDIRECT_URL : redirect_url , cls . FIELD_EVENT_ID : event_id } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Create a new payment request .
19,263
def update ( cls , request_inquiry_id , monetary_account_id = None , status = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_map = { cls . FIELD_STATUS : status } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_UPDATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) , request_inquiry_id ) response_raw = api_client . put ( endpoint_url , request_bytes , custom_headers ) return BunqResponseRequestInquiry . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_PUT ) )
Revoke a request for payment by updating the status to REVOKED .
19,264
def update ( cls , request_response_id , monetary_account_id = None , amount_responded = None , status = None , address_shipping = None , address_billing = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_map = { cls . FIELD_AMOUNT_RESPONDED : amount_responded , cls . FIELD_STATUS : status , cls . FIELD_ADDRESS_SHIPPING : address_shipping , cls . FIELD_ADDRESS_BILLING : address_billing } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_UPDATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) , request_response_id ) response_raw = api_client . put ( endpoint_url , request_bytes , custom_headers ) return BunqResponseRequestResponse . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_PUT ) )
Update the status to accept or reject the RequestResponse .
19,265
def create ( cls , counter_user_alias , share_detail , status , monetary_account_id = None , draft_share_invite_bank_id = None , share_type = None , start_date = None , end_date = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_COUNTER_USER_ALIAS : counter_user_alias , cls . FIELD_DRAFT_SHARE_INVITE_BANK_ID : draft_share_invite_bank_id , cls . FIELD_SHARE_DETAIL : share_detail , cls . FIELD_STATUS : status , cls . FIELD_SHARE_TYPE : share_type , cls . FIELD_START_DATE : start_date , cls . FIELD_END_DATE : end_date } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Create a new share inquiry for a monetary account specifying the permission the other bunq user will have on it .
19,266
def list ( cls , params = None , custom_headers = None ) : if params is None : params = { } if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) endpoint_url = cls . _ENDPOINT_URL_LISTING response_raw = api_client . get ( endpoint_url , params , custom_headers ) return BunqResponseUserList . cast_from_bunq_response ( cls . _from_json_list ( response_raw ) )
Get a collection of all available users .
19,267
def update ( cls , first_name = None , middle_name = None , last_name = None , public_nick_name = None , address_main = None , address_postal = None , avatar_uuid = None , tax_resident = None , document_type = None , document_number = None , document_country_of_issuance = None , document_front_attachment_id = None , document_back_attachment_id = None , date_of_birth = None , place_of_birth = None , country_of_birth = None , nationality = None , language = None , region = None , gender = None , status = None , sub_status = None , legal_guardian_alias = None , session_timeout = None , card_ids = None , card_limits = None , daily_limit_without_confirmation_login = None , notification_filters = None , display_name = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_map = { cls . FIELD_FIRST_NAME : first_name , cls . FIELD_MIDDLE_NAME : middle_name , cls . FIELD_LAST_NAME : last_name , cls . FIELD_PUBLIC_NICK_NAME : public_nick_name , cls . FIELD_ADDRESS_MAIN : address_main , cls . FIELD_ADDRESS_POSTAL : address_postal , cls . FIELD_AVATAR_UUID : avatar_uuid , cls . FIELD_TAX_RESIDENT : tax_resident , cls . FIELD_DOCUMENT_TYPE : document_type , cls . FIELD_DOCUMENT_NUMBER : document_number , cls . FIELD_DOCUMENT_COUNTRY_OF_ISSUANCE : document_country_of_issuance , cls . FIELD_DOCUMENT_FRONT_ATTACHMENT_ID : document_front_attachment_id , cls . FIELD_DOCUMENT_BACK_ATTACHMENT_ID : document_back_attachment_id , cls . FIELD_DATE_OF_BIRTH : date_of_birth , cls . FIELD_PLACE_OF_BIRTH : place_of_birth , cls . FIELD_COUNTRY_OF_BIRTH : country_of_birth , cls . FIELD_NATIONALITY : nationality , cls . FIELD_LANGUAGE : language , cls . FIELD_REGION : region , cls . FIELD_GENDER : gender , cls . FIELD_STATUS : status , cls . FIELD_SUB_STATUS : sub_status , cls . FIELD_LEGAL_GUARDIAN_ALIAS : legal_guardian_alias , cls . FIELD_SESSION_TIMEOUT : session_timeout , cls . FIELD_CARD_IDS : card_ids , cls . FIELD_CARD_LIMITS : card_limits , cls . FIELD_DAILY_LIMIT_WITHOUT_CONFIRMATION_LOGIN : daily_limit_without_confirmation_login , cls . FIELD_NOTIFICATION_FILTERS : notification_filters , cls . FIELD_DISPLAY_NAME : display_name } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_UPDATE . format ( cls . _determine_user_id ( ) ) response_raw = api_client . put ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Modify a specific person object s data .
19,268
def update ( cls , name = None , public_nick_name = None , avatar_uuid = None , address_main = None , address_postal = None , language = None , region = None , country = None , ubo = None , chamber_of_commerce_number = None , legal_form = None , status = None , sub_status = None , session_timeout = None , daily_limit_without_confirmation_login = None , notification_filters = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_map = { cls . FIELD_NAME : name , cls . FIELD_PUBLIC_NICK_NAME : public_nick_name , cls . FIELD_AVATAR_UUID : avatar_uuid , cls . FIELD_ADDRESS_MAIN : address_main , cls . FIELD_ADDRESS_POSTAL : address_postal , cls . FIELD_LANGUAGE : language , cls . FIELD_REGION : region , cls . FIELD_COUNTRY : country , cls . FIELD_UBO : ubo , cls . FIELD_CHAMBER_OF_COMMERCE_NUMBER : chamber_of_commerce_number , cls . FIELD_LEGAL_FORM : legal_form , cls . FIELD_STATUS : status , cls . FIELD_SUB_STATUS : sub_status , cls . FIELD_SESSION_TIMEOUT : session_timeout , cls . FIELD_DAILY_LIMIT_WITHOUT_CONFIRMATION_LOGIN : daily_limit_without_confirmation_login , cls . FIELD_NOTIFICATION_FILTERS : notification_filters } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_UPDATE . format ( cls . _determine_user_id ( ) ) response_raw = api_client . put ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Modify a specific company s data .
19,269
def create ( cls , cash_register_id , tab_uuid , description , monetary_account_id = None , ean_code = None , avatar_attachment_uuid = None , tab_attachment = None , quantity = None , amount = None , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_DESCRIPTION : description , cls . FIELD_EAN_CODE : ean_code , cls . FIELD_AVATAR_ATTACHMENT_UUID : avatar_attachment_uuid , cls . FIELD_TAB_ATTACHMENT : tab_attachment , cls . FIELD_QUANTITY : quantity , cls . FIELD_AMOUNT : amount } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) , cls . _determine_monetary_account_id ( monetary_account_id ) , cash_register_id , tab_uuid ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Create a new TabItem for a given Tab .
19,270
def create ( cls , token , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_TOKEN : token } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseTokenQrRequestIdeal . cast_from_bunq_response ( cls . _from_json ( response_raw , cls . _OBJECT_TYPE_POST ) )
Create a request from an ideal transaction .
19,271
def create ( cls , monetary_account_paying_id , request_id , maximum_amount_per_month , custom_headers = None ) : if custom_headers is None : custom_headers = { } request_map = { cls . FIELD_MONETARY_ACCOUNT_PAYING_ID : monetary_account_paying_id , cls . FIELD_REQUEST_ID : request_id , cls . FIELD_MAXIMUM_AMOUNT_PER_MONTH : maximum_amount_per_month } request_map_string = converter . class_to_json ( request_map ) request_map_string = cls . _remove_field_for_request ( request_map_string ) api_client = client . ApiClient ( cls . _get_api_context ( ) ) request_bytes = request_map_string . encode ( ) endpoint_url = cls . _ENDPOINT_URL_CREATE . format ( cls . _determine_user_id ( ) ) response_raw = api_client . post ( endpoint_url , request_bytes , custom_headers ) return BunqResponseInt . cast_from_bunq_response ( cls . _process_for_id ( response_raw ) )
Create a new SDD whitelist entry .
19,272
def icon_resource ( name , package = None ) : if not package : package = '%s.resources.images' % calling_package ( ) name = resource_filename ( package , name ) if not name . startswith ( '/' ) : return 'file://%s' % abspath ( name ) return 'file://%s' % name
Returns the absolute URI path to an image . If a package is not explicitly specified then the calling package name is used .
19,273
def image_resources ( package = None , directory = 'resources' ) : if not package : package = calling_package ( ) package_dir = '.' . join ( [ package , directory ] ) images = [ ] for i in resource_listdir ( package , directory ) : if i . startswith ( '__' ) or i . endswith ( '.egg-info' ) : continue fname = resource_filename ( package_dir , i ) if resource_isdir ( package_dir , i ) : images . extend ( image_resources ( package_dir , i ) ) elif what ( fname ) : images . append ( fname ) return images
Returns all images under the directory relative to a package path . If no directory or package is specified then the resources module of the calling package will be used . Images are recursively discovered .
19,274
def indexbox ( msg = "Shall I continue?" , title = " " , choices = ( "Yes" , "No" ) , image = None ) : reply = buttonbox ( msg = msg , choices = choices , title = title , image = image ) index = - 1 for choice in choices : index = index + 1 if reply == choice : return index raise AssertionError ( "There is a program logic error in the EasyGui code for indexbox." )
Display a buttonbox with the specified choices . Return the index of the choice selected .
19,275
def msgbox ( msg = "(Your message goes here)" , title = " " , ok_button = "OK" , image = None , root = None ) : if type ( ok_button ) != type ( "OK" ) : raise AssertionError ( "The 'ok_button' argument to msgbox must be a string." ) return buttonbox ( msg = msg , title = title , choices = [ ok_button ] , image = image , root = root )
Display a messagebox
19,276
def multpasswordbox ( msg = "Fill in values for the fields." , title = " " , fields = tuple ( ) , values = tuple ( ) ) : r return __multfillablebox ( msg , title , fields , values , "*" )
r Same interface as multenterbox . But in multpassword box the last of the fields is assumed to be a password and is masked with asterisks .
19,277
def passwordbox ( msg = "Enter your password." , title = " " , default = "" , image = None , root = None ) : return __fillablebox ( msg , title , default , mask = "*" , image = image , root = root )
Show a box in which a user can enter a password . The text is masked with asterisks so the password is not displayed . Returns the text that the user entered or None if he cancels the operation .
19,278
def diropenbox ( msg = None , title = None , default = None ) : if sys . platform == 'darwin' : _bring_to_front ( ) title = getFileDialogTitle ( msg , title ) localRoot = Tk ( ) localRoot . withdraw ( ) if not default : default = None f = tk_FileDialog . askdirectory ( parent = localRoot , title = title , initialdir = default , initialfile = None ) localRoot . destroy ( ) if not f : return None return os . path . normpath ( f )
A dialog to get a directory name . Note that the msg argument if specified is ignored .
19,279
def __buttonEvent ( event ) : global boxRoot , __widgetTexts , __replyButtonText __replyButtonText = __widgetTexts [ event . widget ] boxRoot . quit ( )
Handle an event that is generated by a person clicking a button .
19,280
def on_terminate ( func ) : def exit_function ( * args ) : func ( ) exit ( 0 ) signal . signal ( signal . SIGTERM , exit_function )
Register a signal handler to execute when Maltego forcibly terminates the transform .
19,281
def croak ( error , message_writer = message ) : if isinstance ( error , MaltegoException ) : message_writer ( MaltegoTransformExceptionMessage ( exceptions = [ error ] ) ) else : message_writer ( MaltegoTransformExceptionMessage ( exceptions = [ MaltegoException ( error ) ] ) )
Throw an exception in the Maltego GUI containing error_msg .
19,282
def debug ( * args ) : for i in args : click . echo ( 'D:%s' % str ( i ) , err = True )
Send debug messages to the Maltego console .
19,283
def create_aws_lambda ( ctx , bucket , region_name , aws_access_key_id , aws_secret_access_key ) : from canari . commands . create_aws_lambda import create_aws_lambda create_aws_lambda ( ctx . project , bucket , region_name , aws_access_key_id , aws_secret_access_key )
Creates an AWS Chalice project for deployment to AWS Lambda .
19,284
def create_package ( package , author , email , description , create_example ) : from canari . commands . create_package import create_package create_package ( package , author , email , description , create_example )
Creates a Canari transform package skeleton .
19,285
def create_transform ( ctx , transform ) : from canari . commands . create_transform import create_transform create_transform ( ctx . project , transform )
Creates a new transform in the specified directory and auto - updates dependencies .
19,286
def dockerize_package ( ctx , os , host ) : from canari . commands . dockerize_package import dockerize_package dockerize_package ( ctx . project , os , host )
Creates a Docker build file pre - configured with Plume .
19,287
def generate_entities ( ctx , output_path , mtz_file , exclude_namespace , namespace , maltego_entities , append , entity ) : from canari . commands . generate_entities import generate_entities generate_entities ( ctx . project , output_path , mtz_file , exclude_namespace , namespace , maltego_entities , append , entity )
Converts Maltego entity definition files to Canari python classes . Excludes Maltego built - in entities by default .
19,288
def generate_entities_doc ( ctx , out_path , package ) : from canari . commands . generate_entities_doc import generate_entities_doc generate_entities_doc ( ctx . project , out_path , package )
Create entities documentation from Canari python classes file .
19,289
def load_plume_package ( package , plume_dir , accept_defaults ) : from canari . commands . load_plume_package import load_plume_package load_plume_package ( package , plume_dir , accept_defaults )
Loads a canari package into Plume .
19,290
def shell ( ctx , package , working_dir , sudo ) : ctx . mode = CanariMode . LocalShellDebug from canari . commands . shell import shell shell ( package , working_dir , sudo )
Runs a Canari interactive python shell
19,291
def unload_plume_package ( package , plume_dir ) : from canari . commands . unload_plume_package import unload_plume_package unload_plume_package ( package , plume_dir )
Unloads a canari package from Plume .
19,292
def set_canari_mode ( mode = CanariMode . Unknown ) : global canari_mode old_mode = canari_mode canari_mode = mode return old_mode
Sets the global operating mode for Canari . This is used to alter the behaviour of dangerous classes like the CanariConfigParser .
19,293
def approx_fprime ( x , f , epsilon = None , args = ( ) , kwargs = None , centered = True ) : kwargs = { } if kwargs is None else kwargs n = len ( x ) f0 = f ( * ( x , ) + args , ** kwargs ) dim = np . atleast_1d ( f0 ) . shape grad = np . zeros ( ( n , ) + dim , float ) ei = np . zeros ( np . shape ( x ) , float ) if not centered : epsilon = _get_epsilon ( x , 2 , epsilon , n ) for k in range ( n ) : ei [ k ] = epsilon [ k ] grad [ k , : ] = ( f ( * ( x + ei , ) + args , ** kwargs ) - f0 ) / epsilon [ k ] ei [ k ] = 0.0 else : epsilon = _get_epsilon ( x , 3 , epsilon , n ) / 2. for k in range ( n ) : ei [ k ] = epsilon [ k ] grad [ k , : ] = ( f ( * ( x + ei , ) + args , ** kwargs ) - f ( * ( x - ei , ) + args , ** kwargs ) ) / ( 2 * epsilon [ k ] ) ei [ k ] = 0.0 grad = grad . squeeze ( ) axes = [ 0 , 1 , 2 ] [ : grad . ndim ] axes [ : 2 ] = axes [ 1 : : - 1 ] return np . transpose ( grad , axes = axes ) . squeeze ( )
Gradient of function or Jacobian if function fun returns 1d array
19,294
def do_cprofile ( func ) : def profiled_func ( * args , ** kwargs ) : profile = cProfile . Profile ( ) try : profile . enable ( ) result = func ( * args , ** kwargs ) profile . disable ( ) return result finally : profile . print_stats ( ) return profiled_func
Decorator to profile a function
19,295
def convolve ( sequence , rule , ** kwds ) : dtype = np . result_type ( float , np . ravel ( sequence ) [ 0 ] ) seq = np . asarray ( sequence , dtype = dtype ) if np . iscomplexobj ( seq ) : return ( convolve1d ( seq . real , rule , ** kwds ) + 1j * convolve1d ( seq . imag , rule , ** kwds ) ) return convolve1d ( seq , rule , ** kwds )
Wrapper around scipy . ndimage . convolve1d that allows complex input .
19,296
def dea3 ( v0 , v1 , v2 , symmetric = False ) : e0 , e1 , e2 = np . atleast_1d ( v0 , v1 , v2 ) with warnings . catch_warnings ( ) : warnings . simplefilter ( "ignore" ) delta2 , delta1 = e2 - e1 , e1 - e0 err2 , err1 = np . abs ( delta2 ) , np . abs ( delta1 ) tol2 , tol1 = max_abs ( e2 , e1 ) * _EPS , max_abs ( e1 , e0 ) * _EPS delta1 [ err1 < _TINY ] = _TINY delta2 [ err2 < _TINY ] = _TINY ss = 1.0 / delta2 - 1.0 / delta1 + _TINY smalle2 = abs ( ss * e1 ) <= 1.0e-3 converged = ( err1 <= tol1 ) & ( err2 <= tol2 ) | smalle2 result = np . where ( converged , e2 * 1.0 , e1 + 1.0 / ss ) abserr = err1 + err2 + np . where ( converged , tol2 * 10 , np . abs ( result - e2 ) ) if symmetric and len ( result ) > 1 : return result [ : - 1 ] , abserr [ 1 : ] return result , abserr
Extrapolate a slowly convergent sequence
19,297
def _fd_matrix ( step_ratio , parity , nterms ) : _assert ( 0 <= parity <= 6 , 'Parity must be 0, 1, 2, 3, 4, 5 or 6! ({0:d})' . format ( parity ) ) step = [ 1 , 2 , 2 , 4 , 4 , 4 , 4 ] [ parity ] inv_sr = 1.0 / step_ratio offset = [ 1 , 1 , 2 , 2 , 4 , 1 , 3 ] [ parity ] c0 = [ 1.0 , 1.0 , 1.0 , 2.0 , 24.0 , 1.0 , 6.0 ] [ parity ] c = c0 / special . factorial ( np . arange ( offset , step * nterms + offset , step ) ) [ i , j ] = np . ogrid [ 0 : nterms , 0 : nterms ] return np . atleast_2d ( c [ j ] * inv_sr ** ( i * ( step * j + offset ) ) )
Return matrix for finite difference and complex step derivation .
19,298
def _apply_fd_rule ( self , step_ratio , sequence , steps ) : f_del , h , original_shape = self . _vstack ( sequence , steps ) fd_rule = self . _get_finite_difference_rule ( step_ratio ) ne = h . shape [ 0 ] nr = fd_rule . size - 1 _assert ( nr < ne , 'num_steps ({0:d}) must be larger than ' '({1:d}) n + order - 1 = {2:d} + {3:d} -1' ' ({4:s})' . format ( ne , nr + 1 , self . n , self . order , self . method ) ) f_diff = convolve ( f_del , fd_rule [ : : - 1 ] , axis = 0 , origin = nr // 2 ) der_init = f_diff / ( h ** self . n ) ne = max ( ne - nr , 1 ) return der_init [ : ne ] , h [ : ne ] , original_shape
Return derivative estimates of fun at x0 for a sequence of stepsizes h
19,299
def _complex_even ( f , fx , x , h ) : n = len ( x ) ee = np . diag ( h ) hess = 2. * np . outer ( h , h ) for i in range ( n ) : for j in range ( i , n ) : hess [ i , j ] = ( f ( x + 1j * ee [ i ] + ee [ j ] ) - f ( x + 1j * ee [ i ] - ee [ j ] ) ) . imag / hess [ j , i ] hess [ j , i ] = hess [ i , j ] return hess
Calculate Hessian with complex - step derivative approximation