当前位置: 首页>>代码示例>>Python>>正文


Python tokens.Error方法代码示例

本文整理汇总了Python中sqlparse.tokens.Error方法的典型用法代码示例。如果您正苦于以下问题:Python tokens.Error方法的具体用法?Python tokens.Error怎么用?Python tokens.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlparse.tokens的用法示例。


在下文中一共展示了tokens.Error方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_partial_identifier

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Error [as 别名]
def parse_partial_identifier(word):
    """Attempt to parse a (partially typed) word as an identifier

    word may include a schema qualification, like `schema_name.partial_name`
    or `schema_name.` There may also be unclosed quotation marks, like
    `"schema`, or `schema."partial_name`

    :param word: string representing a (partially complete) identifier
    :return: sqlparse.sql.Identifier, or None
    """

    p = sqlparse.parse(word)[0]
    n_tok = len(p.tokens)
    if n_tok == 1 and isinstance(p.tokens[0], Identifier):
        return p.tokens[0]
    elif p.token_next_by(m=(Error, '"'))[1]:
        # An unmatched double quote, e.g. '"foo', 'foo."', or 'foo."bar'
        # Close the double quote, then reparse
        return parse_partial_identifier(word + '"')
    else:
        return None 
开发者ID:dbcli,项目名称:pgcli,代码行数:23,代码来源:utils.py

示例2: parse_partial_identifier

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Error [as 别名]
def parse_partial_identifier(word):
    """Attempt to parse a (partially typed) word as an identifier

    word may include a schema qualification, like `schema_name.partial_name`
    or `schema_name.` There may also be unclosed quotation marks, like
    `"schema`, or `schema."partial_name`

    :param word: string representing a (partially complete) identifier
    :return: sqlparse.sql.Identifier, or None
    """

    p = sqlparse.parse(word)[0]
    n_tok = len(p.tokens)
    if n_tok == 1 and isinstance(p.tokens[0], Identifier):
        return p.tokens[0]
    if p.token_next_by(m=(Error, '"'))[1]:
        # An unmatched double quote, e.g. '"foo', 'foo."', or 'foo."bar'
        # Close the double quote, then reparse
        return parse_partial_identifier(word + '"')
    return None 
开发者ID:dbcli,项目名称:mssql-cli,代码行数:22,代码来源:utils.py

示例3: _parsed_is_open_quote

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Error [as 别名]
def _parsed_is_open_quote(parsed):
    # Look for unmatched single quotes, or unmatched dollar sign quotes
    return any(tok.match(Token.Error, ("'", "$")) for tok in parsed.flatten()) 
开发者ID:dbcli,项目名称:pgcli,代码行数:5,代码来源:utils.py

示例4: _parsed_is_open_quote

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Error [as 别名]
def _parsed_is_open_quote(parsed):
    # Look for unmatched single quotes, or unmatched dollar sign quotes
    return any(tok.match(Token.Error, ("'", '"', "$")) for tok in parsed.flatten()) 
开发者ID:dbcli,项目名称:mssql-cli,代码行数:5,代码来源:utils.py

示例5: get_tokens

# 需要导入模块: from sqlparse import tokens [as 别名]
# 或者: from sqlparse.tokens import Error [as 别名]
def get_tokens(text, encoding=None):
        """
        Return an iterable of (tokentype, value) pairs generated from
        `text`. If `unfiltered` is set to `True`, the filtering mechanism
        is bypassed even if filters are defined.

        Also preprocess the text, i.e. expand tabs and strip it if
        wanted and applies registered filters.

        Split ``text`` into (tokentype, text) pairs.

        ``stack`` is the inital stack (default: ``['root']``)
        """
        if isinstance(text, file_types):
            text = text.read()

        if isinstance(text, text_type):
            pass
        elif isinstance(text, bytes_type):
            if encoding:
                text = text.decode(encoding)
            else:
                try:
                    text = text.decode('utf-8')
                except UnicodeDecodeError:
                    text = text.decode('unicode-escape')
        else:
            raise TypeError(u"Expected text or file-like object, got {!r}".
                            format(type(text)))

        iterable = enumerate(text)
        for pos, char in iterable:
            for rexmatch, action in SQL_REGEX:
                m = rexmatch(text, pos)

                if not m:
                    continue
                elif isinstance(action, tokens._TokenType):
                    yield action, m.group()
                elif callable(action):
                    yield action(m.group())

                consume(iterable, m.end() - pos - 1)
                break
            else:
                yield tokens.Error, char 
开发者ID:mtxr,项目名称:SublimeText-SQLTools,代码行数:48,代码来源:lexer.py


注:本文中的sqlparse.tokens.Error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。