From c4be735c645bdbcb86b2448899a3aa664d5e97df Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Thu, 18 Oct 2012 23:53:23 +0000 Subject: pylint svn path=/branches/tk274/; revision=4786 --- buildtools/make-relaxng.py | 4 +- buildtools/make-sql-schemas.py | 2 +- buildtools/pylint.rc | 14 ++++- rpkid/Makefile.in | 2 +- rpkid/irbe_cli.py | 105 ++++++++++++++++---------------- rpkid/rpki-sql-backup.py | 2 +- rpkid/rpki-sql-setup.py | 8 ++- rpkid/rpki-start-servers.py | 1 + rpkid/rpki/adns.py | 19 +++--- rpkid/rpki/async.py | 26 +------- rpkid/rpki/config.py | 6 +- rpkid/rpki/csv_utils.py | 6 +- rpkid/rpki/exceptions.py | 2 +- rpkid/rpki/http.py | 29 +++++---- rpkid/rpki/ipaddrs.py | 2 +- rpkid/rpki/irdb/__init__.py | 2 + rpkid/rpki/irdb/models.py | 6 +- rpkid/rpki/irdb/router.py | 4 +- rpkid/rpki/irdb/zookeeper.py | 30 ++++----- rpkid/rpki/irdbd.py | 9 ++- rpkid/rpki/log.py | 1 + rpkid/rpki/mysql_import.py | 4 +- rpkid/rpki/oids.py | 2 +- rpkid/rpki/old_irdbd.py | 16 ++++- rpkid/rpki/publication.py | 3 +- rpkid/rpki/rcynic.py | 70 ++++++++++----------- rpkid/rpki/relaxng.py | 8 +-- rpkid/rpki/resource_set.py | 64 +++++++++---------- rpkid/rpki/rootd.py | 4 +- rpkid/rpki/rpkic.py | 10 +-- rpkid/rpki/rpkid.py | 1 - rpkid/rpki/rpkid_tasks.py | 2 +- rpkid/rpki/sql.py | 6 +- rpkid/rpki/sundial.py | 2 +- rpkid/rpki/up_down.py | 2 +- rpkid/rpki/x509.py | 45 +++++++------- rpkid/rpki/xml_utils.py | 2 +- rpkid/setup.py | 4 +- rpkid/tests/myrpki-xml-parse-test.py | 6 +- rpkid/tests/smoketest.py | 60 +++++++++++------- rpkid/tests/testpoke.py | 4 +- rpkid/tests/yamlconf.py | 16 ++--- rpkid/tests/yamltest.py | 38 ++++++++---- rtr-origin/rtr-origin.py | 2 +- scripts/convert-from-entitydb-to-sql.py | 2 +- scripts/format-application-x-rpki.py | 16 ++++- scripts/x509-dot.py | 2 +- 47 files changed, 358 insertions(+), 313 deletions(-) diff --git a/buildtools/make-relaxng.py b/buildtools/make-relaxng.py index 0058ade5..d35f56bc 100644 --- a/buildtools/make-relaxng.py +++ b/buildtools/make-relaxng.py @@ -3,7 +3,7 @@ Script to generate rpki/relaxng.py. $Id$ -Copyright (C) 2009-2011 Internet Systems Consortium ("ISC") +Copyright (C) 2009-2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -43,7 +43,7 @@ import lxml.etree format_2 = """\ ## @var %(name)s ## Parsed RelaxNG %(name)s schema -%(name)s = lxml.etree.RelaxNG(lxml.etree.fromstring('''%(rng)s''')) +%(name)s = lxml.etree.RelaxNG(lxml.etree.fromstring(r'''%(rng)s''')) """ def filename_to_symbol(s): diff --git a/buildtools/make-sql-schemas.py b/buildtools/make-sql-schemas.py index 3ecde014..8175bbf5 100644 --- a/buildtools/make-sql-schemas.py +++ b/buildtools/make-sql-schemas.py @@ -3,7 +3,7 @@ Script to generate rpki/relaxng.py. $Id$ -Copyright (C) 2009-2011 Internet Systems Consortium ("ISC") +Copyright (C) 2009-2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/buildtools/pylint.rc b/buildtools/pylint.rc index 5e555f45..872345fb 100644 --- a/buildtools/pylint.rc +++ b/buildtools/pylint.rc @@ -4,6 +4,18 @@ # differs enough from mine that it's not really usable without # customization. Useful options: --help, --generate-rcfile. +# Note that, in addition to disabling unhelpful messages globally, one +# can disable specific messages for an entire module or for a specific +# known issue, using magic comments in the Python source code. Form +# of the comment is the same in either case, how much it controls +# depends on the scope in which one places the comment. Format: +# +# # pylint: disable=code,code,... +# +# At top level in a module (eg, right before first import), it +# disables for a module. Within blocks (eg, as a comment on the line +# defining formal parameters to a function) it only in that scope. + [MASTER] profile=no @@ -32,7 +44,7 @@ disable-msg-cat= #enable-msg= # Disable the message(s) with the given id(s). -disable-msg=R0801,R0903,R0913,C0321,R0904,W0201,E1101,W0614,C0301,R0901,C0302,R0902,R0201,W0613,R0912,R0915,W0703,W0212,R0914,W0603 +disable=R0801,R0903,R0913,C0321,R0904,W0201,E1101,W0614,C0301,R0901,C0302,R0902,R0201,W0613,R0912,R0915,W0703,W0212,R0914,W0603,W0142,I0011,C0111,C0103,R0401 [REPORTS] diff --git a/rpkid/Makefile.in b/rpkid/Makefile.in index 12c264b3..1e90f502 100644 --- a/rpkid/Makefile.in +++ b/rpkid/Makefile.in @@ -131,7 +131,7 @@ tags: Makefile find . -type f \( -name '*.py' -o -name '*.sql' -o -name '*.rnc' -o -name '*.py.in' \) ! -name relaxng.py ! -name sql_schemas.py | etags - lint: - pylint --rcfile ${abs_top_srcdir}/buildtools/pylint.rc rpki/[a-z]*.py *d.py rpki-*.py rpkic.py irbe_cli.py tests/*.py + pylint --rcfile ${abs_top_srcdir}/buildtools/pylint.rc rpki/*.py rpki/irdb/*.py *.py tests/*.py # Documentation diff --git a/rpkid/irbe_cli.py b/rpkid/irbe_cli.py index 520b186d..0a458009 100644 --- a/rpkid/irbe_cli.py +++ b/rpkid/irbe_cli.py @@ -3,7 +3,7 @@ Command line IR back-end control program for rpkid and pubd. $Id$ -Copyright (C) 2009--2010 Internet Systems Consortium ("ISC") +Copyright (C) 2009--2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -95,6 +95,7 @@ class cmd_elt_mixin(reply_elt_mixin): """ Parse options for this class. """ + # pylint: disable=W0621 opts, argv = getopt.getopt(argv, "", [x + "=" for x in self.attributes + self.elements if x not in self.excludes] + list(self.booleans)) for o, a in opts: o = o[2:] @@ -148,47 +149,48 @@ class cmd_msg_mixin(object): # left-right protcol -class self_elt(cmd_elt_mixin, rpki.left_right.self_elt): - pass +class left_right_msg(cmd_msg_mixin, rpki.left_right.msg): -class bsc_elt(cmd_elt_mixin, rpki.left_right.bsc_elt): + class self_elt(cmd_elt_mixin, rpki.left_right.self_elt): + pass - excludes = ("pkcs10_request",) + class bsc_elt(cmd_elt_mixin, rpki.left_right.bsc_elt): - def client_query_signing_cert(self, arg): - """--signing_cert option.""" - self.signing_cert = rpki.x509.X509(Auto_file = arg) + excludes = ("pkcs10_request",) - def client_query_signing_cert_crl(self, arg): - """--signing_cert_crl option.""" - self.signing_cert_crl = rpki.x509.CRL(Auto_file = arg) + def client_query_signing_cert(self, arg): + """--signing_cert option.""" + self.signing_cert = rpki.x509.X509(Auto_file = arg) - def client_reply_decode(self): - global pem_out - if pem_out is not None and self.pkcs10_request is not None: - if isinstance(pem_out, str): - pem_out = open(pem_out, "w") - pem_out.write(self.pkcs10_request.get_PEM()) + def client_query_signing_cert_crl(self, arg): + """--signing_cert_crl option.""" + self.signing_cert_crl = rpki.x509.CRL(Auto_file = arg) -class parent_elt(cmd_elt_mixin, rpki.left_right.parent_elt): - pass + def client_reply_decode(self): + global pem_out + if pem_out is not None and self.pkcs10_request is not None: + if isinstance(pem_out, str): + pem_out = open(pem_out, "w") + pem_out.write(self.pkcs10_request.get_PEM()) -class child_elt(cmd_elt_mixin, rpki.left_right.child_elt): - pass + class parent_elt(cmd_elt_mixin, rpki.left_right.parent_elt): + pass -class repository_elt(cmd_elt_mixin, rpki.left_right.repository_elt): - pass + class child_elt(cmd_elt_mixin, rpki.left_right.child_elt): + pass -class list_published_objects_elt(cmd_elt_mixin, rpki.left_right.list_published_objects_elt): - excludes = ("uri",) + class repository_elt(cmd_elt_mixin, rpki.left_right.repository_elt): + pass -class list_received_resources_elt(cmd_elt_mixin, rpki.left_right.list_received_resources_elt): - excludes = ("parent_handle", "notBefore", "notAfter", "uri", "sia_uri", "aia_uri", "asn", "ipv4", "ipv6") + class list_published_objects_elt(cmd_elt_mixin, rpki.left_right.list_published_objects_elt): + excludes = ("uri",) -class report_error_elt(reply_elt_mixin, rpki.left_right.report_error_elt): - pass + class list_received_resources_elt(cmd_elt_mixin, rpki.left_right.list_received_resources_elt): + excludes = ("parent_handle", "notBefore", "notAfter", "uri", "sia_uri", "aia_uri", "asn", "ipv4", "ipv6") + + class report_error_elt(reply_elt_mixin, rpki.left_right.report_error_elt): + pass -class left_right_msg(cmd_msg_mixin, rpki.left_right.msg): pdus = dict((x.element_name, x) for x in (self_elt, bsc_elt, parent_elt, child_elt, repository_elt, list_published_objects_elt, list_received_resources_elt, report_error_elt)) @@ -201,36 +203,37 @@ class left_right_cms_msg(rpki.left_right.cms_msg): # Publication protocol -class config_elt(cmd_elt_mixin, rpki.publication.config_elt): +class publication_msg(cmd_msg_mixin, rpki.publication.msg): - def client_query_bpki_crl(self, arg): - """ - Special handler for --bpki_crl option. - """ - self.bpki_crl = rpki.x509.CRL(Auto_file = arg) + class config_elt(cmd_elt_mixin, rpki.publication.config_elt): -class client_elt(cmd_elt_mixin, rpki.publication.client_elt): - pass + def client_query_bpki_crl(self, arg): + """ + Special handler for --bpki_crl option. + """ + self.bpki_crl = rpki.x509.CRL(Auto_file = arg) -class certificate_elt(cmd_elt_mixin, rpki.publication.certificate_elt): - pass + class client_elt(cmd_elt_mixin, rpki.publication.client_elt): + pass -class crl_elt(cmd_elt_mixin, rpki.publication.crl_elt): - pass + class certificate_elt(cmd_elt_mixin, rpki.publication.certificate_elt): + pass + + class crl_elt(cmd_elt_mixin, rpki.publication.crl_elt): + pass -class manifest_elt(cmd_elt_mixin, rpki.publication.manifest_elt): - pass + class manifest_elt(cmd_elt_mixin, rpki.publication.manifest_elt): + pass -class roa_elt(cmd_elt_mixin, rpki.publication.roa_elt): - pass + class roa_elt(cmd_elt_mixin, rpki.publication.roa_elt): + pass -class report_error_elt(reply_elt_mixin, rpki.publication.report_error_elt): - pass + class report_error_elt(reply_elt_mixin, rpki.publication.report_error_elt): + pass -class ghostbuster_elt(cmd_elt_mixin, rpki.publication.ghostbuster_elt): - pass + class ghostbuster_elt(cmd_elt_mixin, rpki.publication.ghostbuster_elt): + pass -class publication_msg(cmd_msg_mixin, rpki.publication.msg): pdus = dict((x.element_name, x) for x in (config_elt, client_elt, certificate_elt, crl_elt, manifest_elt, roa_elt, report_error_elt, diff --git a/rpkid/rpki-sql-backup.py b/rpkid/rpki-sql-backup.py index b6e7320a..ea11d957 100644 --- a/rpkid/rpki-sql-backup.py +++ b/rpkid/rpki-sql-backup.py @@ -6,7 +6,7 @@ For the moment, this just writes all the SQL to stdout. $Id$ -Copyright (C) 2010 Internet Systems Consortium ("ISC") +Copyright (C) 2010-2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/rpkid/rpki-sql-setup.py b/rpkid/rpki-sql-setup.py index be138b0e..700d150a 100644 --- a/rpkid/rpki-sql-setup.py +++ b/rpkid/rpki-sql-setup.py @@ -4,7 +4,7 @@ root password, pulls other information from rpki.conf. $Id$ -Copyright (C) 2009--2011 Internet Systems Consortium ("ISC") +Copyright (C) 2009--2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -19,8 +19,10 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import os, getopt, sys, rpki.config, getpass, warnings - +import getopt +import sys +import getpass +import rpki.config import rpki.sql_schemas from rpki.mysql_import import MySQLdb diff --git a/rpkid/rpki-start-servers.py b/rpkid/rpki-start-servers.py index e7061062..722f51e6 100644 --- a/rpkid/rpki-start-servers.py +++ b/rpkid/rpki-start-servers.py @@ -58,6 +58,7 @@ cfg = rpki.config.parser(cfg_file, "myrpki") def run(name): + # pylint: disable=E1103 cmd = (sys.executable, os.path.join(rpkid_dir, name), "-c", cfg.filename) if debug: proc = subprocess.Popen(cmd + ("-d",), stdout = open(name + ".log", "a"), stderr = subprocess.STDOUT) diff --git a/rpkid/rpki/adns.py b/rpkid/rpki/adns.py index efee897f..736d793a 100644 --- a/rpkid/rpki/adns.py +++ b/rpkid/rpki/adns.py @@ -4,7 +4,7 @@ dnspython package. $Id$ -Copyright (C) 2010--2011 Internet Systems Consortium ("ISC") +Copyright (C) 2010--2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -34,8 +34,13 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import asyncore, socket, time, sys -import rpki.async, rpki.sundial, rpki.log +import asyncore +import socket +import time +import sys +import rpki.async +import rpki.sundial +import rpki.log try: import dns.resolver, dns.rdatatype, dns.rdataclass, dns.name, dns.message @@ -364,12 +369,12 @@ if __name__ == "__main__": e) if True: - for qtype in (dns.rdatatype.A, dns.rdatatype.AAAA, dns.rdatatype.HINFO): - test_query("subvert-rpki.hactrn.net", qtype) + for t in (dns.rdatatype.A, dns.rdatatype.AAAA, dns.rdatatype.HINFO): + test_query("subvert-rpki.hactrn.net", t) test_query("nonexistant.rpki.net") test_query("subvert-rpki.hactrn.net", qclass = dns.rdataclass.CH) - for host in ("subvert-rpki.hactrn.net", "nonexistant.rpki.net"): - test_getaddrinfo(host) + for h in ("subvert-rpki.hactrn.net", "nonexistant.rpki.net"): + test_getaddrinfo(h) rpki.async.event_loop() diff --git a/rpkid/rpki/async.py b/rpkid/rpki/async.py index 178bfb7b..4a6a1627 100644 --- a/rpkid/rpki/async.py +++ b/rpkid/rpki/async.py @@ -106,17 +106,7 @@ timer_queue = [] class timer(object): """ - Timer construct for event-driven code. It can be used in either of two ways: - - - As a virtual class, in which case the subclass should provide a - handler() method to receive the wakup event when the timer expires; or - - - By setting an explicit handler callback, either via the - constructor or the set_handler() method. - - Subclassing is probably more Pythonic, but setting an explict - handler turns out to be very convenient when combined with bound - methods to other objects. + Timer construct for event-driven code. """ ## @var gc_debug @@ -185,13 +175,6 @@ class timer(object): """ return self in timer_queue - def handler(self): - """ - Handle a timer that has expired. This must either be overriden by - a subclass or set dynamically by set_handler(). - """ - raise NotImplementedError - def set_handler(self, handler): """ Set timer's expiration handler. This is an alternative to @@ -202,13 +185,6 @@ class timer(object): """ self.handler = handler - def errback(self, e): - """ - Error callback. May be overridden, or set with set_errback(). - """ - rpki.log.error("Unhandled exception from timer: %s" % e) - rpki.log.traceback() - def set_errback(self, errback): """ Set a timer's errback. Like set_handler(), for errbacks. diff --git a/rpkid/rpki/config.py b/rpkid/rpki/config.py index 8957315f..cc5b6580 100644 --- a/rpkid/rpki/config.py +++ b/rpkid/rpki/config.py @@ -4,7 +4,7 @@ ConfigParser module. $Id$ -Copyright (C) 2009--2011 Internet Systems Consortium ("ISC") +Copyright (C) 2009--2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -87,6 +87,8 @@ class parser(object): if default_dirname is not None: filenames.append("%s/%s" % (default_dirname, default_filename)) + f = fn = None + for fn in filenames: try: f = open(fn) @@ -130,7 +132,7 @@ class parser(object): section = self.default_section if self.cfg.has_option(section, option): matches.append((-1, self.get(option, section = section))) - for key, value in self.cfg.items(section): + for key in self.cfg.options(section): s = key.rsplit(".", 1) if len(s) == 2 and s[0] == option and s[1].isdigit(): matches.append((int(s[1]), self.get(option, section = section))) diff --git a/rpkid/rpki/csv_utils.py b/rpkid/rpki/csv_utils.py index 352aebd9..30d07560 100644 --- a/rpkid/rpki/csv_utils.py +++ b/rpkid/rpki/csv_utils.py @@ -3,7 +3,7 @@ CSV utilities, moved here from myrpki.py. $Id$ -Copyright (C) 2009--2011 Internet Systems Consortium ("ISC") +Copyright (C) 2009--2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -71,7 +71,7 @@ class csv_reader(object): def __enter__(self): return self - def __exit__(self, type, value, traceback): + def __exit__(self, _type, value, traceback): self.file.close() class csv_writer(object): @@ -92,7 +92,7 @@ class csv_writer(object): def __enter__(self): return self - def __exit__(self, type, value, traceback): + def __exit__(self, _type, value, traceback): self.close() def close(self): diff --git a/rpkid/rpki/exceptions.py b/rpkid/rpki/exceptions.py index 68ea3bf6..0f5dbc49 100644 --- a/rpkid/rpki/exceptions.py +++ b/rpkid/rpki/exceptions.py @@ -3,7 +3,7 @@ Exception definitions for RPKI modules. $Id$ -Copyright (C) 2009--2010 Internet Systems Consortium ("ISC") +Copyright (C) 2009--2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/rpkid/rpki/http.py b/rpkid/rpki/http.py index 7d47826e..c3eae1fe 100644 --- a/rpkid/rpki/http.py +++ b/rpkid/rpki/http.py @@ -3,7 +3,7 @@ HTTP utilities, both client and server. $Id$ -Copyright (C) 2009-2011 Internet Systems Consortium ("ISC") +Copyright (C) 2009-2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -82,11 +82,6 @@ enable_ipv6_servers = True # far too much of the world. enable_ipv6_clients = False -## @var use_adns -# Whether to use rpki.adns code. This is still experimental, so it's -# not (yet) enabled by default. -use_adns = False - ## @var have_ipv6 # Whether the current machine claims to support IPv6. Note that just # because the kernel supports it doesn't mean that the machine has @@ -95,6 +90,7 @@ use_adns = False # SRI-NIC.ARPA?" seems a bit dated...). Don't set this, it's set # automatically by probing using the socket() system call at runtime. try: + # pylint: disable=W0702,W0104 socket.socket(socket.AF_INET6).close() socket.IPPROTO_IPV6 socket.IPV6_V6ONLY @@ -103,6 +99,16 @@ except: else: have_ipv6 = True +## @var use_adns + +# Whether to use rpki.adns code. This is still experimental, so it's +# not (yet) enabled by default. +use_adns = False +try: + import rpki.adns +except ImportError: + pass + def supported_address_families(enable_ipv6): """ IP address families on which servers should listen, and to consider @@ -590,7 +596,7 @@ class http_listener(asyncore.dispatcher): asyncore.dispatcher.__init__(self) self.handlers = handlers try: - af, socktype, proto, canonname, sockaddr = addrinfo + af, socktype, proto, canonname, sockaddr = addrinfo # pylint: disable=W0612 self.create_socket(af, socktype) self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: @@ -614,8 +620,8 @@ class http_listener(asyncore.dispatcher): stream for it and pass along all of our handler data. """ try: - s, client = self.accept() - self.log("Accepting connection from %s" % addr_to_string(client)) + s, c = self.accept() + self.log("Accepting connection from %s" % addr_to_string(c)) http_server(sock = s, handlers = self.handlers) except (rpki.async.ExitNow, SystemExit): raise @@ -669,7 +675,6 @@ class http_client(http_stream): self.log("Bypassing DNS for localhost") self.gotaddrinfo(localhost_addrinfo()) else: - import rpki.adns # This should move to start of file once we've decided to inflict it on all users families = supported_address_families(enable_ipv6_clients) self.log("Starting ADNS lookup for %s in families %r" % (self.host, families)) rpki.adns.getaddrinfo(self.gotaddrinfo, self.dns_error, self.host, families) @@ -804,7 +809,7 @@ class http_client(http_stream): if bad: try: raise rpki.exceptions.HTTPTimeout - except: + except: # pylint: disable=W0702 self.handle_error() else: self.queue.detach(self) @@ -886,7 +891,7 @@ class http_queue(object): self.log("Detaching client %r" % client_) self.client = None - def return_result(self, client, result, detach = False): + def return_result(self, client, result, detach = False): # pylint: disable=W0621 """ Client stream has returned a result, which we need to pass along to the original caller. Result may be either an HTTP response diff --git a/rpkid/rpki/ipaddrs.py b/rpkid/rpki/ipaddrs.py index 9b67d0f0..d096e1d4 100644 --- a/rpkid/rpki/ipaddrs.py +++ b/rpkid/rpki/ipaddrs.py @@ -13,7 +13,7 @@ once, here, thus avoiding a lot of duplicate code elsewhere. $Id$ -Copyright (C) 2009 Internet Systems Consortium ("ISC") +Copyright (C) 2009-2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/rpkid/rpki/irdb/__init__.py b/rpkid/rpki/irdb/__init__.py index 14365e10..64c9ee6c 100644 --- a/rpkid/rpki/irdb/__init__.py +++ b/rpkid/rpki/irdb/__init__.py @@ -19,6 +19,8 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ +# pylint: disable=W0401 + from rpki.irdb.models import * from rpki.irdb.zookeeper import Zookeeper from rpki.irdb.router import DBContextRouter, database diff --git a/rpkid/rpki/irdb/models.py b/rpkid/rpki/irdb/models.py index 8a41647d..e408612e 100644 --- a/rpkid/rpki/irdb/models.py +++ b/rpkid/rpki/irdb/models.py @@ -7,7 +7,7 @@ Django GUI code, so be careful. $Id$ -Copyright (C) 2011 Internet Systems Consortium ("ISC") +Copyright (C) 2011-2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -22,6 +22,8 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ +# pylint: disable=W0232 + import django.db.models import rpki.x509 import rpki.sundial @@ -294,7 +296,7 @@ class CA(django.db.models.Model): return result def revoke(self, cert): - Revocations.objects.create( + Revocation.objects.create( issuer = self, revoked = rpki.sundial.now(), serial = cert.certificate.getSerial(), diff --git a/rpkid/rpki/irdb/router.py b/rpkid/rpki/irdb/router.py index 3036a58b..fad78b36 100644 --- a/rpkid/rpki/irdb/router.py +++ b/rpkid/rpki/irdb/router.py @@ -77,7 +77,7 @@ class database(object): def __init__(self, name, on_entry = None, on_exit = None): if not isinstance(name, str): - raise ValueError("database name must be a string, not %r" % value) + raise ValueError("database name must be a string, not %r" % name) self.name = name self.on_entry = on_entry self.on_exit = on_exit @@ -88,7 +88,7 @@ class database(object): self.former = DBContextRouter._database DBContextRouter._database = self.name - def __exit__(self, type, value, traceback): + def __exit__(self, _type, value, traceback): assert DBContextRouter._database is self.name DBContextRouter._database = self.former if self.on_exit is not None: diff --git a/rpkid/rpki/irdb/zookeeper.py b/rpkid/rpki/irdb/zookeeper.py index 49416b89..9747bb30 100644 --- a/rpkid/rpki/irdb/zookeeper.py +++ b/rpkid/rpki/irdb/zookeeper.py @@ -18,17 +18,10 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import subprocess -import csv -import re +# pylint: disable=W0612 + import os -import getopt -import sys -import base64 -import time -import glob import copy -import warnings import rpki.config import rpki.cli import rpki.sundial @@ -45,10 +38,9 @@ import rpki.irdb import django.db.transaction from lxml.etree import (Element, SubElement, ElementTree, - fromstring as ElementFromString, - tostring as ElementToString) + tostring as ElementToString) -from rpki.csv_utils import (csv_reader, csv_writer, BadCSVSyntax) +from rpki.csv_utils import csv_reader @@ -116,7 +108,7 @@ class PEM_writer(object): try: if compare and pem == open(filename, "r").read(): return - except: + except: # pylint: disable=W0702 pass tempname += ".%s.tmp" % os.getpid() mode = 0400 if filename.endswith(".key") else 0444 @@ -233,7 +225,7 @@ class Zookeeper(object): if handle is None: raise MissingHandle - self.handle= handle + self.handle = handle def set_logstream(self, logstream): @@ -529,7 +521,7 @@ class Zookeeper(object): try: self.resource_ca.children.get(handle = child_handle).delete() except rpki.irdb.Child.DoesNotExist: - self.log("No such child \"%s\"" % arg) + self.log("No such child \"%s\"" % child_handle) @django.db.transaction.commit_on_success @@ -605,7 +597,7 @@ class Zookeeper(object): try: self.resource_ca.parents.get(handle = parent_handle).delete() except rpki.irdb.Parent.DoesNotExist: - self.log("No such parent \"%s\"" % arg) + self.log("No such parent \"%s\"" % parent_handle) @django.db.transaction.commit_on_success @@ -724,7 +716,7 @@ class Zookeeper(object): try: self.server_ca.clients.get(handle = client_handle).delete() except rpki.irdb.Client.DoesNotExist: - self.log("No such client \"%s\"" % arg) + self.log("No such client \"%s\"" % client_handle) @django.db.transaction.commit_on_success @@ -773,9 +765,9 @@ class Zookeeper(object): assert repository_handle is not None try: - self.resource_ca.repositories.get(handle = arg).delete() + self.resource_ca.repositories.get(handle = repository_handle).delete() except rpki.irdb.Repository.DoesNotExist: - self.log("No such repository \"%s\"" % arg) + self.log("No such repository \"%s\"" % repository_handle) @django.db.transaction.commit_on_success diff --git a/rpkid/rpki/irdbd.py b/rpkid/rpki/irdbd.py index 908c3325..dafdaff9 100644 --- a/rpkid/rpki/irdbd.py +++ b/rpkid/rpki/irdbd.py @@ -42,7 +42,6 @@ import os import time import getopt import urlparse -import warnings import rpki.http import rpki.config import rpki.resource_set @@ -144,7 +143,7 @@ class main(object): def __init__(self, **kwargs): - global rpki + global rpki # pylint: disable=W0602 os.environ["TZ"] = "UTC" time.tzset() @@ -192,7 +191,7 @@ class main(object): def main(self): - global rpki + global rpki # pylint: disable=W0602 from django.conf import settings startup_msg = self.cfg.get("startup-message", "") @@ -220,8 +219,8 @@ class main(object): "PORT" : "" }}, INSTALLED_APPS = ("rpki.irdb",),) - import rpki.irdb - + import rpki.irdb # pylint: disable=W0621 + # Entirely too much fun with read-only access to transactional databases. # # http://stackoverflow.com/questions/3346124/how-do-i-force-django-to-ignore-any-caches-and-reload-data diff --git a/rpkid/rpki/log.py b/rpkid/rpki/log.py index 7c20c3c1..2b48cb6d 100644 --- a/rpkid/rpki/log.py +++ b/rpkid/rpki/log.py @@ -171,6 +171,7 @@ def log_repr(obj, *tokens): IDs as needed, includes self_handle when available. """ + # pylint: disable=W0702 words = ["%s.%s" % (obj.__class__.__module__, obj.__class__.__name__)] try: words.append("{%s}" % obj.self.self_handle) diff --git a/rpkid/rpki/mysql_import.py b/rpkid/rpki/mysql_import.py index ac2b580d..40ccc348 100644 --- a/rpkid/rpki/mysql_import.py +++ b/rpkid/rpki/mysql_import.py @@ -16,7 +16,7 @@ object from this module. Looks kind of strange, but seems to work. $Id$ -Copyright (C) 2011 Internet Systems Consortium ("ISC") +Copyright (C) 2011-2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -45,6 +45,8 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ +# pylint: disable=W0611 + from __future__ import with_statement import warnings diff --git a/rpkid/rpki/oids.py b/rpkid/rpki/oids.py index 35b4453a..dc596f0b 100644 --- a/rpkid/rpki/oids.py +++ b/rpkid/rpki/oids.py @@ -3,7 +3,7 @@ OID database. $Id$ -Copyright (C) 2009--2011 Internet Systems Consortium ("ISC") +Copyright (C) 2009--2012 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/rpkid/rpki/old_irdbd.py b/rpkid/rpki/old_irdbd.py index c63ce9e2..6cc6cb14 100644 --- a/rpkid/rpki/old_irdbd.py +++ b/rpkid/rpki/old_irdbd.py @@ -37,9 +37,19 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import sys, os, time, getopt, urlparse, warnings -import rpki.http, rpki.config, rpki.resource_set, rpki.relaxng -import rpki.exceptions, rpki.left_right, rpki.log, rpki.x509 +import sys +import os +import time +import getopt +import urlparse +import rpki.http +import rpki.config +import rpki.resource_set +import rpki.relaxng +import rpki.exceptions +import rpki.left_right +import rpki.log +import rpki.x509 from rpki.mysql_import import MySQLdb diff --git a/rpkid/rpki/publication.py b/rpkid/rpki/publication.py index 8c50aeee..975d5fc9 100644 --- a/rpkid/rpki/publication.py +++ b/rpkid/rpki/publication.py @@ -205,7 +205,7 @@ class publication_object_elt(rpki.xml_utils.base_elt, publication_namespace): """ assert name == self.element_name, "Unexpected name %s, stack %s" % (name, stack) if text: - self.payload = self.payload_type(Base64 = text) + self.payload = self.payload_type(Base64 = text) # pylint: disable=E1102 stack.pop() def toXML(self): @@ -221,6 +221,7 @@ class publication_object_elt(rpki.xml_utils.base_elt, publication_namespace): """ Action dispatch handler. """ + # pylint: disable=E0203 try: if self.client is None: raise rpki.exceptions.BadQuery, "Client query received on control channel" diff --git a/rpkid/rpki/rcynic.py b/rpkid/rpki/rcynic.py index 6f5da2ca..d6c00710 100644 --- a/rpkid/rpki/rcynic.py +++ b/rpkid/rpki/rcynic.py @@ -16,9 +16,8 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -__revision__ = '$Id$' +__version__ = '$Id$' -import sys import os import rpki.x509 import rpki.exceptions @@ -175,7 +174,7 @@ class rcynic_file_iterator(object): self.rcynic_dir = os.path.join(rcynic_root, authenticated_subdir) def __iter__(self): - for root, dirs, files in os.walk(self.rcynic_dir): + for root, dirs, files in os.walk(self.rcynic_dir): # pylint: disable=W0612 for filename in files: filename = os.path.join(root, filename) ext = os.path.splitext(filename)[1] @@ -183,26 +182,26 @@ class rcynic_file_iterator(object): yield file_name_classes[ext](filename) class validation_status_element(object): - def __init__(self, *args, **kwargs): - self.attrs = [] - for k,v in kwargs.iteritems(): - setattr(self, k, v) - # attribute names are saved so that the __repr__ method can - # display the subset of attributes the user specified - self.attrs.append(k) - self._obj = None - - def get_obj(self): - if not self._obj: - self._obj = self.file_class(filename=self.filename, uri=self.uri) - return self._obj - - def __repr__(self): - v = [self.__class__.__name__, 'id=%s' % str(id(self))] - v.extend(['%s=%s' % (x, getattr(self, x)) for x in self.attrs]) - return '<%s>' % (' '.join(v),) - - obj = property(get_obj) + def __init__(self, *args, **kwargs): + self.attrs = [] + for k, v in kwargs.iteritems(): + setattr(self, k, v) + # attribute names are saved so that the __repr__ method can + # display the subset of attributes the user specified + self.attrs.append(k) + self._obj = None + + def get_obj(self): + if not self._obj: + self._obj = self.file_class(filename=self.filename, uri=self.uri) + return self._obj + + def __repr__(self): + v = [self.__class__.__name__, 'id=%s' % str(id(self))] + v.extend(['%s=%s' % (x, getattr(self, x)) for x in self.attrs]) + return '<%s>' % (' '.join(v),) + + obj = property(get_obj) class rcynic_xml_iterator(object): """ @@ -251,25 +250,26 @@ class rcynic_xml_iterator(object): # determine the path to this object if status == 'object_accepted': - d = self.authenticated_subdir + d = self.authenticated_subdir elif generation == 'backup': - d = self.authenticated_old_subdir + d = self.authenticated_old_subdir else: - d = self.unauthenticated_subdir + d = self.unauthenticated_subdir filename = os.path.join(d, self.uri_to_filename(uri)) ext = os.path.splitext(filename)[1] if ext in file_name_classes: - yield validation_status_element(timestamp=timestamp, generation=generation, uri=uri, - status=status, filename=filename, file_class=file_name_classes[ext]) + yield validation_status_element(timestamp = timestamp, generation = generation, + uri=uri, status = status, filename = filename, + file_class = file_name_classes[ext]) def label_iterator(xml_file): - """ - Returns an iterator which contains all defined labels from an rcynic XML - output file. Each item is a tuple of the form - (label, kind, description). - """ + """ + Returns an iterator which contains all defined labels from an rcynic XML + output file. Each item is a tuple of the form + (label, kind, description). + """ - for label in ElementTree(file=xml_file).find("labels"): - yield label.tag, label.get("kind"), label.text.strip() + for label in ElementTree(file=xml_file).find("labels"): + yield label.tag, label.get("kind"), label.text.strip() diff --git a/rpkid/rpki/relaxng.py b/rpkid/rpki/relaxng.py index c3f239d4..962858c7 100644 --- a/rpkid/rpki/relaxng.py +++ b/rpkid/rpki/relaxng.py @@ -4,7 +4,7 @@ import lxml.etree ## @var left_right ## Parsed RelaxNG left_right schema -left_right = lxml.etree.RelaxNG(lxml.etree.fromstring(''' +left_right = lxml.etree.RelaxNG(lxml.etree.fromstring(r'''