Skip to content

Commit

Permalink
Fix most pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yan committed Apr 18, 2015
1 parent 1505f5e commit 995b562
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 152 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.pyc
*.egg-info
.eggs/
build/
dist/
venv/
Expand Down
7 changes: 4 additions & 3 deletions letsencrypt/client/plugins/nginx/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def prepare(self):

# Entry point in main.py for installing cert
def deploy_cert(self, domain, cert, key, cert_chain=None):
# pylint: disable=unused-argument
"""Deploys certificate to specified virtual host. Aborts if the
vhost is missing ssl_certificate or ssl_certificate_key.
Expand Down Expand Up @@ -383,9 +384,9 @@ def get_version(self):
nginx_version = tuple([int(i) for i in version_matches[0].split(".")])

# nginx < 0.8.21 doesn't use default_server
if (nginx_version[0] == 0 and
(nginx_version[1] < 8 or
(nginx_version[1] == 8 and nginx_version[2] < 21))):
if (nginx_version[0] == 0 and (nginx_version[1] < 8 or
(nginx_version[1] == 8 and
nginx_version[2] < 21))):
raise errors.LetsEncryptConfiguratorError(
"Nginx version must be 0.8.21+")

Expand Down
6 changes: 0 additions & 6 deletions letsencrypt/client/plugins/nginx/dvsni.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ class NginxDvsni(object):
VHOST_TEMPLATE = """\
<VirtualHost {vhost}>
ServerName {server_name}
UseCanonicalName on
SSLStrictSNIVHostCheck on
LimitRequestBody 1048576
Include {ssl_options_conf_path}
SSLCertificateFile {cert_path}
SSLCertificateKeyFile {key_path}
DocumentRoot {document_root}
</VirtualHost>
Expand Down
34 changes: 34 additions & 0 deletions letsencrypt/client/plugins/nginx/nginxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class RawNginxParser(object):
# pylint: disable=expression-not-assigned
"""
A class that parses nginx configuration with pyparsing
"""
Expand Down Expand Up @@ -51,6 +52,7 @@ def as_list(self):


class RawNginxDumper(object):
# pylint: disable=too-few-public-methods
"""
A class that dumps nginx configuration from the provided tree.
"""
Expand Down Expand Up @@ -86,23 +88,55 @@ def __iter__(self, blocks=None, current_indent=0, spacer=' '):
yield spacer * current_indent + key + spacer + values + ';'

def as_string(self):
"""
Return the parsed block as a string.
"""
return '\n'.join(self)


# Shortcut functions to respect Python's serialization interface
# (like pyyaml, picker or json)

def loads(source):
"""Parses from a string.
:param str souce: The string to parse
:returns: The parsed tree
:rtype: list
"""
return RawNginxParser(source).as_list()


def load(_file):
"""Parses from a file.
:param file _file: The file to parse
:returns: The parsed tree
:rtype: list
"""
return loads(_file.read())


def dumps(blocks, indentation=4):
"""Dump to a string.
:param list block: The parsed tree
:param int indentation: The number of spaces to indent
:rtype: str
"""
return RawNginxDumper(blocks, indentation).as_string()


def dump(blocks, _file, indentation=4):
"""Dump to a file.
:param list block: The parsed tree
:param file _file: The file to dump to
:param int indentation: The number of spaces to indent
:rtype: NoneType
"""
return _file.write(dumps(blocks, indentation))
2 changes: 1 addition & 1 deletion letsencrypt/client/plugins/nginx/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def fromstring(cls, str_addr):
return None

tup = addr.partition(':')
if re.match('^\d+$', tup[0]):
if re.match(r'^\d+$', tup[0]):
# This is a bare port, not a hostname. E.g. listen 80
host = ''
port = tup[0]
Expand Down
Loading

0 comments on commit 995b562

Please sign in to comment.