<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''It provides the basic bricks to build SQLs.

The classes or functions you may use frequently:

.. autosummary ::
    raw
    default
    star
    param
    or_

It is designed for standard SQL and tested in PostgreSQL. If your database uses
non-standard SQL, such as MySQL, you may need to customize and override the
following functions.

.. autosummary ::
    escape
    format_param
    stringify_bool
    delimit_identifier
    escape_identifier

.. note::

    For MySQL, an official patch is here - :doc:`/mysql`.

If you need to customize more, the following classes may help you.

.. autosummary ::
    Clause
    Statement
    Query

.. versionchanged:: 0.1.6
    It is rewritten and totally different from old version.
'''

__all__ = [
    'escape', 'format_param', 'stringify_bool',
    'delimit_identifier', 'escape_identifier',
    'raw', 'param', 'default', '___', 'star',
    'qualifier', 'paren', 'value',
    'OptionError', 'allowed_options', 'identifier',
    'joiner',
    'concat_by_comma', 'concat_by_and', 'concat_by_space', 'concat_by_or',
    'OperatorError', 'allowed_operators',
    'build_where', 'build_set', 'build_on',
    'or_',
    'Clause', 'Statement', 'Query',
]

from functools import wraps
from datetime import datetime, date, time

def escape(s):
    '''It escapes the value.

    By default, it just replaces ``'`` (single-quote) with ``''`` (two single-quotes).

    It aims at avoiding SQL injection. Here are some examples:

    >>> tmpl = "select * from person where person_id = '%s';"
    >>> evil_value = "' or true; -- "

    >>> print tmpl % evil_value
    select * from person where person_id = '' or true; -- ';

    >>> print tmpl % escape(evil_value)
    select * from person where person_id = '\'' or true; -- ';

    .. warning ::
        If you don't use utf-8 for your connection, such as big5, gbk, please<commit_msg>fixed missing unicode in py3<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''It provides the basic bricks to build SQLs.

The classes or functions you may use frequently:

.. autosummary ::
    raw
    default
    star
    param
    or_

It is designed for standard SQL and tested in PostgreSQL. If your database uses
non-standard SQL, such as MySQL, you may need to customize and override the
following functions.

.. autosummary ::
    escape
    format_param
    stringify_bool
    delimit_identifier
    escape_identifier

.. note::

    For MySQL, an official patch is here - :doc:`/mysql`.

If you need to customize more, the following classes may help you.

.. autosummary ::
    Clause
    Statement
    Query

.. versionchanged:: 0.1.6
    It is rewritten and totally different from old version.
'''

__all__ = [
    'escape', 'format_param', 'stringify_bool',
    'delimit_identifier', 'escape_identifier',
    'raw', 'param', 'default', '___', 'star',
    'qualifier', 'paren', 'value',
    'OptionError', 'allowed_options', 'identifier',
    'joiner',
    'concat_by_comma', 'concat_by_and', 'concat_by_space', 'concat_by_or',
    'OperatorError', 'allowed_operators',
    'build_where', 'build_set', 'build_on',
    'or_',
    'Clause', 'Statement', 'Query',
]

import sys
if sys.version_info >= (3,):
    unicode = str

from functools import wraps
from datetime import datetime, date, time

def escape(s):
    '''It escapes the value.

    By default, it just replaces ``'`` (single-quote) with ``''`` (two single-quotes).

    It aims at avoiding SQL injection. Here are some examples:

    >>> tmpl = "select * from person where person_id = '%s';"
    >>> evil_value = "' or true; -- "

    >>> print tmpl % evil_value
    select * from person where person_id = '' or true; -- ';

    >>> print tmpl % escape(evil_value)
    select * from person where person_id = '\'' or true; -- ';

    .. warning ::
        If you don't use utf-8 for your connection, such as big5, gbk, please
{'fraction_non_alphanumeric': 0.12715298885511653, 'fraction_numerical': 0.0035460992907801418, 'mean_word_length': 3.1656118143459917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '860703', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1200, 'n_words': 422}