idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
5,600
def get_ancestors ( self ) : ancestors = list ( self . get_parents ( ) ) ancestor_unique_attributes = set ( [ ( a . __class__ , a . id ) for a in ancestors ] ) ancestors_with_parents = [ a for a in ancestors if isinstance ( a , DescendantMixin ) ] for ancestor in ancestors_with_parents : for parent in ancestor . get_an...
Get all unique instance ancestors
5,601
def has_succeed ( self ) : status_code = self . _response . status_code if status_code in [ HTTP_CODE_ZERO , HTTP_CODE_SUCCESS , HTTP_CODE_CREATED , HTTP_CODE_EMPTY , HTTP_CODE_MULTIPLE_CHOICES ] : return True if status_code in [ HTTP_CODE_BAD_REQUEST , HTTP_CODE_UNAUTHORIZED , HTTP_CODE_PERMISSION_DENIED , HTTP_CODE_N...
Check if the connection has succeed
5,602
def handle_response_for_connection ( self , should_post = False ) : status_code = self . _response . status_code data = self . _response . data if data and 'errors' in data : self . _response . errors = data [ 'errors' ] if status_code in [ HTTP_CODE_SUCCESS , HTTP_CODE_CREATED , HTTP_CODE_EMPTY ] : return True if stat...
Check if the response succeed or not .
5,603
def _did_receive_response ( self , response ) : try : data = response . json ( ) except : data = None self . _response = NURESTResponse ( status_code = response . status_code , headers = response . headers , data = data , reason = response . reason ) level = logging . WARNING if self . _response . status_code >= 300 el...
Called when a response is received
5,604
def _did_timeout ( self ) : bambou_logger . debug ( 'Bambou %s on %s has timeout (timeout=%ss)..' % ( self . _request . method , self . _request . url , self . timeout ) ) self . _has_timeouted = True if self . async : self . _callback ( self ) else : return self
Called when a resquest has timeout
5,605
def _make_request ( self , session = None ) : if session is None : session = NURESTSession . get_current_session ( ) self . _has_timeouted = False controller = session . login_controller enterprise = controller . enterprise user_name = controller . user api_key = controller . api_key certificate = controller . certific...
Make a synchronous request
5,606
def __make_request ( self , requests_session , method , url , params , data , headers , certificate ) : verify = False timeout = self . timeout try : response = requests_session . request ( method = method , url = url , data = data , headers = headers , verify = verify , timeout = timeout , params = params , cert = cer...
Encapsulate requests call
5,607
def start ( self ) : from . nurest_session import NURESTSession session = NURESTSession . get_current_session ( ) if self . async : thread = threading . Thread ( target = self . _make_request , kwargs = { 'session' : session } ) thread . is_daemon = False thread . start ( ) return self . transaction_id return self . _m...
Make an HTTP request with a specific method
5,608
def reset ( self ) : self . _request = None self . _response = None self . _transaction_id = uuid . uuid4 ( ) . hex
Reset the connection
5,609
def create ( self , price_estimate ) : kwargs = { } try : previous_price_estimate = price_estimate . get_previous ( ) except ObjectDoesNotExist : pass else : configuration = previous_price_estimate . consumption_details . configuration kwargs [ 'configuration' ] = configuration month_start = core_utils . month_start ( ...
Take configuration from previous month it it exists . Set last_update_time equals to the beginning of the month .
5,610
def get_fields ( self ) : fields = super ( BaseHookSerializer , self ) . get_fields ( ) fields [ 'event_types' ] = serializers . MultipleChoiceField ( choices = loggers . get_valid_events ( ) , required = False ) fields [ 'event_groups' ] = serializers . MultipleChoiceField ( choices = loggers . get_event_groups_keys (...
When static declaration is used event type choices are fetched too early - even before all apps are initialized . As a result some event types are missing . When dynamic declaration is used all valid event types are available as choices .
5,611
def build_nested_field ( self , field_name , relation_info , nested_depth ) : if field_name != 'children' : return super ( PriceEstimateSerializer , self ) . build_nested_field ( field_name , relation_info , nested_depth ) field_class = self . __class__ field_kwargs = { 'read_only' : True , 'many' : True , 'context' : ...
Use PriceEstimateSerializer to serialize estimate children
5,612
def prepare_for_reraise ( error , exc_info = None ) : if not hasattr ( error , "_type_" ) : if exc_info is None : exc_info = sys . exc_info ( ) error . _type_ = exc_info [ 0 ] error . _traceback = exc_info [ 2 ] return error
Prepares the exception for re - raising with reraise method .
5,613
def reraise ( error ) : if hasattr ( error , "_type_" ) : six . reraise ( type ( error ) , error , error . _traceback ) raise error
Re - raises the error that was processed by prepare_for_reraise earlier .
5,614
def rest_name ( cls ) : if cls . __name__ == "NURESTRootObject" or cls . __name__ == "NURESTObject" : return "Not Implemented" if cls . __rest_name__ is None : raise NotImplementedError ( '%s has no defined name. Implement rest_name property first.' % cls ) return cls . __rest_name__
Represents a singular REST name
5,615
def resource_name ( cls ) : if cls . __name__ == "NURESTRootObject" or cls . __name__ == "NURESTObject" : return "Not Implemented" if cls . __resource_name__ is None : raise NotImplementedError ( '%s has no defined resource name. Implement resource_name property first.' % cls ) return cls . __resource_name__
Represents the resource name
5,616
def _compute_args ( self , data = dict ( ) , ** kwargs ) : for name , remote_attribute in self . _attributes . items ( ) : default_value = BambouConfig . get_default_attribute_value ( self . __class__ , name , remote_attribute . attribute_type ) setattr ( self , name , default_value ) if len ( data ) > 0 : self . from_...
Compute the arguments
5,617
def children_rest_names ( self ) : names = [ ] for fetcher in self . fetchers : names . append ( fetcher . __class__ . managed_object_rest_name ( ) ) return names
Gets the list of all possible children ReST names .
5,618
def validate ( self ) : self . _attribute_errors = dict ( ) for local_name , attribute in self . _attributes . items ( ) : value = getattr ( self , local_name , None ) if attribute . is_required and ( value is None or value == "" ) : self . _attribute_errors [ local_name ] = { 'title' : 'Invalid input' , 'description' ...
Validate the current object attributes .
5,619
def expose_attribute ( self , local_name , attribute_type , remote_name = None , display_name = None , is_required = False , is_readonly = False , max_length = None , min_length = None , is_identifier = False , choices = None , is_unique = False , is_email = False , is_login = False , is_editable = True , is_password =...
Expose local_name as remote_name
5,620
def is_owned_by_current_user ( self ) : from bambou . nurest_root_object import NURESTRootObject root_object = NURESTRootObject . get_default_root_object ( ) return self . _owner == root_object . id
Check if the current user owns the object
5,621
def parent_for_matching_rest_name ( self , rest_names ) : parent = self while parent : if parent . rest_name in rest_names : return parent parent = parent . parent_object return None
Return parent that matches a rest name
5,622
def genealogic_types ( self ) : types = [ ] parent = self while parent : types . append ( parent . rest_name ) parent = parent . parent_object return types
Get genealogic types
5,623
def genealogic_ids ( self ) : ids = [ ] parent = self while parent : ids . append ( parent . id ) parent = parent . parent_object return ids
Get all genealogic ids
5,624
def add_child ( self , child ) : rest_name = child . rest_name children = self . fetcher_for_rest_name ( rest_name ) if children is None : raise InternalConsitencyError ( 'Could not find fetcher with name %s while adding %s in parent %s' % ( rest_name , child , self ) ) if child not in children : child . parent_object ...
Add a child
5,625
def remove_child ( self , child ) : rest_name = child . rest_name children = self . fetcher_for_rest_name ( rest_name ) target_child = None for local_child in children : if local_child . id == child . id : target_child = local_child break if target_child : target_child . parent_object = None children . remove ( target_...
Remove a child
5,626
def to_dict ( self ) : dictionary = dict ( ) for local_name , attribute in self . _attributes . items ( ) : remote_name = attribute . remote_name if hasattr ( self , local_name ) : value = getattr ( self , local_name ) if isinstance ( value , NURESTObject ) : value = value . to_dict ( ) if isinstance ( value , list ) a...
Converts the current object into a Dictionary using all exposed ReST attributes .
5,627
def from_dict ( self , dictionary ) : for remote_name , remote_value in dictionary . items ( ) : local_name = next ( ( name for name , attribute in self . _attributes . items ( ) if attribute . remote_name == remote_name ) , None ) if local_name : setattr ( self , local_name , remote_value ) else : pass
Sets all the exposed ReST attribues from the given dictionary
5,628
def delete ( self , response_choice = 1 , async = False , callback = None ) : return self . _manage_child_object ( nurest_object = self , method = HTTP_METHOD_DELETE , async = async , callback = callback , response_choice = response_choice )
Delete object and call given callback in case of call .
5,629
def save ( self , response_choice = None , async = False , callback = None ) : return self . _manage_child_object ( nurest_object = self , method = HTTP_METHOD_PUT , async = async , callback = callback , response_choice = response_choice )
Update object and call given callback in case of async call
5,630
def send_request ( self , request , async = False , local_callback = None , remote_callback = None , user_info = None ) : callbacks = dict ( ) if local_callback : callbacks [ 'local' ] = local_callback if remote_callback : callbacks [ 'remote' ] = remote_callback connection = NURESTConnection ( request = request , asyn...
Sends a request calls the local callback then the remote callback in case of async call
5,631
def _manage_child_object ( self , nurest_object , method = HTTP_METHOD_GET , async = False , callback = None , handler = None , response_choice = None , commit = False ) : url = None if method == HTTP_METHOD_POST : url = self . get_resource_url_for_child_type ( nurest_object . __class__ ) else : url = self . get_resour...
Low level child management . Send given HTTP method with given nurest_object to given ressource of current object
5,632
def _did_receive_response ( self , connection ) : if connection . has_timeouted : bambou_logger . info ( "NURESTConnection has timeout." ) return has_callbacks = connection . has_callbacks ( ) should_post = not has_callbacks if connection . handle_response_for_connection ( should_post = should_post ) and has_callbacks ...
Receive a response from the connection
5,633
def _did_retrieve ( self , connection ) : response = connection . response try : self . from_dict ( response . data [ 0 ] ) except : pass return self . _did_perform_standard_operation ( connection )
Callback called after fetching the object
5,634
def _did_perform_standard_operation ( self , connection ) : if connection . async : callback = connection . callbacks [ 'remote' ] if connection . user_info and 'nurest_object' in connection . user_info : callback ( connection . user_info [ 'nurest_object' ] , connection ) else : callback ( self , connection ) else : i...
Performs standard opertions
5,635
def create_child ( self , nurest_object , response_choice = None , async = False , callback = None , commit = True ) : return self . _manage_child_object ( nurest_object = nurest_object , async = async , method = HTTP_METHOD_POST , callback = callback , handler = self . _did_create_child , response_choice = response_ch...
Add given nurest_object to the current object
5,636
def instantiate_child ( self , nurest_object , from_template , response_choice = None , async = False , callback = None , commit = True ) : if not from_template . id : raise InternalConsitencyError ( "Cannot instantiate a child from a template with no ID: %s." % from_template ) nurest_object . template_id = from_templa...
Instantiate an nurest_object from a template object
5,637
def _did_create_child ( self , connection ) : response = connection . response try : connection . user_info [ 'nurest_object' ] . from_dict ( response . data [ 0 ] ) except Exception : pass return self . _did_perform_standard_operation ( connection )
Callback called after adding a new child nurest_object
5,638
def assign ( self , objects , nurest_object_type , async = False , callback = None , commit = True ) : ids = list ( ) for nurest_object in objects : ids . append ( nurest_object . id ) url = self . get_resource_url_for_child_type ( nurest_object_type ) request = NURESTRequest ( method = HTTP_METHOD_PUT , url = url , da...
Reference a list of objects into the current resource
5,639
def rest_equals ( self , rest_object ) : if not self . equals ( rest_object ) : return False return self . to_dict ( ) == rest_object . to_dict ( )
Compare objects REST attributes
5,640
def equals ( self , rest_object ) : if self . _is_dirty : return False if rest_object is None : return False if not isinstance ( rest_object , NURESTObject ) : raise TypeError ( 'The object is not a NURESTObject %s' % rest_object ) if self . rest_name != rest_object . rest_name : return False if self . id and rest_obje...
Compare with another object
5,641
def get_ip_address ( request ) : if 'HTTP_X_FORWARDED_FOR' in request . META : return request . META [ 'HTTP_X_FORWARDED_FOR' ] . split ( ',' ) [ 0 ] . strip ( ) else : return request . META [ 'REMOTE_ADDR' ]
Correct IP address is expected as first element of HTTP_X_FORWARDED_FOR or REMOTE_ADDR
5,642
def get_estimates_without_scope_in_month ( self , customer ) : estimates = self . get_price_estimates_for_customer ( customer ) if not estimates : return [ ] tables = { model : collections . defaultdict ( list ) for model in self . get_estimated_models ( ) } dates = set ( ) for estimate in estimates : date = ( estimate...
It is expected that valid row for each month contains at least one price estimate for customer service setting service service project link project and resource . Otherwise all price estimates in the row should be deleted .
5,643
def get_default_value ( self ) : if self . choices : return self . choices [ 0 ] value = self . attribute_type ( ) if self . attribute_type is time : value = int ( value ) elif self . attribute_type is str : value = "A" if self . min_length : if self . attribute_type is str : value = value . ljust ( self . min_length ,...
Get a default value of the attribute_type
5,644
def get_min_value ( self ) : value = self . get_default_value ( ) if self . attribute_type is str : min_value = value [ : self . min_length - 1 ] elif self . attribute_type is int : min_value = self . min_length - 1 else : raise TypeError ( 'Attribute %s can not have a minimum value' % self . local_name ) return min_va...
Get the minimum value
5,645
def get_max_value ( self ) : value = self . get_default_value ( ) if self . attribute_type is str : max_value = value . ljust ( self . max_length + 1 , 'a' ) elif self . attribute_type is int : max_value = self . max_length + 1 else : raise TypeError ( 'Attribute %s can not have a maximum value' % self . local_name ) r...
Get the maximum value
5,646
def get_api_root_view ( self , api_urls = None ) : api_root_dict = OrderedDict ( ) list_name = self . routes [ 0 ] . name for prefix , viewset , basename in self . registry : api_root_dict [ prefix ] = list_name . format ( basename = basename ) class APIRootView ( views . APIView ) : _ignore_model_permissions = True ex...
Return a basic root view .
5,647
def get_default_base_name ( self , viewset ) : queryset = getattr ( viewset , 'queryset' , None ) if queryset is not None : get_url_name = getattr ( queryset . model , 'get_url_name' , None ) if get_url_name is not None : return get_url_name ( ) return super ( SortedDefaultRouter , self ) . get_default_base_name ( view...
Attempt to automatically determine base name using get_url_name .
5,648
def change_customer_nc_users_quota ( sender , structure , user , role , signal , ** kwargs ) : assert signal in ( signals . structure_role_granted , signals . structure_role_revoked ) , 'Handler "change_customer_nc_users_quota" has to be used only with structure_role signals' assert sender in ( Customer , Project ) , '...
Modify nc_user_count quota usage on structure role grant or revoke
5,649
def delete_service_settings_on_service_delete ( sender , instance , ** kwargs ) : service = instance try : service_settings = service . settings except ServiceSettings . DoesNotExist : return if not service_settings . shared : service . settings . delete ( )
Delete not shared service settings without services
5,650
def delete_service_settings_on_scope_delete ( sender , instance , ** kwargs ) : for service_settings in ServiceSettings . objects . filter ( scope = instance ) : service_settings . unlink_descendants ( ) service_settings . delete ( )
If VM that contains service settings were deleted - all settings resources could be safely deleted from NC .
5,651
def url ( self , url ) : if url and url . endswith ( '/' ) : url = url [ : - 1 ] self . _url = url
Set API URL endpoint
5,652
def get_authentication_header ( self , user = None , api_key = None , password = None , certificate = None ) : if not user : user = self . user if not api_key : api_key = self . api_key if not password : password = self . password if not password : password = self . password if not certificate : certificate = self . _c...
Return authenication string to place in Authorization Header
5,653
def impersonate ( self , user , enterprise ) : if not user or not enterprise : raise ValueError ( 'You must set a user name and an enterprise name to begin impersonification' ) self . _is_impersonating = True self . _impersonation = "%s@%s" % ( user , enterprise )
Impersonate a user in a enterprise
5,654
def equals ( self , controller ) : if controller is None : return False return self . user == controller . user and self . enterprise == controller . enterprise and self . url == controller . url
Verify if the controller corresponds to the current one .
5,655
def release ( self , conn ) : if conn . in_transaction : raise InvalidRequestError ( "Cannot release a connection with " "not finished transaction" ) raw = conn . connection res = yield from self . _pool . release ( raw ) return res
Revert back connection to pool .
5,656
def get_configuration ( cls , resource ) : strategy = cls . _get_strategy ( resource . __class__ ) return strategy . get_configuration ( resource )
Return how much consumables are used by resource with current configuration .
5,657
def get_version ( ) : import imp import os mod = imp . load_source ( 'version' , os . path . join ( 'skdata' , '__init__.py' ) ) return mod . __version__
Obtain the version number
5,658
def accept ( self , request , uuid = None ) : invitation = self . get_object ( ) if invitation . state != models . Invitation . State . PENDING : raise ValidationError ( _ ( 'Only pending invitation can be accepted.' ) ) elif invitation . civil_number and invitation . civil_number != request . user . civil_number : rai...
Accept invitation for current user .
5,659
def scope_deletion ( sender , instance , ** kwargs ) : is_resource = isinstance ( instance , structure_models . ResourceMixin ) if is_resource and getattr ( instance , 'PERFORM_UNLINK' , False ) : _resource_unlink ( resource = instance ) elif is_resource and not getattr ( instance , 'PERFORM_UNLINK' , False ) : _resour...
Run different actions on price estimate scope deletion .
5,660
def _resource_deletion ( resource ) : if resource . __class__ not in CostTrackingRegister . registered_resources : return new_configuration = { } price_estimate = models . PriceEstimate . update_resource_estimate ( resource , new_configuration ) price_estimate . init_details ( )
Recalculate consumption details and save resource details
5,661
def resource_update ( sender , instance , created = False , ** kwargs ) : resource = instance try : new_configuration = CostTrackingRegister . get_configuration ( resource ) except ResourceNotRegisteredError : return models . PriceEstimate . update_resource_estimate ( resource , new_configuration , raise_exception = no...
Update resource consumption details and price estimate if its configuration has changed . Create estimates for previous months if resource was created not in current month .
5,662
def resource_quota_update ( sender , instance , ** kwargs ) : quota = instance resource = quota . scope try : new_configuration = CostTrackingRegister . get_configuration ( resource ) except ResourceNotRegisteredError : return models . PriceEstimate . update_resource_estimate ( resource , new_configuration , raise_exce...
Update resource consumption details and price estimate if its configuration has changed
5,663
def _create_historical_estimates ( resource , configuration ) : today = timezone . now ( ) month_start = core_utils . month_start ( today ) while month_start > resource . created : month_start -= relativedelta ( months = 1 ) models . PriceEstimate . create_historical ( resource , configuration , max ( month_start , res...
Create consumption details and price estimates for past months .
5,664
def IPYTHON_MAIN ( ) : import pkg_resources runner_frame = inspect . getouterframes ( inspect . currentframe ( ) ) [ - 2 ] return ( getattr ( runner_frame , "function" , None ) == pkg_resources . load_entry_point ( "ipython" , "console_scripts" , "ipython" ) . __name__ )
Decide if the Ipython command line is running code .
5,665
def register_model ( cls , model ) : rest_name = model . rest_name resource_name = model . resource_name if rest_name not in cls . _model_rest_name_registry : cls . _model_rest_name_registry [ rest_name ] = [ model ] cls . _model_resource_name_registry [ resource_name ] = [ model ] elif model not in cls . _model_rest_n...
Register a model class according to its remote name
5,666
def get_first_model_with_rest_name ( cls , rest_name ) : models = cls . get_models_with_rest_name ( rest_name ) if len ( models ) > 0 : return models [ 0 ] return None
Get the first model corresponding to a rest_name
5,667
def get_first_model_with_resource_name ( cls , resource_name ) : models = cls . get_models_with_resource_name ( resource_name ) if len ( models ) > 0 : return models [ 0 ] return None
Get the first model corresponding to a resource_name
5,668
def find_spec ( self , fullname , target = None ) : spec = super ( ) . find_spec ( fullname , target = target ) if spec is None : original = fullname if "." in fullname : original , fullname = fullname . rsplit ( "." , 1 ) else : original , fullname = "" , original if "_" in fullname : files = fuzzy_file_search ( self ...
Try to finder the spec and if it cannot be found use the underscore starring syntax to identify potential matches .
5,669
def save ( self , async = False , callback = None , encrypted = True ) : if self . _new_password and encrypted : self . password = Sha1 . encrypt ( self . _new_password ) controller = NURESTSession . get_current_session ( ) . login_controller controller . password = self . _new_password controller . api_key = None data...
Updates the user and perform the callback method
5,670
def _did_save ( self , connection ) : self . _new_password = None controller = NURESTSession . get_current_session ( ) . login_controller controller . password = None controller . api_key = self . api_key if connection . async : callback = connection . callbacks [ 'remote' ] if connection . user_info : callback ( conne...
Launched when save has been successfully executed
5,671
def fetch ( self , async = False , callback = None ) : request = NURESTRequest ( method = HTTP_METHOD_GET , url = self . get_resource_url ( ) ) if async : return self . send_request ( request = request , async = async , local_callback = self . _did_fetch , remote_callback = callback ) else : connection = self . send_re...
Fetch all information about the current object
5,672
def _fabtabular ( ) : import csv import sys from pkg_resources import resource_filename data = resource_filename ( __package__ , 'iso-639-3.tab' ) inverted = resource_filename ( __package__ , 'iso-639-3_Name_Index.tab' ) macro = resource_filename ( __package__ , 'iso-639-3-macrolanguages.tab' ) part5 = resource_filenam...
This function retrieves the ISO 639 and inverted names datasets as tsv files and returns them as lists .
5,673
def users ( self , request , uuid = None ) : project = self . get_object ( ) queryset = project . get_users ( ) filter_backend = filters . UserConcatenatedNameOrderingBackend ( ) queryset = filter_backend . filter_queryset ( request , queryset , self ) queryset = self . paginate_queryset ( queryset ) serializer = self ...
A list of users connected to the project
5,674
def can_user_update_settings ( request , view , obj = None ) : if obj is None : return if obj . customer and not obj . shared : return permissions . is_owner ( request , view , obj ) else : return permissions . is_staff ( request , view , obj )
Only staff can update shared settings otherwise user has to be an owner of the settings .
5,675
def list ( self , request , * args , ** kwargs ) : return super ( ServicesViewSet , self ) . list ( request , * args , ** kwargs )
Filter services by type ^^^^^^^^^^^^^^^^^^^^^^^
5,676
def _require_staff_for_shared_settings ( request , view , obj = None ) : if obj is None : return if obj . settings . shared and not request . user . is_staff : raise PermissionDenied ( _ ( 'Only staff users are allowed to import resources from shared services.' ) )
Allow to execute action only if service settings are not shared or user is staff
5,677
def unlink ( self , request , uuid = None ) : service = self . get_object ( ) service . unlink_descendants ( ) self . perform_destroy ( service ) return Response ( status = status . HTTP_204_NO_CONTENT )
Unlink all related resources service project link and service itself .
5,678
def get_aggregator_quotas ( self , quota ) : ancestors = quota . scope . get_quota_ancestors ( ) aggregator_quotas = [ ] for ancestor in ancestors : for ancestor_quota_field in ancestor . get_quotas_fields ( field_class = AggregatorQuotaField ) : if ancestor_quota_field . get_child_quota_name ( ) == quota . name : aggr...
Fetch ancestors quotas that have the same name and are registered as aggregator quotas .
5,679
def subscribe ( self , handler ) : assert callable ( handler ) , "Invalid handler %s" % handler self . handlers . append ( handler )
Adds a new event handler .
5,680
def on ( self , event , handler ) : event_hook = self . get_or_create ( event ) event_hook . subscribe ( handler ) return self
Attaches the handler to the specified event .
5,681
def off ( self , event , handler ) : event_hook = self . get_or_create ( event ) event_hook . unsubscribe ( handler ) return self
Detaches the handler from the specified event .
5,682
def trigger ( self , event , * args ) : event_hook = self . get_or_create ( event ) event_hook . trigger ( * args ) return self
Triggers the specified event by invoking EventHook . trigger under the hood .
5,683
def safe_trigger ( self , event , * args ) : event_hook = self . get_or_create ( event ) event_hook . safe_trigger ( * args ) return self
Safely triggers the specified event by invoking EventHook . safe_trigger under the hood .
5,684
def cancel_expired_invitations ( invitations = None ) : expiration_date = timezone . now ( ) - settings . WALDUR_CORE [ 'INVITATION_LIFETIME' ] if not invitations : invitations = models . Invitation . objects . filter ( state = models . Invitation . State . PENDING ) invitations = invitations . filter ( created__lte = ...
Invitation lifetime must be specified in Waldur Core settings with parameter INVITATION_LIFETIME . If invitation creation time is less than expiration time the invitation will set as expired .
5,685
def _prepare_abi ( self , jsonabi ) : self . signatures = { } for element_description in jsonabi : abi_e = AbiMethod ( element_description ) if abi_e [ "type" ] == "constructor" : self . signatures [ b"__constructor__" ] = abi_e elif abi_e [ "type" ] == "fallback" : abi_e . setdefault ( "inputs" , [ ] ) self . signatur...
Prepare the contract json abi for sighash lookups and fast access
5,686
def describe_input ( self , s ) : signatures = self . signatures . items ( ) for sighash , method in signatures : if sighash is None or sighash . startswith ( b"__" ) : continue if s . startswith ( sighash ) : s = s [ len ( sighash ) : ] types_def = self . signatures . get ( sighash ) [ "inputs" ] types = [ t [ "type" ...
Describe the input bytesequence s based on the loaded contract abi definition
5,687
def assert_is ( expected , actual , message = None , extra = None ) : assert expected is actual , _assert_fail_message ( message , expected , actual , "is not" , extra )
Raises an AssertionError if expected is not actual .
5,688
def assert_is_not ( expected , actual , message = None , extra = None ) : assert expected is not actual , _assert_fail_message ( message , expected , actual , "is" , extra )
Raises an AssertionError if expected is actual .
5,689
def assert_eq ( expected , actual , message = None , tolerance = None , extra = None ) : if tolerance is None : assert expected == actual , _assert_fail_message ( message , expected , actual , "!=" , extra ) else : assert isinstance ( tolerance , _number_types ) , ( "tolerance parameter to assert_eq must be a number: %...
Raises an AssertionError if expected ! = actual .
5,690
def assert_dict_eq ( expected , actual , number_tolerance = None , dict_path = [ ] ) : assert_is_instance ( expected , dict ) assert_is_instance ( actual , dict ) expected_keys = set ( expected . keys ( ) ) actual_keys = set ( actual . keys ( ) ) assert expected_keys <= actual_keys , "Actual dict at %s is missing keys:...
Asserts that two dictionaries are equal producing a custom message if they are not .
5,691
def assert_gt ( left , right , message = None , extra = None ) : assert left > right , _assert_fail_message ( message , left , right , "<=" , extra )
Raises an AssertionError if left_hand < = right_hand .
5,692
def assert_ge ( left , right , message = None , extra = None ) : assert left >= right , _assert_fail_message ( message , left , right , "<" , extra )
Raises an AssertionError if left_hand < right_hand .
5,693
def assert_lt ( left , right , message = None , extra = None ) : assert left < right , _assert_fail_message ( message , left , right , ">=" , extra )
Raises an AssertionError if left_hand > = right_hand .
5,694
def assert_le ( left , right , message = None , extra = None ) : assert left <= right , _assert_fail_message ( message , left , right , ">" , extra )
Raises an AssertionError if left_hand > right_hand .
5,695
def assert_in ( obj , seq , message = None , extra = None ) : assert obj in seq , _assert_fail_message ( message , obj , seq , "is not in" , extra )
Raises an AssertionError if obj is not in seq .
5,696
def assert_not_in ( obj , seq , message = None , extra = None ) : if isinstance ( seq , six . string_types ) and obj in seq and len ( seq ) > 200 : index = seq . find ( obj ) start_index = index - 50 if start_index > 0 : truncated = "(truncated) ..." else : truncated = "" start_index = 0 end_index = index + len ( obj )...
Raises an AssertionError if obj is in iter .
5,697
def assert_in_with_tolerance ( obj , seq , tolerance , message = None , extra = None ) : for i in seq : try : assert_eq ( obj , i , tolerance = tolerance , message = message , extra = extra ) return except AssertionError : pass assert False , _assert_fail_message ( message , obj , seq , "is not in" , extra )
Raises an AssertionError if obj is not in seq using assert_eq cmp .
5,698
def assert_is_substring ( substring , subject , message = None , extra = None ) : assert ( ( subject is not None ) and ( substring is not None ) and ( subject . find ( substring ) != - 1 ) ) , _assert_fail_message ( message , substring , subject , "is not in" , extra )
Raises an AssertionError if substring is not a substring of subject .
5,699
def assert_is_not_substring ( substring , subject , message = None , extra = None ) : assert ( ( subject is not None ) and ( substring is not None ) and ( subject . find ( substring ) == - 1 ) ) , _assert_fail_message ( message , substring , subject , "is in" , extra )
Raises an AssertionError if substring is a substring of subject .