Linux premium155.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
LiteSpeed
: 162.0.235.200 | : 3.144.106.207
Cant Read [ /etc/named.conf ]
7.4.33
varifktc
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
opt /
cloudlinux /
venv /
lib /
python3.11 /
site-packages /
[ HOME SHELL ]
Name
Size
Permission
Action
GitPython-3.1.32.dist-info
[ DIR ]
drwxr-xr-x
Jinja2-3.0.3.dist-info
[ DIR ]
drwxr-xr-x
Mako-1.2.4.dist-info
[ DIR ]
drwxr-xr-x
MarkupSafe-2.1.3.dist-info
[ DIR ]
drwxr-xr-x
PyJWT-2.8.0.dist-info
[ DIR ]
drwxr-xr-x
PyMySQL-1.1.0.dist-info
[ DIR ]
drwxr-xr-x
PyVirtualDisplay-3.0.dist-info
[ DIR ]
drwxr-xr-x
PyYAML-6.0.1.dist-info
[ DIR ]
drwxr-xr-x
SQLAlchemy-1.3.24.dist-info
[ DIR ]
drwxr-xr-x
__pycache__
[ DIR ]
drwxr-xr-x
_distutils_hack
[ DIR ]
drwxr-xr-x
_pytest
[ DIR ]
drwxr-xr-x
_yaml
[ DIR ]
drwxr-xr-x
aiohttp
[ DIR ]
drwxr-xr-x
aiohttp-3.9.2.dist-info
[ DIR ]
drwxr-xr-x
aiosignal
[ DIR ]
drwxr-xr-x
aiosignal-1.3.1.dist-info
[ DIR ]
drwxr-xr-x
alembic
[ DIR ]
drwxr-xr-x
alembic-1.11.1.dist-info
[ DIR ]
drwxr-xr-x
annotated_types
[ DIR ]
drwxr-xr-x
annotated_types-0.6.0.dist-inf...
[ DIR ]
drwxr-xr-x
astroid
[ DIR ]
drwxr-xr-x
astroid-2.15.6.dist-info
[ DIR ]
drwxr-xr-x
async_timeout
[ DIR ]
drwxr-xr-x
async_timeout-4.0.3.dist-info
[ DIR ]
drwxr-xr-x
attr
[ DIR ]
drwxr-xr-x
attrs
[ DIR ]
drwxr-xr-x
attrs-23.1.0.dist-info
[ DIR ]
drwxr-xr-x
certifi
[ DIR ]
drwxr-xr-x
certifi-2023.7.22.dist-info
[ DIR ]
drwxr-xr-x
cffi
[ DIR ]
drwxr-xr-x
cffi-1.15.1.dist-info
[ DIR ]
drwxr-xr-x
chardet
[ DIR ]
drwxr-xr-x
chardet-5.2.0.dist-info
[ DIR ]
drwxr-xr-x
charset_normalizer
[ DIR ]
drwxr-xr-x
charset_normalizer-2.1.1.dist-...
[ DIR ]
drwxr-xr-x
cl_dom_collector
[ DIR ]
drwxr-xr-x
clcagefslib
[ DIR ]
drwxr-xr-x
clcommon
[ DIR ]
drwxr-xr-x
clconfig
[ DIR ]
drwxr-xr-x
clconfigure
[ DIR ]
drwxr-xr-x
cldashboard
[ DIR ]
drwxr-xr-x
clevents
[ DIR ]
drwxr-xr-x
clflags
[ DIR ]
drwxr-xr-x
cllicense
[ DIR ]
drwxr-xr-x
cllimits
[ DIR ]
drwxr-xr-x
cllimits_validator
[ DIR ]
drwxr-xr-x
cllimitslib_v2
[ DIR ]
drwxr-xr-x
cllvectl
[ DIR ]
drwxr-xr-x
clpackages
[ DIR ]
drwxr-xr-x
clquota
[ DIR ]
drwxr-xr-x
clselect
[ DIR ]
drwxr-xr-x
clselector
[ DIR ]
drwxr-xr-x
clsentry
[ DIR ]
drwxr-xr-x
clsummary
[ DIR ]
drwxr-xr-x
clveconfig
[ DIR ]
drwxr-xr-x
clwizard
[ DIR ]
drwxr-xr-x
colorama
[ DIR ]
drwxr-xr-x
colorama-0.4.6.dist-info
[ DIR ]
drwxr-xr-x
contextlib2
[ DIR ]
drwxr-xr-x
contextlib2-21.6.0.dist-info
[ DIR ]
drwxr-xr-x
coverage
[ DIR ]
drwxr-xr-x
coverage-7.2.7.dist-info
[ DIR ]
drwxr-xr-x
cryptography
[ DIR ]
drwxr-xr-x
cryptography-41.0.2.dist-info
[ DIR ]
drwxr-xr-x
ddt-1.4.4.dist-info
[ DIR ]
drwxr-xr-x
dill
[ DIR ]
drwxr-xr-x
dill-0.3.7.dist-info
[ DIR ]
drwxr-xr-x
distlib
[ DIR ]
drwxr-xr-x
distlib-0.3.8.dist-info
[ DIR ]
drwxr-xr-x
docopt-0.6.2.dist-info
[ DIR ]
drwxr-xr-x
dodgy
[ DIR ]
drwxr-xr-x
dodgy-0.2.1.dist-info
[ DIR ]
drwxr-xr-x
filelock
[ DIR ]
drwxr-xr-x
filelock-3.13.1.dist-info
[ DIR ]
drwxr-xr-x
flake8
[ DIR ]
drwxr-xr-x
flake8-5.0.4.dist-info
[ DIR ]
drwxr-xr-x
flake8_polyfill
[ DIR ]
drwxr-xr-x
flake8_polyfill-1.0.2.dist-inf...
[ DIR ]
drwxr-xr-x
frozenlist
[ DIR ]
drwxr-xr-x
frozenlist-1.4.0.dist-info
[ DIR ]
drwxr-xr-x
future
[ DIR ]
drwxr-xr-x
future-0.18.3.dist-info
[ DIR ]
drwxr-xr-x
git
[ DIR ]
drwxr-xr-x
gitdb
[ DIR ]
drwxr-xr-x
gitdb-4.0.10.dist-info
[ DIR ]
drwxr-xr-x
guppy
[ DIR ]
drwxr-xr-x
guppy3-3.1.3.dist-info
[ DIR ]
drwxr-xr-x
hc_json_rpc_client
[ DIR ]
drwxr-xr-x
hc_json_rpc_client-1.0.1.dist-...
[ DIR ]
drwxr-xr-x
idna
[ DIR ]
drwxr-xr-x
idna-3.4.dist-info
[ DIR ]
drwxr-xr-x
iniconfig
[ DIR ]
drwxr-xr-x
iniconfig-2.0.0.dist-info
[ DIR ]
drwxr-xr-x
isort
[ DIR ]
drwxr-xr-x
isort-5.12.0.dist-info
[ DIR ]
drwxr-xr-x
jinja2
[ DIR ]
drwxr-xr-x
jsonschema
[ DIR ]
drwxr-xr-x
jsonschema-3.2.0.dist-info
[ DIR ]
drwxr-xr-x
jwt
[ DIR ]
drwxr-xr-x
lazy_object_proxy
[ DIR ]
drwxr-xr-x
lazy_object_proxy-1.9.0.dist-i...
[ DIR ]
drwxr-xr-x
libfuturize
[ DIR ]
drwxr-xr-x
libpasteurize
[ DIR ]
drwxr-xr-x
lve_stats-2.0.dist-info
[ DIR ]
drwxr-xr-x
lve_utils
[ DIR ]
drwxr-xr-x
lvemanager
[ DIR ]
drwxr-xr-x
lvestats
[ DIR ]
drwxr-xr-x
lxml
[ DIR ]
drwxr-xr-x
lxml-4.9.2.dist-info
[ DIR ]
drwxr-xr-x
mako
[ DIR ]
drwxr-xr-x
markupsafe
[ DIR ]
drwxr-xr-x
mccabe-0.7.0.dist-info
[ DIR ]
drwxr-xr-x
mock
[ DIR ]
drwxr-xr-x
mock-5.1.0.dist-info
[ DIR ]
drwxr-xr-x
multidict
[ DIR ]
drwxr-xr-x
multidict-6.0.4.dist-info
[ DIR ]
drwxr-xr-x
numpy
[ DIR ]
drwxr-xr-x
numpy-1.25.1.dist-info
[ DIR ]
drwxr-xr-x
numpy.libs
[ DIR ]
drwxr-xr-x
packaging
[ DIR ]
drwxr-xr-x
packaging-23.1.dist-info
[ DIR ]
drwxr-xr-x
past
[ DIR ]
drwxr-xr-x
pep8_naming-0.10.0.dist-info
[ DIR ]
drwxr-xr-x
pip
[ DIR ]
drwxr-xr-x
pip-24.1.2.dist-info
[ DIR ]
drwxr-xr-x
pkg_resources
[ DIR ]
drwxr-xr-x
platformdirs
[ DIR ]
drwxr-xr-x
platformdirs-3.11.0.dist-info
[ DIR ]
drwxr-xr-x
pluggy
[ DIR ]
drwxr-xr-x
pluggy-1.2.0.dist-info
[ DIR ]
drwxr-xr-x
prettytable
[ DIR ]
drwxr-xr-x
prettytable-3.8.0.dist-info
[ DIR ]
drwxr-xr-x
prometheus_client
[ DIR ]
drwxr-xr-x
prometheus_client-0.8.0.dist-i...
[ DIR ]
drwxr-xr-x
prospector
[ DIR ]
drwxr-xr-x
prospector-1.10.2.dist-info
[ DIR ]
drwxr-xr-x
psutil
[ DIR ]
drwxr-xr-x
psutil-5.9.5.dist-info
[ DIR ]
drwxr-xr-x
psycopg2
[ DIR ]
drwxr-xr-x
psycopg2_binary-2.9.6.dist-inf...
[ DIR ]
drwxr-xr-x
psycopg2_binary.libs
[ DIR ]
drwxr-xr-x
pycodestyle-2.9.1.dist-info
[ DIR ]
drwxr-xr-x
pycparser
[ DIR ]
drwxr-xr-x
pycparser-2.21.dist-info
[ DIR ]
drwxr-xr-x
pydantic
[ DIR ]
drwxr-xr-x
pydantic-2.4.2.dist-info
[ DIR ]
drwxr-xr-x
pydantic_core
[ DIR ]
drwxr-xr-x
pydantic_core-2.10.1.dist-info
[ DIR ]
drwxr-xr-x
pydocstyle
[ DIR ]
drwxr-xr-x
pydocstyle-6.3.0.dist-info
[ DIR ]
drwxr-xr-x
pyfakefs
[ DIR ]
drwxr-xr-x
pyfakefs-5.2.3.dist-info
[ DIR ]
drwxr-xr-x
pyflakes
[ DIR ]
drwxr-xr-x
pyflakes-2.5.0.dist-info
[ DIR ]
drwxr-xr-x
pylint
[ DIR ]
drwxr-xr-x
pylint-2.17.4.dist-info
[ DIR ]
drwxr-xr-x
pylint_celery
[ DIR ]
drwxr-xr-x
pylint_celery-0.3.dist-info
[ DIR ]
drwxr-xr-x
pylint_django
[ DIR ]
drwxr-xr-x
pylint_django-2.5.3.dist-info
[ DIR ]
drwxr-xr-x
pylint_flask
[ DIR ]
drwxr-xr-x
pylint_flask-0.6.dist-info
[ DIR ]
drwxr-xr-x
pylint_plugin_utils
[ DIR ]
drwxr-xr-x
pylint_plugin_utils-0.7.dist-i...
[ DIR ]
drwxr-xr-x
pylve-2.1-py3.11.egg-info
[ DIR ]
drwxr-xr-x
pymysql
[ DIR ]
drwxr-xr-x
pyparsing
[ DIR ]
drwxr-xr-x
pyparsing-3.0.9.dist-info
[ DIR ]
drwxr-xr-x
pyrsistent
[ DIR ]
drwxr-xr-x
pyrsistent-0.19.3.dist-info
[ DIR ]
drwxr-xr-x
pytest
[ DIR ]
drwxr-xr-x
pytest-7.4.0.dist-info
[ DIR ]
drwxr-xr-x
pytest_subprocess
[ DIR ]
drwxr-xr-x
pytest_subprocess-1.5.0.dist-i...
[ DIR ]
drwxr-xr-x
pyvirtualdisplay
[ DIR ]
drwxr-xr-x
raven
[ DIR ]
drwxr-xr-x
raven-6.10.0.dist-info
[ DIR ]
drwxr-xr-x
requests
[ DIR ]
drwxr-xr-x
requests-2.31.0.dist-info
[ DIR ]
drwxr-xr-x
requirements_detector
[ DIR ]
drwxr-xr-x
requirements_detector-1.2.2.di...
[ DIR ]
drwxr-xr-x
schema-0.7.5.dist-info
[ DIR ]
drwxr-xr-x
semver
[ DIR ]
drwxr-xr-x
semver-3.0.1.dist-info
[ DIR ]
drwxr-xr-x
sentry_sdk
[ DIR ]
drwxr-xr-x
sentry_sdk-1.29.2.dist-info
[ DIR ]
drwxr-xr-x
setoptconf
[ DIR ]
drwxr-xr-x
setoptconf_tmp-0.3.1.dist-info
[ DIR ]
drwxr-xr-x
setuptools
[ DIR ]
drwxr-xr-x
setuptools-70.2.0.dist-info
[ DIR ]
drwxr-xr-x
simplejson
[ DIR ]
drwxr-xr-x
simplejson-3.19.1.dist-info
[ DIR ]
drwxr-xr-x
six-1.16.0.dist-info
[ DIR ]
drwxr-xr-x
smmap
[ DIR ]
drwxr-xr-x
smmap-5.0.0.dist-info
[ DIR ]
drwxr-xr-x
snowballstemmer
[ DIR ]
drwxr-xr-x
snowballstemmer-2.2.0.dist-inf...
[ DIR ]
drwxr-xr-x
sqlalchemy
[ DIR ]
drwxr-xr-x
ssa
[ DIR ]
drwxr-xr-x
svgwrite
[ DIR ]
drwxr-xr-x
svgwrite-1.4.3.dist-info
[ DIR ]
drwxr-xr-x
tap
[ DIR ]
drwxr-xr-x
tap.py-3.1.dist-info
[ DIR ]
drwxr-xr-x
testfixtures
[ DIR ]
drwxr-xr-x
testfixtures-7.1.0.dist-info
[ DIR ]
drwxr-xr-x
toml
[ DIR ]
drwxr-xr-x
toml-0.10.2.dist-info
[ DIR ]
drwxr-xr-x
tomlkit
[ DIR ]
drwxr-xr-x
tomlkit-0.11.8.dist-info
[ DIR ]
drwxr-xr-x
typing_extensions-4.8.0.dist-i...
[ DIR ]
drwxr-xr-x
unshare-0.22.dist-info
[ DIR ]
drwxr-xr-x
urllib3
[ DIR ]
drwxr-xr-x
urllib3-2.0.4.dist-info
[ DIR ]
drwxr-xr-x
vendors_api
[ DIR ]
drwxr-xr-x
virtualenv
[ DIR ]
drwxr-xr-x
virtualenv-20.21.1.dist-info
[ DIR ]
drwxr-xr-x
wcwidth
[ DIR ]
drwxr-xr-x
wcwidth-0.2.6.dist-info
[ DIR ]
drwxr-xr-x
wmt
[ DIR ]
drwxr-xr-x
wrapt
[ DIR ]
drwxr-xr-x
wrapt-1.15.0.dist-info
[ DIR ]
drwxr-xr-x
yaml
[ DIR ]
drwxr-xr-x
yarl
[ DIR ]
drwxr-xr-x
yarl-1.9.2.dist-info
[ DIR ]
drwxr-xr-x
_cffi_backend.cpython-311-x86_...
267.63
KB
-rwxr-xr-x
_pyrsistent_version.py
23
B
-rw-r--r--
cl_proc_hidepid.py
4.53
KB
-rw-r--r--
clcontrollib.py
51.73
KB
-rw-r--r--
cldetectlib.py
18.13
KB
-rw-r--r--
cldiaglib.py
45.57
KB
-rw-r--r--
clhooklib.py
1.27
KB
-rw-r--r--
cli_utils.py
1.66
KB
-rw-r--r--
cllicenselib.py
9.1
KB
-rw-r--r--
clsetuplib.py
4.35
KB
-rw-r--r--
clsudo.py
14.42
KB
-rw-r--r--
ddt.py
12.43
KB
-rw-r--r--
distutils-precedence.pth
151
B
-rw-r--r--
docopt.py
19.48
KB
-rw-r--r--
hc_lve_profiler.py
6.2
KB
-rw-------
lveapi.py
19.53
KB
-rw-r--r--
lvectllib.py
102.55
KB
-rw-r--r--
lvestat.py
6.83
KB
-rw-r--r--
mccabe.py
10.4
KB
-rw-r--r--
pep8ext_naming.py
18.61
KB
-rw-r--r--
py.py
263
B
-rw-r--r--
pycodestyle.py
101.08
KB
-rw-r--r--
pylve.cpython-311-x86_64-linux...
25.48
KB
-rwxr-xr-x
remove_ubc.py
5.73
KB
-rwxr-xr-x
schema.py
29.51
KB
-rw-r--r--
secureio.py
18.83
KB
-rw-r--r--
simple_rpm.so
11.29
KB
-rwxr-xr-x
six.py
33.74
KB
-rw-r--r--
typing_extensions.py
100.97
KB
-rw-r--r--
unshare.cpython-311-x86_64-lin...
8.17
KB
-rwxr-xr-x
Delete
Unzip
Zip
${this.title}
Close
Code Editor : pep8ext_naming.py
# -*- coding: utf-8 -*- """Checker of PEP-8 Naming Conventions.""" import sys from collections import deque from fnmatch import fnmatch from functools import partial from itertools import chain from flake8_polyfill import options try: import ast from ast import iter_child_nodes except ImportError: from flake8.util import ast, iter_child_nodes __version__ = '0.10.0' PYTHON_VERSION = sys.version_info[:3] PY2 = PYTHON_VERSION[0] == 2 METACLASS_BASES = frozenset(('type', 'ABCMeta')) # Node types which may contain class methods METHOD_CONTAINER_NODES = {ast.If, ast.While, ast.For, ast.With} FUNC_NODES = (ast.FunctionDef,) if PY2: METHOD_CONTAINER_NODES |= {ast.TryExcept, ast.TryFinally} else: METHOD_CONTAINER_NODES |= {ast.Try} if PYTHON_VERSION > (3, 5): FUNC_NODES += (ast.AsyncFunctionDef,) METHOD_CONTAINER_NODES |= {ast.AsyncWith, ast.AsyncFor} if PY2: def _unpack_args(args): ret = [] for arg in args: if isinstance(arg, ast.Tuple): ret.extend(_unpack_args(arg.elts)) else: ret.append((arg, arg.id)) return ret def get_arg_name_tuples(node): return _unpack_args(node.args.args) elif PYTHON_VERSION < (3, 8): def get_arg_name_tuples(node): groups = (node.args.args, node.args.kwonlyargs) return [(arg, arg.arg) for args in groups for arg in args] else: def get_arg_name_tuples(node): groups = (node.args.posonlyargs, node.args.args, node.args.kwonlyargs) return [(arg, arg.arg) for args in groups for arg in args] class _ASTCheckMeta(type): def __init__(cls, class_name, bases, namespace): try: cls._checks.append(cls()) except AttributeError: cls._checks = [] def _err(self, node, code, **kwargs): lineno, col_offset = node.lineno, node.col_offset if isinstance(node, ast.ClassDef): if PYTHON_VERSION < (3, 8): lineno += len(node.decorator_list) col_offset += 6 elif isinstance(node, FUNC_NODES): if PYTHON_VERSION < (3, 8): lineno += len(node.decorator_list) col_offset += 4 code_str = getattr(self, code) if kwargs: code_str = code_str.format(**kwargs) return lineno, col_offset + 1, '%s %s' % (code, code_str), self def _ignored(name, ignore): return any(fnmatch(name, i) for i in ignore) BaseASTCheck = _ASTCheckMeta('BaseASTCheck', (object,), {'__doc__': "Base for AST Checks.", 'err': _err}) class _FunctionType(object): CLASSMETHOD = 'classmethod' STATICMETHOD = 'staticmethod' FUNCTION = 'function' METHOD = 'method' _default_ignore_names = [ 'setUp', 'tearDown', 'setUpClass', 'tearDownClass', 'setUpTestData', 'failureException', 'longMessage', 'maxDiff'] _default_classmethod_decorators = ['classmethod'] _default_staticmethod_decorators = ['staticmethod'] def _build_decorator_to_type(classmethod_decorators, staticmethod_decorators): decorator_to_type = {} for decorator in classmethod_decorators: decorator_to_type[decorator] = _FunctionType.CLASSMETHOD for decorator in staticmethod_decorators: decorator_to_type[decorator] = _FunctionType.STATICMETHOD return decorator_to_type class NamingChecker(object): """Checker of PEP-8 Naming Conventions.""" name = 'naming' version = __version__ decorator_to_type = _build_decorator_to_type( _default_classmethod_decorators, _default_staticmethod_decorators) ignore_names = frozenset(_default_ignore_names) def __init__(self, tree, filename): self.visitors = BaseASTCheck._checks self.parents = deque() self._node = tree @classmethod def add_options(cls, parser): options.register(parser, '--ignore-names', default=_default_ignore_names, action='store', type='string', parse_from_config=True, comma_separated_list=True, help='List of names or glob patterns the pep8-naming ' 'plugin should ignore. (Defaults to %default)') options.register(parser, '--classmethod-decorators', default=_default_classmethod_decorators, action='store', type='string', parse_from_config=True, comma_separated_list=True, help='List of method decorators pep8-naming plugin ' 'should consider classmethods (Defaults to ' '%default)') options.register(parser, '--staticmethod-decorators', default=_default_staticmethod_decorators, action='store', type='string', parse_from_config=True, comma_separated_list=True, help='List of method decorators pep8-naming plugin ' 'should consider staticmethods (Defaults to ' '%default)') @classmethod def parse_options(cls, options): cls.ignore_names = frozenset(options.ignore_names) cls.decorator_to_type = _build_decorator_to_type( options.classmethod_decorators, options.staticmethod_decorators) def run(self): return self.visit_tree(self._node) if self._node else () def visit_tree(self, node): for error in self.visit_node(node): yield error self.parents.append(node) for child in iter_child_nodes(node): for error in self.visit_tree(child): yield error self.parents.pop() def visit_node(self, node): if isinstance(node, ast.ClassDef): self.tag_class_functions(node) elif isinstance(node, FUNC_NODES): self.find_global_defs(node) method = 'visit_' + node.__class__.__name__.lower() parents = self.parents ignore_names = self.ignore_names for visitor in self.visitors: visitor_method = getattr(visitor, method, None) if visitor_method is None: continue for error in visitor_method(node, parents, ignore_names): yield error def tag_class_functions(self, cls_node): """Tag functions if they are methods, classmethods, staticmethods""" # tries to find all 'old style decorators' like # m = staticmethod(m) late_decoration = {} for node in iter_child_nodes(cls_node): if not (isinstance(node, ast.Assign) and isinstance(node.value, ast.Call) and isinstance(node.value.func, ast.Name)): continue func_name = node.value.func.id if func_name not in self.decorator_to_type: continue meth = (len(node.value.args) == 1 and node.value.args[0]) if isinstance(meth, ast.Name): late_decoration[meth.id] = self.decorator_to_type[func_name] # If this class inherits from a known metaclass base class, it is # itself a metaclass, and we'll consider all of it's methods to be # classmethods. bases = chain( (b.id for b in cls_node.bases if isinstance(b, ast.Name)), (b.attr for b in cls_node.bases if isinstance(b, ast.Attribute)), ) ismetaclass = any(name for name in bases if name in METACLASS_BASES) self.set_function_nodes_types( iter_child_nodes(cls_node), ismetaclass, late_decoration) def set_function_nodes_types(self, nodes, ismetaclass, late_decoration): # iterate over all functions and tag them for node in nodes: if type(node) in METHOD_CONTAINER_NODES: self.set_function_nodes_types( iter_child_nodes(node), ismetaclass, late_decoration) if not isinstance(node, FUNC_NODES): continue node.function_type = _FunctionType.METHOD if node.name in ('__new__', '__init_subclass__') or ismetaclass: node.function_type = _FunctionType.CLASSMETHOD if node.name in late_decoration: node.function_type = late_decoration[node.name] elif node.decorator_list: names = [self.decorator_to_type[d.id] for d in node.decorator_list if isinstance(d, ast.Name) and d.id in self.decorator_to_type] if names: node.function_type = names[0] @staticmethod def find_global_defs(func_def_node): global_names = set() nodes_to_check = deque(iter_child_nodes(func_def_node)) while nodes_to_check: node = nodes_to_check.pop() if isinstance(node, ast.Global): global_names.update(node.names) if not isinstance(node, (ast.ClassDef,) + FUNC_NODES): nodes_to_check.extend(iter_child_nodes(node)) func_def_node.global_names = global_names class ClassNameCheck(BaseASTCheck): """ Almost without exception, class names use the CapWords convention. Classes for internal use have a leading underscore in addition. """ N801 = "class name '{name}' should use CapWords convention" def visit_classdef(self, node, parents, ignore=None): name = node.name if _ignored(name, ignore): return name = name.strip('_') if not name[:1].isupper() or '_' in name: yield self.err(node, 'N801', name=name) class FunctionNameCheck(BaseASTCheck): """ Function names should be lowercase, with words separated by underscores as necessary to improve readability. Functions *not* being methods '__' in front and back are not allowed. mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility. """ N802 = "function name '{name}' should be lowercase" N807 = "function name '{name}' should not start and end with '__'" def visit_functiondef(self, node, parents, ignore=None): function_type = getattr(node, 'function_type', _FunctionType.FUNCTION) name = node.name if _ignored(name, ignore): return if name in ('__dir__', '__getattr__'): return if name.lower() != name: yield self.err(node, 'N802', name=name) if (function_type == _FunctionType.FUNCTION and name[:2] == '__' and name[-2:] == '__'): yield self.err(node, 'N807', name=name) visit_asyncfunctiondef = visit_functiondef class FunctionArgNamesCheck(BaseASTCheck): """ The argument names of a function should be lowercase, with words separated by underscores. A classmethod should have 'cls' as first argument. A method should have 'self' as first argument. """ N803 = "argument name '{name}' should be lowercase" N804 = "first argument of a classmethod should be named 'cls'" N805 = "first argument of a method should be named 'self'" def visit_functiondef(self, node, parents, ignore=None): def arg_name(arg): try: return arg, arg.arg except AttributeError: # PY2 return node, arg for arg, name in arg_name(node.args.vararg), arg_name(node.args.kwarg): if name is None or _ignored(name, ignore): continue if name.lower() != name: yield self.err(arg, 'N803', name=name) return arg_name_tuples = get_arg_name_tuples(node) if not arg_name_tuples: return arg0, name0 = arg_name_tuples[0] function_type = getattr(node, 'function_type', _FunctionType.FUNCTION) if function_type == _FunctionType.METHOD: if name0 != 'self' and not _ignored(name0, ignore): yield self.err(arg0, 'N805') elif function_type == _FunctionType.CLASSMETHOD: if name0 != 'cls' and not _ignored(name0, ignore): yield self.err(arg0, 'N804') for arg, name in arg_name_tuples: if name.lower() != name and not _ignored(name, ignore): yield self.err(arg, 'N803', name=name) return visit_asyncfunctiondef = visit_functiondef class ImportAsCheck(BaseASTCheck): """ Don't change the naming convention via an import """ N811 = "constant '{name}' imported as non constant '{asname}'" N812 = "lowercase '{name}' imported as non lowercase '{asname}'" N813 = "camelcase '{name}' imported as lowercase '{asname}'" N814 = "camelcase '{name}' imported as constant '{asname}'" N817 = "camelcase '{name}' imported as acronym '{asname}'" def visit_importfrom(self, node, parents, ignore=None): for name in node.names: asname = name.asname if not asname: continue original_name = name.name err_kwargs = {'name': original_name, 'asname': asname} if original_name.isupper(): if not asname.isupper(): yield self.err(node, 'N811', **err_kwargs) elif original_name.islower(): if asname.lower() != asname: yield self.err(node, 'N812', **err_kwargs) elif asname.islower(): yield self.err(node, 'N813', **err_kwargs) elif asname.isupper(): if ''.join(filter(str.isupper, original_name)) == asname: yield self.err(node, 'N817', **err_kwargs) else: yield self.err(node, 'N814', **err_kwargs) visit_import = visit_importfrom class VariablesCheck(BaseASTCheck): """ Class attributes and local variables in functions should be lowercase """ N806 = "variable '{name}' in function should be lowercase" N815 = "variable '{name}' in class scope should not be mixedCase" N816 = "variable '{name}' in global scope should not be mixedCase" def _find_errors(self, assignment_target, parents, ignore): for parent_func in reversed(parents): if isinstance(parent_func, ast.ClassDef): checker = self.class_variable_check break if isinstance(parent_func, FUNC_NODES): checker = partial(self.function_variable_check, parent_func) break else: checker = self.global_variable_check for name in _extract_names(assignment_target): if _ignored(name, ignore): continue error_code = checker(name) if error_code: yield self.err(assignment_target, error_code, name=name) @staticmethod def is_namedtupe(node_value): if isinstance(node_value, ast.Call): if isinstance(node_value.func, ast.Attribute): if node_value.func.attr == 'namedtuple': return True elif isinstance(node_value.func, ast.Name): if node_value.func.id == 'namedtuple': return True return False def visit_assign(self, node, parents, ignore=None): if self.is_namedtupe(node.value): return for target in node.targets: for error in self._find_errors(target, parents, ignore): yield error def visit_namedexpr(self, node, parents, ignore): if self.is_namedtupe(node.value): return for error in self._find_errors(node.target, parents, ignore): yield error visit_annassign = visit_namedexpr def visit_with(self, node, parents, ignore): if PY2: for error in self._find_errors( node.optional_vars, parents, ignore): yield error return for item in node.items: for error in self._find_errors( item.optional_vars, parents, ignore): yield error visit_asyncwith = visit_with def visit_for(self, node, parents, ignore): for error in self._find_errors(node.target, parents, ignore): yield error visit_asyncfor = visit_for def visit_excepthandler(self, node, parents, ignore): if node.name: for error in self._find_errors(node, parents, ignore): yield error def visit_generatorexp(self, node, parents, ignore): for gen in node.generators: for error in self._find_errors(gen.target, parents, ignore): yield error visit_listcomp = visit_dictcomp = visit_setcomp = visit_generatorexp @staticmethod def global_variable_check(name): if is_mixed_case(name): return 'N816' @staticmethod def class_variable_check(name): if is_mixed_case(name): return 'N815' @staticmethod def function_variable_check(func, var_name): if var_name in func.global_names: return None if var_name.lower() == var_name: return None return 'N806' def _extract_names(assignment_target): """Yield assignment_target ids.""" target_type = type(assignment_target) if target_type is ast.Name: yield assignment_target.id elif target_type in (ast.Tuple, ast.List): for element in assignment_target.elts: element_type = type(element) if element_type is ast.Name: yield element.id elif element_type in (ast.Tuple, ast.List): for n in _extract_names(element): yield n elif not PY2 and element_type is ast.Starred: # PEP 3132 for n in _extract_names(element.value): yield n elif target_type is ast.ExceptHandler: if PY2: # Python 2 supports unpacking tuple exception values. if isinstance(assignment_target.name, ast.Tuple): for name in assignment_target.name.elts: yield name.id elif isinstance(assignment_target.name, ast.Attribute): # Python 2 also supports assigning an exception to an attribute # eg. except Exception as obj.attr yield assignment_target.name.attr else: yield assignment_target.name.id else: yield assignment_target.name def is_mixed_case(name): return name.lower() != name and name.lstrip('_')[:1].islower()
Close