當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。