當前位置: 首頁>>代碼示例>>Python>>正文


Python lexers.SqlLexer方法代碼示例

本文整理匯總了Python中pygments.lexers.SqlLexer方法的典型用法代碼示例。如果您正苦於以下問題:Python lexers.SqlLexer方法的具體用法?Python lexers.SqlLexer怎麽用?Python lexers.SqlLexer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pygments.lexers的用法示例。


在下文中一共展示了lexers.SqlLexer方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_attr_renderer

# 需要導入模塊: from pygments import lexers [as 別名]
# 或者: from pygments.lexers import SqlLexer [as 別名]
def get_attr_renderer():
    """Return Dictionary containing different Pygements Lexers for Rendering & Highlighting"""
    return {
        'bash_command': lambda x: render(x, lexers.BashLexer),
        'hql': lambda x: render(x, lexers.SqlLexer),
        'sql': lambda x: render(x, lexers.SqlLexer),
        'doc': lambda x: render(x, lexers.TextLexer),
        'doc_json': lambda x: render(x, lexers.JsonLexer),
        'doc_rst': lambda x: render(x, lexers.RstLexer),
        'doc_yaml': lambda x: render(x, lexers.YamlLexer),
        'doc_md': wrapped_markdown,
        'python_callable': lambda x: render(get_python_source(x), lexers.PythonLexer),
    } 
開發者ID:apache,項目名稱:airflow,代碼行數:15,代碼來源:utils.py

示例2: format_sql

# 需要導入模塊: from pygments import lexers [as 別名]
# 或者: from pygments.lexers import SqlLexer [as 別名]
def format_sql(query):
    if not query:
        return ""
    sql_lexer = SqlLexer()
    html_formatter = HtmlFormatter()
    reindent = len(query) > 80
    query = sqlparse.format(query, reindent=reindent, keyword_case='upper')
    return highlight(query, sql_lexer, html_formatter) 
開發者ID:zentralopensource,項目名稱:zentral,代碼行數:10,代碼來源:sql.py

示例3: _format_sql

# 需要導入模塊: from pygments import lexers [as 別名]
# 或者: from pygments.lexers import SqlLexer [as 別名]
def _format_sql(sql, data, format='html'):
    popts = {}
    if data.get('remove_comments'):
        popts['strip_comments'] = True
    if data.get('keyword_case', 'undefined') not in ('undefined', ''):
        popts['keyword_case'] = data.get('keyword_case')
    if data.get('identifier_case', 'undefined') not in ('undefined', ''):
        popts['identifier_case'] = data.get('identifier_case')
    if data.get('n_indents', None) is not None:
        val = data.get('n_indents')
        try:
            popts['indent_width'] = max(1, min(1000, int(val)))
            popts['reindent'] = True
        except (ValueError, TypeError):
            pass
    if (not 'indent_width' in popts and
        data.get('reindent', '').lower() in ('1', 'true', 't')):
        popts['indent_width'] = 2
        popts['reindent'] = True
    if data.get('output_format', None) is not None:
        popts['output_format'] = data.get('output_format')
    logging.debug('Format: %s, POPTS: %r', format, popts)
    logging.debug(sql)
    sql = sqlparse.format(sql, **popts)
    if format in ('html', 'json'):
        if data.get('highlight', False):
            if popts['output_format'] == 'python':
                lexer = PythonLexer()
            elif popts['output_format'] == 'php':
                lexer = PhpLexer()
            else:
                lexer = SqlLexer()
            sql = highlight(sql, lexer, HtmlFormatter())
        else:
            sql = ('<textarea class="resizable" '
                   'style="height: 350px; margin-top: 1em;">%s</textarea>'
                   % sql)
    return sql 
開發者ID:sriniiyer,項目名稱:codenn,代碼行數:40,代碼來源:legacy.py

示例4: dump_query

# 需要導入模塊: from pygments import lexers [as 別名]
# 或者: from pygments.lexers import SqlLexer [as 別名]
def dump_query(query, filter_columns=None):
    """
    Small helper function to dump a SqlAlchemy SQL query + parameters.
    :param query:
    :param filter_columns:
    :return:
    """
    # Number of rows to display.
    num_rows = 5

    if hasattr(query, "statement"):
        sql_query = str(
            query.statement.compile(dialect=None,
                                    compile_kwargs={"literal_binds": True}))
    else:
        sql_query = str(query)

    formatted_sql_query = sqlparse.format(sql_query,
                                          reindent=True,
                                          keyword_case="upper")
    highlighted_sql_query = highlight(formatted_sql_query, SqlLexer(),
                                      TerminalFormatter())
    print("Query:")
    print(f"{'-' * 15}\n{highlighted_sql_query}{'-' * 15}")

    df = pd.read_sql(query.statement, CVE_DB_ENGINE)
    if filter_columns:
        df = df[filter_columns]

    print(f"Results: {df.shape[0]}; showing first {num_rows}:")
    print(df.head(num_rows)) 
開發者ID:google,項目名稱:vulncode-db,代碼行數:33,代碼來源:crawl_patches.py

示例5: __init__

# 需要導入模塊: from pygments import lexers [as 別名]
# 或者: from pygments.lexers import SqlLexer [as 別名]
def __init__(self, *args, **kwargs):
        self.highlight = kwargs.pop('highlight', True)
        self.style = kwargs.pop('style', 'default')

        self.parse = kwargs.pop('parse', True)
        self.reindent = kwargs.pop('reindent', True)
        self.keyword_case = kwargs.pop('keyword_case', 'upper')

        self._lexer = SqlLexer()
        self._formatter = Terminal256Formatter(style=self.style)

        super(SqlFormatter, self).__init__(*args, **kwargs) 
開發者ID:henriquebastos,項目名稱:sqlformatter,代碼行數:14,代碼來源:sqlformatter.py

示例6: main

# 需要導入模塊: from pygments import lexers [as 別名]
# 或者: from pygments.lexers import SqlLexer [as 別名]
def main():
    history = FileHistory(os.path.expanduser('~/.gsheetsdb_history'))

    arguments = docopt(__doc__, version=__version__.__version__)

    auth = {
        'service_account_file': arguments['--service-account-file'],
        'subject': arguments['--subject'],
    }
    credentials = get_credentials_from_auth(**auth)
    connection = connect(credentials)
    headers = int(arguments['--headers'])
    cursor = connection.cursor()

    lexer = PygmentsLexer(SqlLexer)
    words = keywords + aggregate_functions + scalar_functions
    completer = WordCompleter(words, ignore_case=True)
    style = style_from_pygments_cls(get_style_by_name('manni'))

    while True:
        try:
            query = prompt(
                'sql> ', lexer=lexer, completer=completer,
                style=style, history=history)
        except (EOFError, KeyboardInterrupt):
            break  # Control-D pressed.

        # run query
        query = query.strip('; ').replace('%', '%%')
        if query:
            try:
                result = cursor.execute(query, headers=headers)
            except Exception as e:
                if arguments['--raise']:
                    raise
                print(e)
                continue

            columns = [t[0] for t in cursor.description or []]
            print(tabulate(result, headers=columns))

    print('See ya!') 
開發者ID:betodealmeida,項目名稱:gsheets-db-api,代碼行數:44,代碼來源:console.py


注:本文中的pygments.lexers.SqlLexer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。