From aef93695ae61f50be957eef2187a26765cb821d9 Mon Sep 17 00:00:00 2001 From: Julien Iguchi-Cartigny Date: Sat, 5 Jul 2014 10:22:27 +0200 Subject: [PATCH] starting PEP8 --- wstools/MIMEAttachment.py | 33 +++++++++++++++++---------------- wstools/Namespaces.py | 27 ++++++++++++++++++--------- wstools/TimeoutSocket.py | 11 ++++++----- wstools/UserTuple.py | 2 +- 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/wstools/MIMEAttachment.py b/wstools/MIMEAttachment.py index f4727c7..251a687 100644 --- a/wstools/MIMEAttachment.py +++ b/wstools/MIMEAttachment.py @@ -1,17 +1,17 @@ -#TODO add the license -#I had to rewrite this class because the python MIME email.mime (version 2.5) -#are buggy, they use \n instead \r\n for new line which is not compliant -#to standard! +# TODO add the license +# I had to rewrite this class because the python MIME email.mime (version 2.5) +# are buggy, they use \n instead \r\n for new line which is not compliant +# to standard! # http://bugs.python.org/issue5525 -#TODO do not load all the message in memory stream it from the disk +# TODO do not load all the message in memory stream it from the disk import re import random import sys -#new line +# new line NL = '\r\n' _width = len(repr(sys.maxint - 1)) @@ -27,32 +27,33 @@ class MIMEMessage: self._boundary = "" def makeBoundary(self): - #create the boundary + # create the boundary msgparts = [] msgparts.append(self._xmlMessage) for i in self._files: msgparts.append(i.read()) - #this sucks, all in memory + # this sucks, all in memory alltext = NL.join(msgparts) self._boundary = _make_boundary(alltext) - #maybe I can save some memory + # maybe I can save some memory del alltext del msgparts - self._startCID = "<" + (_fmt % random.randrange(sys.maxint)) + (_fmt % random.randrange(sys.maxint)) + ">" + self._startCID = "<" + (_fmt % random.randrange(sys.maxint)) \ + + (_fmt % random.randrange(sys.maxint)) + ">" def toString(self): '''it return a string with the MIME message''' if len(self._boundary) == 0: - #the makeBoundary hasn't been called yet + # the makeBoundary hasn't been called yet self.makeBoundary() - #ok we have everything let's start to spit the message out - #first the XML + # ok we have everything let's start to spit the message out + # first the XML returnstr = NL + "--" + self._boundary + NL returnstr += "Content-Type: text/xml; charset=\"us-ascii\"" + NL returnstr += "Content-Transfer-Encoding: 7bit" + NL returnstr += "Content-Id: " + self._startCID + NL + NL returnstr += self._xmlMessage + NL - #then the files + # then the files for file in self._files: returnstr += "--" + self._boundary + NL returnstr += "Content-Type: application/octet-stream" + NL @@ -60,7 +61,7 @@ class MIMEMessage: returnstr += "Content-Id: <" + str(id(file)) + ">" + NL + NL file.seek(0) returnstr += file.read() + NL - #closing boundary + # closing boundary returnstr += "--" + self._boundary + "--" + NL return returnstr @@ -91,7 +92,7 @@ class MIMEMessage: def _make_boundary(text=None): - #some code taken from python stdlib + # some code taken from python stdlib # Craft a random boundary. If text is given, ensure that the chosen # boundary doesn't appear in the text. token = random.randrange(sys.maxint) diff --git a/wstools/Namespaces.py b/wstools/Namespaces.py index 1bdb0c3..a3563bb 100644 --- a/wstools/Namespaces.py +++ b/wstools/Namespaces.py @@ -46,7 +46,8 @@ except: class DSIG: BASE = "http://www.w3.org/2000/09/xmldsig#" C14N = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" - C14N_COMM = "http://www.w3.org/TR/2000/CR-xml-c14n-20010315#WithComments" + C14N_COMM = \ + "http://www.w3.org/TR/2000/CR-xml-c14n-20010315#WithComments" C14N_EXCL = "http://www.w3.org/2001/10/xml-exc-c14n#" DIGEST_MD2 = "http://www.w3.org/2000/09/xmldsig#md2" DIGEST_MD5 = "http://www.w3.org/2000/09/xmldsig#md5" @@ -79,8 +80,11 @@ except: class WSRF_V1_2: - '''OASIS WSRF Specifications Version 1.2 + + ''' + OASIS WSRF Specifications Version 1.2 ''' + class LIFETIME: XSD_DRAFT1 = "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd" XSD_DRAFT4 = "http://docs.oasis-open.org/wsrf/2004/11/wsrf-WS-ResourceLifetime-1.2-draft-04.xsd" @@ -112,8 +116,8 @@ class WSRF_V1_2: class BASEFAULTS: XSD_DRAFT1 = "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-BaseFaults-1.2-draft-01.xsd" XSD_DRAFT3 = "http://docs.oasis-open.org/wsrf/2004/11/wsrf-WS-BaseFaults-1.2-draft-03.xsd" - #LATEST = DRAFT3 - #WSDL_LIST = (WSDL_DRAFT1, WSDL_DRAFT3) + # LATEST = DRAFT3 + # WSDL_LIST = (WSDL_DRAFT1, WSDL_DRAFT3) XSD_LIST = (XSD_DRAFT1, XSD_DRAFT3) WSRF = WSRF_V1_2 @@ -141,8 +145,9 @@ class OASIS: class APACHE: - '''This name space is defined by AXIS and it is used for the TC in TCapache.py, - Map and file attachment (DataHandler) + ''' + This name space is defined by AXIS and it is used for the TC in + TCapache.py, Map and file attachment (DataHandler) ''' AXIS_NS = "http://xml.apache.org/xml-soap" @@ -163,8 +168,10 @@ class WSU: class WSR: - PROPERTIES = "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceProperties" - LIFETIME = "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceLifetime" + PROPERTIES = \ + "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceProperties" + LIFETIME = \ + "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceLifetime" class WSA200508: @@ -196,7 +203,9 @@ WSA_LIST = (WSA200508, WSA200408, WSA200403, WSA200303) class _WSAW(str): - """ Define ADDRESS attribute to be compatible with WSA* layout """ + """ + Define ADDRESS attribute to be compatible with WSA* layout + """ ADDRESS = property(lambda s: s) WSAW200605 = _WSAW("http://www.w3.org/2006/05/addressing/wsdl") diff --git a/wstools/TimeoutSocket.py b/wstools/TimeoutSocket.py index 3e324a5..4ec0f88 100644 --- a/wstools/TimeoutSocket.py +++ b/wstools/TimeoutSocket.py @@ -15,7 +15,6 @@ ident = "$Id$" -import string import socket import select import errno @@ -24,7 +23,10 @@ WSAEINVAL = getattr(errno, 'WSAEINVAL', 10022) class TimeoutSocket: - """A socket imposter that supports timeout limits.""" + + """ + A socket imposter that supports timeout limits. + """ def __init__(self, timeout=20, sock=None): self.timeout = float(timeout) @@ -57,9 +59,8 @@ class TimeoutSocket: code = 0 else: code, why = why - if code not in ( - errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK - ): + if code not in \ + (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): raise r, w, e = select.select([], [sock], [], timeout) if w: diff --git a/wstools/UserTuple.py b/wstools/UserTuple.py index 98960fc..02981d0 100644 --- a/wstools/UserTuple.py +++ b/wstools/UserTuple.py @@ -43,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # $Id$ -#XXX tuple instances (in Python 2.2) contain also: +# XXX tuple instances (in Python 2.2) contain also: # __class__, __delattr__, __getattribute__, __hash__, __new__, # __reduce__, __setattr__, __str__ # What about these?