sys.version_info.major

Here are the examples of the python api sys.version_info.major taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

153 Examples 7

Example 151

Project: mastool Source File: practices.py
@h.labeled(code='M004',
           msg='assigning to built-in',
           solution="change symbol name to something else")
def find_assign_to_builtin(node):
    """Finds assigning to built-ins"""

    # The list of forbidden builtins is constant and not determined at
    # runtime anyomre. The reason behind this change is that certain
    # modules (like `gettext` for instance) would mess with the
    # builtins module making this practice yield false positives.
    if sys.version_info.major == 3:
        builtins = {"abs", "all", "any", "ascii", "bin", "bool",
                    "bytearray", "bytes", "callable", "chr",
                    "classmethod", "compile", "complex", "delattr",
                    "dict", "dir", "divmod", "enumerate", "eval",
                    "exec", "filter", "float", "format", "frozenset",
                    "getattr", "globals", "hasattr", "hash", "help",
                    "hex", "id", "__import__", "input", "int",
                    "isinstance", "issubclass", "iter", "len", "list",
                    "locals", "map", "max", "memoryview", "min",
                    "next", "object", "oct", "open", "ord", "pow",
                    "print", "property", "range", "repr", "reversed",
                    "round", "set", "setattr", "slice", "sorted",
                    "staticmethod", "str", "sum", "super", "tuple",
                    "type", "vars", "zip"}
    else:
        builtins = {"abs", "all", "any", "basestring", "bin", "bool",
                    "bytearray", "callable", "chr", "classmethod",
                    "cmp", "compile", "complex", "delattr", "dict",
                    "dir", "divmod", "enumerate", "eval", "execfile",
                    "file", "filter", "float", "format", "frozenset",
                    "getattr", "globals", "hasattr", "hash", "help",
                    "hex", "id", "import__", "input", "int",
                    "isinstance", "issubclass", "iter", "len", "list",
                    "locals", "long", "map", "max", "memoryview",
                    "min", "next", "object", "oct", "open", "ord",
                    "pow", "print", "property", "range", "raw_input",
                    "reduce", "reload", "repr", "reversed", "round",
                    "set", "setattr", "slice", "sorted",
                    "staticmethod", "str", "sum", "super", "tuple",
                    "type", "unichr", "unicode", "vars", "xrange",
                    "zip"}

    return (
        isinstance(node, ast.Assign)
        and len(builtins & set(h.target_names(node.targets))) > 0
    )

Example 152

Project: bandit Source File: general_hardcoded_password.py
@test.checks('FunctionDef')
@test.test_id('B107')
def hardcoded_password_default(context):
    """**B107: Test for use of hard-coded password argument defaults**

    The use of hard-coded passwords increases the possibility of password
    guessing tremendously. This plugin test looks for all function definitions
    that specify a default string literal for some argument. It checks that
    the argument does not look like a password.

    Variables are considered to look like a password if they have match any one
    of:

    - "password"
    - "pass"
    - "passwd"
    - "pwd"
    - "secret"
    - "token"
    - "secrete"

    Note: this can be noisy and may generate false positives.

    **Config Options:**

    None

    :Example:

    .. code-block:: none

        >> Issue: [B107:hardcoded_password_default] Possible hardcoded
        password: 'Admin'
           Severity: Low   Confidence: Medium
           Location: ./examples/hardcoded-passwords.py:1

        1    def someFunction(user, password="Admin"):
        2      print("Hi " + user)

    .. seealso::

        - https://www.owasp.org/index.php/Use_of_hard-coded_password

    .. versionadded:: 0.9.0

    """
    # looks for "def function(candidate='some_string')"

    # this pads the list of default values with "None" if nothing is given
    defs = [None] * (len(context.node.args.args) -
                     len(context.node.args.defaults))
    defs.extend(context.node.args.defaults)

    # go through all (param, value)s and look for candidates
    for key, val in zip(context.node.args.args, defs):
        if isinstance(key, ast.Name):
            check = key.arg if sys.version_info.major > 2 else key.id  # Py3
            if isinstance(val, ast.Str) and check in candidates:
                return _report(val.s)

Example 153

Project: OpenTrader Source File: tabview.py
Function: view
def view(data, enc=None, start_pos=(0, 0), column_width=20, column_gap=2,
         trunc_char='…', column_widths=None, search_str=None,
         double_width=False, delimiter=None, orient='columns'):
    """The curses.wrapper passes stdscr as the first argument to main +
    passes to main any other arguments passed to wrapper. Initializes
    and then puts screen back in a normal state after closing or
    exceptions.

    Args:
        data: data (filename, file, dict, list of lists, tuple of tuples,
              numpy ndarray or pandas Series/DataFrame/Panel).
              Should be normalized to equal row lengths
        enc: encoding for file/data
        start_pos: initial file position. Either a single integer for just y
            (row) position, or tuple/list (y,x)
        column_width: 'max' (max width for the column),
                      'mode' (uses arithmetic mode to compute width), or
                      int x (x characters wide). Default is 'mode'
        column_gap: gap between columns
        column_widths: list of widths for each column [len1, len2, lenxxx...]
        trunc_char: character to indicate continuation of too-long columns
        search_str: string to search for
        double_width: boolean indicating whether double-width characters
                      should be handled (defaults to False for large files)
        delimiter: CSV delimiter. Typically needed only if the automatic
                   delimiter detection doesn't work. None => automatic

    """
    if sys.version_info.major < 3:
        try:
            lc_all = locale.getlocale(locale.LC_ALL)
            locale.setlocale(locale.LC_ALL, '')
        except:
            lc_all = None
    else:
        lc_all = None
    try:
        buf = None
        while True:
            try:
                if isinstance(data, basestring):
                    with open(data, 'rb') as fd:
                        new_data = fd.readlines()
                elif isinstance(data, (io.IOBase, file)):
                    new_data = data.readlines()
                else:
                    new_data = data

                if input_type(new_data):
                    buf = process_data(new_data, enc, delimiter, orient=orient)
                elif buf:
                    # cannot reload the file
                    pass
                else:
                    # cannot read the file
                    return 1

                curses.wrapper(main, buf,
                               start_pos=start_pos,
                               column_width=column_width,
                               column_gap=column_gap,
                               trunc_char=trunc_char,
                               column_widths=column_widths,
                               search_str=search_str,
                               double_width=double_width)

            except (QuitException, KeyboardInterrupt):
                return 0
            except ReloadException as e:
                start_pos = e.start_pos
                column_width = e.column_width_mode
                column_gap = e.column_gap
                column_widths = e.column_widths
                search_str = e.search_str
                continue
    finally:
        if lc_all is not None:
            locale.setlocale(locale.LC_ALL, lc_all)
See More Examples - Go to Next Page
Page 1 Page 2 Page 3 Page 4 Selected