diff options
author | Fabian Affolter <fabian@bernewireless.net> | 2010-06-07 13:26:11 +0000 |
---|---|---|
committer | Sol Jerome <solj@ices.utexas.edu> | 2010-06-07 08:42:53 -0500 |
commit | 6d2a8b48de43d5a07c8c0ea813f61db30722b320 (patch) | |
tree | fad57e3a0ccc188d9fa69c5c93a18346d5d3b558 | |
parent | 3599dc2990dafbacdb5aa54a6bd338850cefa770 (diff) | |
download | bcfg2-6d2a8b48de43d5a07c8c0ea813f61db30722b320.tar.gz bcfg2-6d2a8b48de43d5a07c8c0ea813f61db30722b320.tar.bz2 bcfg2-6d2a8b48de43d5a07c8c0ea813f61db30722b320.zip |
Updated files to match PEP 257
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5899 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r-- | src/lib/Component.py | 8 | ||||
-rw-r--r-- | src/lib/Logger.py | 23 | ||||
-rw-r--r-- | src/lib/Options.py | 6 | ||||
-rw-r--r-- | src/lib/Proxy.py | 16 | ||||
-rw-r--r-- | src/lib/SSLServer.py | 9 | ||||
-rw-r--r-- | src/lib/__init__.py | 2 |
6 files changed, 40 insertions, 24 deletions
diff --git a/src/lib/Component.py b/src/lib/Component.py index 1a4c35d02..9cdf23b9d 100644 --- a/src/lib/Component.py +++ b/src/lib/Component.py @@ -90,6 +90,7 @@ def exposed(func): def my_method (self, param1, param2): do_stuff() my_method = expose(my_method) + """ func.exposed = True return func @@ -112,7 +113,6 @@ def readonly(func): return func class Component (object): - """Base component. Intended to be served as an instance by Cobalt.Component.XMLRPCServer @@ -127,6 +127,7 @@ class Component (object): Methods: save -- pickle the component to a file do_tasks -- perform automatic tasks for the component + """ name = "component" @@ -137,6 +138,7 @@ class Component (object): Keyword arguments: statefile -- file in which to save state automatically + """ self.statefile = kwargs.get("statefile", None) self.logger = logging.getLogger("%s %s" % (self.implementation, self.name)) @@ -148,6 +150,7 @@ class Component (object): Automatic tasks are member callables with an attribute automatic == True. + """ for name, func in inspect.getmembers(self, callable): if getattr(func, "automatic", False): @@ -179,6 +182,7 @@ class Component (object): Arguments: method_name -- name of the method to resolve + """ try: func = getattr(self, method_name) @@ -193,6 +197,7 @@ class Component (object): method -- XML-RPC method name args -- tuple of paramaters to method + """ need_to_lock = True if method in dispatch_dict: @@ -247,6 +252,7 @@ class Component (object): Arguments: method_name -- name of method to get help on + """ try: func = self._resolve_exposed_method(method_name) diff --git a/src/lib/Logger.py b/src/lib/Logger.py index 65ee0e596..5616d7469 100644 --- a/src/lib/Logger.py +++ b/src/lib/Logger.py @@ -1,4 +1,4 @@ -'''Bcfg2 logging support''' +"""Bcfg2 logging support""" __revision__ = '$Revision$' import copy @@ -14,16 +14,16 @@ import termios logging.raiseExceptions = 0 def print_attributes(attrib): - ''' Add the attributes for an element''' + """Add the attributes for an element.""" return ' '.join(['%s="%s"' % data for data in list(attrib.items())]) def print_text(text): - ''' Add text to the output (which will need normalising ''' + """Add text to the output (which will need normalising.""" charmap = {'<':'<', '>':'>', '&':'&'} return ''.join([charmap.get(char, char) for char in text]) + '\n' def xml_print(element, running_indent=0, indent=4): - ''' Add an element and its children to the return string ''' + """Add an element and its children to the return string.""" if (len(element.getchildren()) == 0) and (not element.text): ret = (' ' * running_indent) ret += '<%s %s/>\n' % (element.tag, print_attributes(element.attrib)) @@ -41,7 +41,7 @@ def xml_print(element, running_indent=0, indent=4): return ret class TermiosFormatter(logging.Formatter): - '''The termios formatter displays output in a terminal-sensitive fashion''' + """The termios formatter displays output in a terminal-sensitive fashion.""" def __init__(self, fmt=None, datefmt=None): logging.Formatter.__init__(self, fmt, datefmt) @@ -92,10 +92,10 @@ class TermiosFormatter(logging.Formatter): return '\n'.join(returns) class FragmentingSysLogHandler(logging.handlers.SysLogHandler): - ''' + """ This handler fragments messages into chunks smaller than 250 characters - ''' + """ def __init__(self, procname, path, facility): self.procname = procname @@ -103,7 +103,7 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler): logging.handlers.SysLogHandler.__init__(self, path, facility) def emit(self, record): - '''chunk and deliver records''' + """Chunk and deliver records.""" record.name = self.procname if str(record.msg) > 250: msgs = [] @@ -138,7 +138,7 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler): self.socket.send(msg) def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='daemon', level=0, to_file=None): - '''setup logging for bcfg2 software''' + """Setup logging for Bcfg2 software.""" if hasattr(logging, 'already_setup'): return # add the handler to the root logger @@ -170,12 +170,13 @@ def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='da logging.already_setup = True def trace_process(**kwargs): - """Literally log every line of python code as it runs. Keyword arguments: log -- file (name) to log to (default stderr) - scope -- base scope to log to (default Cobalt)""" + scope -- base scope to log to (default Cobalt) + + """ file_name = kwargs.get("log", None) if file_name is not None: diff --git a/src/lib/Options.py b/src/lib/Options.py index 879bc3bab..abdfedc51 100644 --- a/src/lib/Options.py +++ b/src/lib/Options.py @@ -1,4 +1,4 @@ -'''Option parsing library for utilities''' +"""Option parsing library for utilities.""" __revision__ = '$Revision$' import ConfigParser @@ -315,10 +315,10 @@ CLIENT_SERVICE_MODE = Option('Set client service mode', default='default', class OptionParser(OptionSet): - ''' + """ OptionParser bootstraps option parsing, getting the value of the config file - ''' + """ def __init__(self, args): self.Bootstrap = OptionSet([('configfile', CFILE)]) self.Bootstrap.parse(sys.argv[1:], do_getopt=False) diff --git a/src/lib/Proxy.py b/src/lib/Proxy.py index 788cfde0f..275405faf 100644 --- a/src/lib/Proxy.py +++ b/src/lib/Proxy.py @@ -5,6 +5,7 @@ ComponentProxy -- an RPC client proxy to Cobalt components Functions: load_config -- read configuration files + """ __revision__ = '$Revision: $' @@ -47,7 +48,7 @@ class CertificateError(Exception): self.commonName = commonName class RetryMethod(_Method): - """Method with error handling and retries built in""" + """Method with error handling and retries built in.""" log = logging.getLogger('xmlrpc') max_retries = 4 def __call__(self, *args): @@ -84,8 +85,7 @@ class RetryMethod(_Method): xmlrpclib._Method = RetryMethod class SSLHTTPConnection(httplib.HTTPConnection): - - """Extension of HTTPConnection that implements SSL and related behaviors""" + """Extension of HTTPConnection that implements SSL and related behaviors.""" logger = logging.getLogger('Bcfg2.Proxy.SSLHTTPConnection') @@ -134,6 +134,7 @@ class SSLHTTPConnection(httplib.HTTPConnection): connect() call will throw a `CertificateError`. protocol : {'xmlrpc/ssl', 'xmlrpc/tlsv1'}, optional Communication protocol to use. + """ if not has_py26: httplib.HTTPConnection.__init__(self, host, port, strict) @@ -147,7 +148,7 @@ class SSLHTTPConnection(httplib.HTTPConnection): self.timeout = timeout def connect(self): - """Initiates a connection using previously set attributes""" + """Initiates a connection using previously set attributes.""" if SSL_LIB == 'py26_ssl': self._connect_py26ssl() elif SSL_LIB == 'm2crypto': @@ -157,7 +158,7 @@ class SSLHTTPConnection(httplib.HTTPConnection): def _connect_py26ssl(self): - """Initiates a connection using the ssl module""" + """Initiates a connection using the ssl module.""" rawsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if self.protocol == 'xmlrpc/ssl': ssl_protocol_ver = ssl.PROTOCOL_SSLv23 @@ -193,7 +194,7 @@ class SSLHTTPConnection(httplib.HTTPConnection): self.sock.closeSocket = True def _connect_m2crypto(self): - """Initiates a connection using the M2Crypto module""" + """Initiates a connection using the M2Crypto module.""" if self.protocol == 'xmlrpc/ssl': ctx = SSL.Context('sslv23') @@ -257,7 +258,7 @@ class XMLRPCTransport(xmlrpclib.Transport): return https def request(self, host, handler, request_body, verbose=0): - '''send request to server and return response''' + """Send request to server and return response.""" h = self.make_connection(host) self.send_request(h, handler, request_body) self.send_host(h, host) @@ -303,6 +304,7 @@ def ComponentProxy(url, user=None, password=None, key=None, cert=None, ca=None, component_name -- name of the component to connect to Additional arguments are passed to the ServerProxy constructor. + """ if user and password: diff --git a/src/lib/SSLServer.py b/src/lib/SSLServer.py index fac332f14..ca22a33b8 100644 --- a/src/lib/SSLServer.py +++ b/src/lib/SSLServer.py @@ -69,6 +69,7 @@ class SSLServer (SocketServer.TCPServer, object): Properties: url -- A url pointing to this server. + """ allow_reuse_address = True @@ -88,6 +89,7 @@ class SSLServer (SocketServer.TCPServer, object): certfile -- certificate file (enables ssl encryption) reqCert -- client must present certificate timeout -- timeout for non-blocking request handling + """ all_iface_address = ('', server_address[1]) @@ -158,6 +160,7 @@ class XMLRPCRequestHandler (SimpleXMLRPCServer.SimpleXMLRPCRequestHandler): Methods: authenticate -- prompt a check of a client's provided username and password handle_one_request -- handle a single rpc (optionally authenticating) + """ logger = logging.getLogger("Cobalt.Server.XMLRPCRequestHandler") @@ -182,7 +185,9 @@ class XMLRPCRequestHandler (SimpleXMLRPCServer.SimpleXMLRPCRequestHandler): def parse_request(self): """Extends parse_request. - Optionally check HTTP authentication when parsing.""" + Optionally check HTTP authentication when parsing. + + """ if not SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.parse_request(self): return False try: @@ -251,6 +256,7 @@ class XMLRPCServer (SocketServer.ThreadingMixIn, SSLServer, Properties: require_auth -- the request handler is requiring authorization credentials -- valid credentials being used for authentication + """ def __init__(self, server_address, RequestHandlerClass=None, @@ -272,6 +278,7 @@ class XMLRPCServer (SocketServer.ThreadingMixIn, SSLServer, register -- presence should be reported to service-location (default True) allow_none -- allow None values in xml-rpc encoding -- encoding to use for xml-rpc (default UTF-8) + """ XMLRPCDispatcher.__init__(self, allow_none, encoding) diff --git a/src/lib/__init__.py b/src/lib/__init__.py index b9056f25f..d36c0a00a 100644 --- a/src/lib/__init__.py +++ b/src/lib/__init__.py @@ -1,4 +1,4 @@ -'''base modules definition''' +"""Base modules definition.""" __revision__ = '$Revision$' __all__ = ['Server', 'Client', 'Component', 'Logger', 'Options', 'Proxy', 'Statistics'] |