/usr/lib/python3/dist-packages/flake8/util.py is in python3-flake8 2.5.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | # -*- coding: utf-8 -*-
import os
try:
import ast
iter_child_nodes = ast.iter_child_nodes
except ImportError: # Python 2.5
import _ast as ast
if 'decorator_list' not in ast.ClassDef._fields:
# Patch the missing attribute 'decorator_list'
ast.ClassDef.decorator_list = ()
ast.FunctionDef.decorator_list = property(lambda s: s.decorators)
def iter_child_nodes(node):
"""
Yield all direct child nodes of *node*, that is, all fields that
are nodes and all items of fields that are lists of nodes.
"""
if not node._fields:
return
for name in node._fields:
field = getattr(node, name, None)
if isinstance(field, ast.AST):
yield field
elif isinstance(field, list):
for item in field:
if isinstance(item, ast.AST):
yield item
class OrderedSet(list):
"""List without duplicates."""
__slots__ = ()
def add(self, value):
if value not in self:
self.append(value)
def is_windows():
"""Determine if the system is Windows."""
return os.name == 'nt'
def is_using_stdin(paths):
"""Determine if we're running checks on stdin."""
return '-' in paths
def warn_when_using_jobs(options):
return (options.verbose and options.jobs and options.jobs.isdigit() and
int(options.jobs) > 1)
def force_disable_jobs(styleguide):
return is_windows() or is_using_stdin(styleguide.paths)
def option_normalizer(value):
if str(value).upper() in ('1', 'T', 'TRUE', 'ON'):
value = True
if str(value).upper() in ('0', 'F', 'FALSE', 'OFF'):
value = False
if isinstance(value, str):
value = [opt.strip() for opt in value.split(',') if opt.strip()]
return value
|