python类error()的实例源码

lex.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_tokens(self):
        tokens = self.ldict.get("tokens",None)
        if not tokens:
            self.log.error("No token list is defined")
            self.error = 1
            return

        if not isinstance(tokens,(list, tuple)):
            self.log.error("tokens must be a list or tuple")
            self.error = 1
            return

        if not tokens:
            self.log.error("tokens is empty")
            self.error = 1
            return

        self.tokens = tokens

    # Validate the tokens
lex.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def __init__(self):
        self.lexre = None             # Master regular expression. This is a list of
                                      # tuples (re,findex) where re is a compiled
                                      # regular expression and findex is a list
                                      # mapping regex group numbers to rules
        self.lexretext = None         # Current regular expression strings
        self.lexstatere = {}          # Dictionary mapping lexer states to master regexs
        self.lexstateretext = {}      # Dictionary mapping lexer states to regex strings
        self.lexstaterenames = {}     # Dictionary mapping lexer states to symbol names
        self.lexstate = "INITIAL"     # Current lexer state
        self.lexstatestack = []       # Stack of lexer states
        self.lexstateinfo = None      # State information
        self.lexstateignore = {}      # Dictionary of ignored characters for each state
        self.lexstateerrorf = {}      # Dictionary of error functions for each state
        self.lexreflags = 0           # Optional re compile flags
        self.lexdata = None           # Actual input data (as a string)
        self.lexpos = 0               # Current position in input text
        self.lexlen = 0               # Length of the input text
        self.lexerrorf = None         # Error rule (if any)
        self.lextokens = None         # List of valid tokens
        self.lexignore = ""           # Ignored characters
        self.lexliterals = ""         # Literal characters that can be passed through
        self.lexmodule = None         # Module
        self.lineno = 1               # Current line number
        self.lexoptimize = 0          # Optimized mode
lex.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def get_tokens(self):
        tokens = self.ldict.get("tokens",None)
        if not tokens:
            self.log.error("No token list is defined")
            self.error = 1
            return

        if not isinstance(tokens,(list, tuple)):
            self.log.error("tokens must be a list or tuple")
            self.error = 1
            return

        if not tokens:
            self.log.error("tokens is empty")
            self.error = 1
            return

        self.tokens = tokens

    # Validate the tokens
__init__.py 文件源码 项目:badwolf 作者: bosondata 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def match_file(self, filename):
        """Used to check if files can be handled by this linter,
        Often this will just file extension checks."""
        pattern = self.options.get('pattern') or self.default_pattern
        if not pattern:
            return True

        globs = pattern.split()
        for glob in globs:
            if fnmatch.fnmatch(filename, glob):
                # ??? glob ??
                return True
        try:
            if re.match(pattern, filename, re.I):
                # ???????????
                return True
        except re.error:
            pass
        return False
regexparser.py 文件源码 项目:gopythongo 作者: gopythongo 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def validate_args(self, args: configargparse.Namespace) -> None:
        if args.version_parser == self.versionparser_name:
            if args.version_regex:
                try:
                    re.compile(args.version_regex)
                except re.error as e:
                    raise ErrorMessage("The regular expression passed to %s (%s) is invalid: %s." %
                                       (highlight("--version-regex"), highlight(args.version_regex), str(e)))

                def check_for(string: str) -> None:
                    if string not in args.version_regex:
                        raise ErrorMessage("The regular expression specified in %s must contain a named group %s." %
                                           (highlight("--version-regex"), highlight(string)))

                for g in ["<major>", "<minor>", "<patch>"]:
                    check_for(g)
            else:
                raise ErrorMessage("%s requires the parameter %s" %
                                   (highlight("--version-parser=%s" % self.versionparser_name),
                                    highlight("--version-regex")))
basic.py 文件源码 项目:DevOps 作者: YoLoveLife 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _check_locale(self):
        '''
        Uses the locale module to test the currently set locale
        (per the LANG and LC_CTYPE environment settings)
        '''
        try:
            # setting the locale to '' uses the default locale
            # as it would be returned by locale.getdefaultlocale()
            locale.setlocale(locale.LC_ALL, '')
        except locale.Error:
            # fallback to the 'C' locale, which may cause unicode
            # issues but is preferable to simply failing because
            # of an unknown locale
            locale.setlocale(locale.LC_ALL, 'C')
            os.environ['LANG'] = 'C'
            os.environ['LC_ALL'] = 'C'
            os.environ['LC_MESSAGES'] = 'C'
        except Exception:
            e = get_exception()
            self.fail_json(msg="An unknown error was encountered while attempting to validate the locale: %s" % e)
basic.py 文件源码 项目:DevOps 作者: YoLoveLife 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _set_cwd(self):
        try:
            cwd = os.getcwd()
            if not os.access(cwd, os.F_OK|os.R_OK):
                raise
            return cwd
        except:
            # we don't have access to the cwd, probably because of sudo.
            # Try and move to a neutral location to prevent errors
            for cwd in [os.path.expandvars('$HOME'), tempfile.gettempdir()]:
                try:
                    if os.access(cwd, os.F_OK|os.R_OK):
                        os.chdir(cwd)
                        return cwd
                except:
                    pass
        # we won't error here, as it may *not* be a problem,
        # and we don't want to break modules unnecessarily
        return None
cooker.py 文件源码 项目:isar 作者: ilbers 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def handlePrefProviders(self):

        for mc in self.multiconfigs:
            localdata = data.createCopy(self.databuilder.mcdata[mc])
            bb.data.update_data(localdata)
            bb.data.expandKeys(localdata)

            # Handle PREFERRED_PROVIDERS
            for p in (localdata.getVar('PREFERRED_PROVIDERS', True) or "").split():
                try:
                    (providee, provider) = p.split(':')
                except:
                    providerlog.critical("Malformed option in PREFERRED_PROVIDERS variable: %s" % p)
                    continue
                if providee in self.recipecaches[mc].preferred and self.recipecaches[mc].preferred[providee] != provider:
                    providerlog.error("conflicting preferences for %s: both %s and %s specified", providee, provider, self.recipecaches[mc].preferred[providee])
                self.recipecaches[mc].preferred[providee] = provider
cooker.py 文件源码 项目:isar 作者: ilbers 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def matchFile(self, buildfile):
        """
        Find the .bb file which matches the expression in 'buildfile'.
        Raise an error if multiple files
        """
        matches = self.matchFiles(buildfile)
        if len(matches) != 1:
            if matches:
                msg = "Unable to match '%s' to a specific recipe file - %s matches found:" % (buildfile, len(matches))
                if matches:
                    for f in matches:
                        msg += "\n    %s" % f
                parselog.error(msg)
            else:
                parselog.error("Unable to find any recipe file matching '%s'" % buildfile)
            raise NoSpecificMatch
        return matches[0]
lex.py 文件源码 项目:isar 作者: ilbers 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self):
        self.lexre = None             # Master regular expression. This is a list of
                                      # tuples (re,findex) where re is a compiled
                                      # regular expression and findex is a list
                                      # mapping regex group numbers to rules
        self.lexretext = None         # Current regular expression strings
        self.lexstatere = {}          # Dictionary mapping lexer states to master regexs
        self.lexstateretext = {}      # Dictionary mapping lexer states to regex strings
        self.lexstaterenames = {}     # Dictionary mapping lexer states to symbol names
        self.lexstate = "INITIAL"     # Current lexer state
        self.lexstatestack = []       # Stack of lexer states
        self.lexstateinfo = None      # State information
        self.lexstateignore = {}      # Dictionary of ignored characters for each state
        self.lexstateerrorf = {}      # Dictionary of error functions for each state
        self.lexreflags = 0           # Optional re compile flags
        self.lexdata = None           # Actual input data (as a string)
        self.lexpos = 0               # Current position in input text
        self.lexlen = 0               # Length of the input text
        self.lexerrorf = None         # Error rule (if any)
        self.lextokens = None         # List of valid tokens
        self.lexignore = ""           # Ignored characters
        self.lexliterals = ""         # Literal characters that can be passed through
        self.lexmodule = None         # Module
        self.lineno = 1               # Current line number
        self.lexoptimize = 0          # Optimized mode
lex.py 文件源码 项目:isar 作者: ilbers 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_tokens(self):
        tokens = self.ldict.get("tokens",None)
        if not tokens:
            self.log.error("No token list is defined")
            self.error = 1
            return

        if not isinstance(tokens,(list, tuple)):
            self.log.error("tokens must be a list or tuple")
            self.error = 1
            return

        if not tokens:
            self.log.error("tokens is empty")
            self.error = 1
            return

        self.tokens = tokens

    # Validate the tokens
parse.py 文件源码 项目:hammer 作者: ucb-bar 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def _match_re(self):
        if self.__match_re is None:
            expression = '^%s$' % self._expression
            try:
                self.__match_re = re.compile(expression,
                    re.IGNORECASE | re.DOTALL)
            except AssertionError:
                # access error through sys to keep py3k and backward compat
                e = str(sys.exc_info()[1])
                if e.endswith('this version only supports 100 named groups'):
                    raise TooManyFields('sorry, you are attempting to parse '
                        'too many complex fields')
            except re.error:
                raise NotImplementedError("Group names (e.g. (?P<name>) can "
                    "cause failure, as they are not escaped properly: '%s'" %
                    expression)
        return self.__match_re
SearchEngine.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def getprog(self):
        pat = self.getpat()
        if not pat:
            self.report_error(pat, "Empty regular expression")
            return None
        pat = self.getcookedpat()
        flags = 0
        if not self.iscase():
            flags = flags | re.IGNORECASE
        try:
            prog = re.compile(pat, flags)
        except re.error as what:
            try:
                msg, col = what
            except:
                msg = str(what)
                col = -1
            self.report_error(pat, msg, col)
            return None
        return prog
emojiutil.py 文件源码 项目:Python 作者: Guzi219 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def remove_emoji(desstr,restr=''):
    try:
        highpoints = re.compile(u'([\U00002600-\U000027BF])|([\U0001f300-\U0001f64F])|([\U0001f680-\U0001f6FF])')
        print 'remove emoji now.'
    except re.error:
        print 'failed to remove emoji.'
        highpoints = re.compile(u'([\u2600-\u27BF])|([\uD83C][\uDF00-\uDFFF])|([\uD83D][\uDC00-\uDE4F])|([\uD83D][\uDE80-\uDEFF])')
        # mytext = u'<some string containing 4-byte chars>'
        desstr = highpoints.sub(u'\u25FD', desstr)
    return desstr
emojiutil.py 文件源码 项目:Python 作者: Guzi219 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def remove_define_emoji(desstr,restr=''):
    try:
         co = re.compile(u'&#x1f60c;')
         print 'remove define emoji only.'
    except Exception, e:
        print 'error ===='
        print e
    return co.sub(restr,desstr)
stone_validators.py 文件源码 项目:DropboxConnect 作者: raguay 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, message, parent=None):
        """
        Args:
            message (str): Error message detailing validation failure.
            parent (str): Adds the parent as the closest reference point for
                the error. Use :meth:`add_parent` to add more.
        """
        super(ValidationError, self).__init__(message)
        self.message = message
        self._parents = []
        if parent:
            self._parents.append(parent)
stone_validators.py 文件源码 项目:DropboxConnect 作者: raguay 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __str__(self):
        """
        Returns:
            str: A descriptive message of the validation error that may also
                include the path to the validator that failed.
        """
        if self._parents:
            return '{}: {}'.format('.'.join(self._parents[::-1]), self.message)
        else:
            return self.message
stone_validators.py 文件源码 项目:DropboxConnect 作者: raguay 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __repr__(self):
        # Not a perfect repr, but includes the error location information.
        return 'ValidationError(%r)' % six.text_type(self)
stone_validators.py 文件源码 项目:DropboxConnect 作者: raguay 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, min_length=None, max_length=None, pattern=None):
        if min_length is not None:
            assert isinstance(min_length, numbers.Integral), \
                'min_length must be an integral number'
            assert min_length >= 0, 'min_length must be >= 0'
        if max_length is not None:
            assert isinstance(max_length, numbers.Integral), \
                'max_length must be an integral number'
            assert max_length > 0, 'max_length must be > 0'
        if min_length and max_length:
            assert max_length >= min_length, 'max_length must be >= min_length'
        if pattern is not None:
            assert isinstance(pattern, six.string_types), \
                'pattern must be a string'

        self.min_length = min_length
        self.max_length = max_length
        self.pattern = pattern
        self.pattern_re = None

        if pattern:
            try:
                self.pattern_re = re.compile(r"\A(?:" + pattern + r")\Z")
            except re.error as e:
                raise AssertionError('Regex {!r} failed: {}'.format(
                    pattern, e.args[0]))
regex.py 文件源码 项目:mongodb-monitoring 作者: jruaux 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def try_compile(self):
        """Compile this :class:`Regex` as a Python regular expression.

        .. warning::
           Python regular expressions use a different syntax and different
           set of flags than MongoDB, which uses `PCRE`_. A regular
           expression retrieved from the server may not compile in
           Python, or may match a different set of strings in Python than
           when used in a MongoDB query. :meth:`try_compile()` may raise
           :exc:`re.error`.

        .. _PCRE: http://www.pcre.org/
        """
        return re.compile(self.pattern, self.flags)


问题


面经


文章

微信
公众号

扫码关注公众号