def test():
    '''Test `is_legal_variable_name` on various legal and illegal inputs.'''
    legals = ['qwerqw', 'wer23434f3', 'VDF4vr', '_4523ga', 'AGF___43___4_',
              '_', '__', '___']
    illegals = ['1dgfads', 'aga`fdg', '-haeth', '4gag5h+sdfh.', '.afdg',
                'fdga"adfg', 'afdga afd']
    
    for legal in legals:
        assert is_legal_ascii_variable_name(legal)
    
    for illegal in illegals:
        assert not is_legal_ascii_variable_name(illegal)
Exemplo n.º 2
0
def test():
    '''Test `is_legal_variable_name` on various legal and illegal inputs.'''
    legals = [
        'qwerqw', 'wer23434f3', 'VDF4vr', '_4523ga', 'AGF___43___4_', '_',
        '__', '___'
    ]
    illegals = [
        '1dgfads', 'aga`fdg', '-haeth', '4gag5h+sdfh.', '.afdg', 'fdga"adfg',
        'afdga afd'
    ]

    for legal in legals:
        assert is_legal_ascii_variable_name(legal)

    for illegal in illegals:
        assert not is_legal_ascii_variable_name(illegal)
Exemplo n.º 3
0
 def _check_validity_and_color(self):
     '''
     Check whether the value is a valid name, if it isn't show error color.
     '''
     is_valid = misc_tools.is_legal_ascii_variable_name(self.GetValue())
     if is_valid:
         self.SetBackgroundColour(self._original_background_color)
     else:  # not is_valid
         self.SetBackgroundColour(colors.get_error_background_color())
     self.Refresh()
     return is_valid
Exemplo n.º 4
0
    def save(self):
        '''
        Save all arguments to the dialog, unless there's an error resolving.
        
        The arguments will be saved to the following attributes of the dialog:
        
         *  `.step_functions_to_argument_dicts[step_function]`
         *  `.step_functions_to_star_args[step_function]`
         *  `.step_functions_to_star_kwargs[step_function]`
        
        '''

        step_profile_dialog = self.step_profile_dialog
        step_function = self.step_function


        arg_dict = step_profile_dialog.\
            step_functions_to_argument_dicts[step_function]

        star_arg_list = step_profile_dialog.\
            step_functions_to_star_args[step_function]

        star_kwarg_dict = step_profile_dialog.\
            step_functions_to_star_kwargs[step_function]

        resolve_failed = None

        if self.arg_box:
            arg_dict.clear()
            for arg in self.arg_box.args:
                name = arg.name
                value_string = arg.get_value_string()
                try:
                    # Not storing, just checking if it'll raise an error:
                    self.step_profile_dialog.resolve(value_string)
                except Exception:
                    if not resolve_failed:
                        resolve_failed = ResolveFailed(
                            "Can't resolve '%s' to a Python "
                            "object." % value_string, arg.value_text_ctrl)
                else:
                    arg_dict[name] = value_string

        if self.star_arg_box:
            del star_arg_list[:]
            for star_arg in self.star_arg_box.star_args:
                value_string = star_arg.get_value_string()
                try:
                    # Not storing, just checking if it'll raise an error:
                    self.step_profile_dialog.resolve(value_string)
                except Exception:
                    if not resolve_failed:
                        resolve_failed = ResolveFailed(
                            "Can't resolve '%s' to a Python "
                            "object." % value_string, star_arg.value_text_ctrl)
                else:
                    star_arg_list.append(value_string)

        if self.star_kwarg_box:
            star_kwarg_dict.clear()
            for star_kwarg in self.star_kwarg_box.star_kwargs:
                name = star_kwarg.get_name_string()
                if not misc_tools.is_legal_ascii_variable_name(name):
                    if not resolve_failed:
                        resolve_failed = ResolveFailed(
                            "'%s' is not a legal name for a variable." % name,
                            star_kwarg.name_text_ctrl)
                    continue
                value_string = star_kwarg.get_value_string()
                try:
                    # Not storing, just checking if it'll raise an error:
                    self.step_profile_dialog.resolve(value_string)
                except Exception:
                    if not resolve_failed:
                        resolve_failed = ResolveFailed(
                            "Can't resolve '%s' to a Python "
                            "object." % value_string,
                            star_kwarg.value_text_ctrl)
                else:
                    star_kwarg_dict[name] = value_string

        if resolve_failed:
            raise resolve_failed
Exemplo n.º 5
0
    def save(self):
        '''
        Save all arguments to the dialog, unless there's an error resolving.
        
        The arguments will be saved to the following attributes of the dialog:
        
         *  `.step_functions_to_argument_dicts[step_function]`
         *  `.step_functions_to_star_args[step_function]`
         *  `.step_functions_to_star_kwargs[step_function]`
        
        '''
        
        step_profile_dialog = self.step_profile_dialog
        step_function = self.step_function

        
        arg_dict = step_profile_dialog.\
            step_functions_to_argument_dicts[step_function]
        
        star_arg_list = step_profile_dialog.\
            step_functions_to_star_args[step_function]
        
        star_kwarg_dict = step_profile_dialog.\
            step_functions_to_star_kwargs[step_function]
        
        resolve_failed = None
        
        
        if self.arg_box:
            arg_dict.clear()
            for arg in self.arg_box.args:
                name = arg.name
                value_string = arg.get_value_string() 
                try:
                    # Not storing, just checking if it'll raise an error:
                    self.step_profile_dialog.resolve(value_string)
                except Exception:
                    if not resolve_failed:
                        resolve_failed = ResolveFailed(
                            "Can't resolve '%s' to a Python "
                            "object." % value_string,
                            arg.value_text_ctrl
                        )
                else:
                    arg_dict[name] = value_string
        
            
        if self.star_arg_box:
            del star_arg_list[:]
            for star_arg in self.star_arg_box.star_args:
                value_string = star_arg.get_value_string()
                try:
                    # Not storing, just checking if it'll raise an error:
                    self.step_profile_dialog.resolve(value_string)
                except Exception:
                    if not resolve_failed:
                        resolve_failed = ResolveFailed(
                            "Can't resolve '%s' to a Python "
                            "object." % value_string,
                            star_arg.value_text_ctrl
                        )
                else:
                    star_arg_list.append(value_string)
                
                    
        if self.star_kwarg_box:
            star_kwarg_dict.clear()
            for star_kwarg in self.star_kwarg_box.star_kwargs:
                name = star_kwarg.get_name_string()
                if not misc_tools.is_legal_ascii_variable_name(name):
                    if not resolve_failed:
                        resolve_failed = ResolveFailed(
                            "'%s' is not a legal name for a variable." % name,
                            star_kwarg.name_text_ctrl
                        )
                    continue
                value_string = star_kwarg.get_value_string()
                try:
                    # Not storing, just checking if it'll raise an error:
                    self.step_profile_dialog.resolve(value_string)
                except Exception:
                    if not resolve_failed:
                        resolve_failed = ResolveFailed(
                            "Can't resolve '%s' to a Python "
                            "object." % value_string,
                            star_kwarg.value_text_ctrl
                        )
                else:
                    star_kwarg_dict[name] = value_string
                
        
        if resolve_failed:
            raise resolve_failed