mirror of https://github.com/yandex/gixy
Minor code style improvements
parent
411b74f7ba
commit
3dc9bde70b
|
@ -5,7 +5,6 @@ from six.moves import StringIO
|
|||
|
||||
from gixy.core.plugins_manager import PluginsManager
|
||||
|
||||
|
||||
# used while parsing args to keep track of where they came from
|
||||
_COMMAND_LINE_SOURCE_KEY = 'command_line'
|
||||
_ENV_VAR_SOURCE_KEY = 'environment_variables'
|
||||
|
@ -32,8 +31,8 @@ class GixyConfigParser(DefaultConfigFileParser):
|
|||
|
||||
white_space = '\\s*'
|
||||
key = '(?P<key>[^:=;#\s]+?)'
|
||||
value = white_space+'[:=\s]'+white_space+'(?P<value>.+?)'
|
||||
comment = white_space+'(?P<comment>\\s[;#].*)?'
|
||||
value = white_space + '[:=\s]' + white_space + '(?P<value>.+?)'
|
||||
comment = white_space + '(?P<comment>\\s[;#].*)?'
|
||||
|
||||
key_only_match = re.match('^' + key + comment + '$', line)
|
||||
if key_only_match:
|
||||
|
@ -41,7 +40,7 @@ class GixyConfigParser(DefaultConfigFileParser):
|
|||
items[key] = 'true'
|
||||
continue
|
||||
|
||||
key_value_match = re.match('^'+key+value+comment+'$', line)
|
||||
key_value_match = re.match('^' + key + value + comment + '$', line)
|
||||
if key_value_match:
|
||||
key = key_value_match.group('key')
|
||||
value = key_value_match.group('value')
|
||||
|
@ -54,7 +53,7 @@ class GixyConfigParser(DefaultConfigFileParser):
|
|||
continue
|
||||
|
||||
raise ConfigFileParserException('Unexpected line %s in %s: %s' % (i,
|
||||
getattr(stream, 'name', 'stream'), line))
|
||||
getattr(stream, 'name', 'stream'), line))
|
||||
return items
|
||||
|
||||
def serialize(self, items):
|
||||
|
@ -95,7 +94,7 @@ class ArgsParser(ArgumentParser):
|
|||
for arg in action.option_strings:
|
||||
if arg in {'--config', '--write-config', '--version'}:
|
||||
continue
|
||||
if any([arg.startswith(2*c) for c in self.prefix_chars]):
|
||||
if any([arg.startswith(2 * c) for c in self.prefix_chars]):
|
||||
keys += [arg[2:], arg] # eg. for '--bla' return ['bla', '--bla']
|
||||
|
||||
return keys
|
||||
|
@ -119,8 +118,8 @@ class ArgsParser(ArgumentParser):
|
|||
for action in self._actions:
|
||||
config_file_keys = self.get_possible_config_keys(action)
|
||||
if config_file_keys and not action.is_positional_arg and \
|
||||
already_on_command_line(existing_command_line_args,
|
||||
action.option_strings):
|
||||
already_on_command_line(existing_command_line_args,
|
||||
action.option_strings):
|
||||
value = getattr(parsed_namespace, action.dest, None)
|
||||
if value is not None:
|
||||
if type(value) is bool:
|
||||
|
@ -157,4 +156,4 @@ def create_parser():
|
|||
args_for_setting_config_path=['-c', '--config'],
|
||||
args_for_writing_out_config_file=['--write-config'],
|
||||
add_config_file_help=False
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from gixy.core.regexp import Regexp
|
||||
from gixy.core.variable import Variable
|
||||
|
||||
|
||||
BUILTIN_VARIABLES = {
|
||||
# http://nginx.org/en/docs/http/ngx_http_core_module.html#var_uri
|
||||
'uri': '/[^\x20\t]*',
|
||||
|
|
|
@ -9,7 +9,6 @@ class Config(object):
|
|||
output_format=None,
|
||||
output_file=None,
|
||||
allow_includes=True):
|
||||
|
||||
self.severity = severity
|
||||
self.output_format = output_format
|
||||
self.output_file = output_file
|
||||
|
|
|
@ -3,7 +3,6 @@ import copy
|
|||
|
||||
from gixy.core.utils import is_indexed_name
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
CONTEXTS = []
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class Issue(object):
|
||||
|
||||
def __init__(self, plugin, summary=None, description=None,
|
||||
severity=None, reason=None, help_url=None, directives=None):
|
||||
self.plugin = plugin
|
||||
|
|
|
@ -5,7 +5,6 @@ from gixy.plugins.plugin import Plugin
|
|||
|
||||
|
||||
class PluginsManager(object):
|
||||
|
||||
def __init__(self, config=None):
|
||||
self.imported = False
|
||||
self.config = config
|
||||
|
@ -19,7 +18,7 @@ class PluginsManager(object):
|
|||
for plugin_file in files_list:
|
||||
if not plugin_file.endswith('.py') or plugin_file.startswith('_'):
|
||||
continue
|
||||
__import__('gixy.plugins.'+os.path.splitext(plugin_file)[0], None, None, [''])
|
||||
__import__('gixy.plugins.' + os.path.splitext(plugin_file)[0], None, None, [''])
|
||||
|
||||
self.imported = True
|
||||
|
||||
|
|
|
@ -21,14 +21,17 @@ try:
|
|||
from _sre import MAXREPEAT
|
||||
except ImportError:
|
||||
import _sre
|
||||
|
||||
MAXREPEAT = _sre.MAXREPEAT = 65535
|
||||
|
||||
|
||||
# SRE standard exception (access as sre.error)
|
||||
# should this really be here?
|
||||
|
||||
class error(Exception):
|
||||
pass
|
||||
|
||||
|
||||
# operators
|
||||
|
||||
FAILURE = "failure"
|
||||
|
@ -148,6 +151,7 @@ CHCODES = [
|
|||
CATEGORY_UNI_NOT_LINEBREAK
|
||||
]
|
||||
|
||||
|
||||
def makedict(list):
|
||||
d = {}
|
||||
i = 0
|
||||
|
@ -156,6 +160,7 @@ def makedict(list):
|
|||
i = i + 1
|
||||
return d
|
||||
|
||||
|
||||
OPCODES = makedict(OPCODES)
|
||||
ATCODES = makedict(ATCODES)
|
||||
CHCODES = makedict(CHCODES)
|
||||
|
@ -206,17 +211,16 @@ CH_UNICODE = {
|
|||
}
|
||||
|
||||
# flags
|
||||
SRE_FLAG_TEMPLATE = 1 # template mode (disable backtracking)
|
||||
SRE_FLAG_IGNORECASE = 2 # case insensitive
|
||||
SRE_FLAG_LOCALE = 4 # honour system locale
|
||||
SRE_FLAG_MULTILINE = 8 # treat target as multiline string
|
||||
SRE_FLAG_DOTALL = 16 # treat target as a single string
|
||||
SRE_FLAG_UNICODE = 32 # use unicode locale
|
||||
SRE_FLAG_VERBOSE = 64 # ignore whitespace and comments
|
||||
SRE_FLAG_DEBUG = 128 # debugging
|
||||
SRE_FLAG_TEMPLATE = 1 # template mode (disable backtracking)
|
||||
SRE_FLAG_IGNORECASE = 2 # case insensitive
|
||||
SRE_FLAG_LOCALE = 4 # honour system locale
|
||||
SRE_FLAG_MULTILINE = 8 # treat target as multiline string
|
||||
SRE_FLAG_DOTALL = 16 # treat target as a single string
|
||||
SRE_FLAG_UNICODE = 32 # use unicode locale
|
||||
SRE_FLAG_VERBOSE = 64 # ignore whitespace and comments
|
||||
SRE_FLAG_DEBUG = 128 # debugging
|
||||
|
||||
# flags for INFO primitive
|
||||
SRE_INFO_PREFIX = 1 # has prefix
|
||||
SRE_INFO_LITERAL = 2 # entire pattern is literal (given by prefix)
|
||||
SRE_INFO_CHARSET = 4 # pattern starts with character from given set
|
||||
|
||||
SRE_INFO_PREFIX = 1 # has prefix
|
||||
SRE_INFO_LITERAL = 2 # entire pattern is literal (given by prefix)
|
||||
SRE_INFO_CHARSET = 4 # pattern starts with character from given set
|
||||
|
|
|
@ -4,7 +4,6 @@ import logging
|
|||
from gixy.core.regexp import Regexp
|
||||
from gixy.core.context import get_context
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
# See ngx_http_script_compile in http/ngx_http_script.c
|
||||
EXTRACT_RE = re.compile(r'\$([1-9]|[a-z_][a-z0-9_]*|\{[a-z0-9_]+\})', re.IGNORECASE)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import os
|
||||
from gixy.directives.directive import Directive
|
||||
|
||||
|
||||
DIRECTIVES = {}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
"""NginxParser is a member object of the NginxConfigurator class."""
|
||||
import os
|
||||
import glob
|
||||
import logging
|
||||
|
@ -13,7 +12,6 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class NginxParser(object):
|
||||
|
||||
def __init__(self, file_path, allow_includes=True):
|
||||
self.base_file_path = file_path
|
||||
self.cwd = os.path.dirname(file_path)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
"""Very low-level nginx config parser based on pyparsing."""
|
||||
import re
|
||||
import logging
|
||||
from cached_property import cached_property
|
||||
|
@ -7,7 +6,6 @@ from pyparsing import (
|
|||
Literal, Suppress, White, Word, alphanums, Forward, Group, Optional, Combine,
|
||||
Keyword, OneOrMore, ZeroOrMore, Regex, QuotedString, nestedExpr)
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue