many pep8 improvements

This commit is contained in:
mdipierro
2012-10-19 12:33:53 -05:00
parent 71ec15190b
commit 6aa5edc7ff
117 changed files with 7160 additions and 5670 deletions
+10 -9
View File
@@ -49,7 +49,7 @@ defined_status = {
503: 'SERVICE UNAVAILABLE',
504: 'GATEWAY TIMEOUT',
505: 'HTTP VERSION NOT SUPPORTED',
}
}
# If web2py is executed with python2.4 we need
# to use Exception instead of BaseException
@@ -61,6 +61,7 @@ except NameError:
regex_status = re.compile('^\d{3} \w+$')
class HTTP(BaseException):
def __init__(
@@ -69,14 +70,14 @@ class HTTP(BaseException):
body='',
cookies=None,
**headers
):
):
self.status = status
self.body = body
self.headers = headers
self.cookies2headers(cookies)
def cookies2headers(self,cookies):
if cookies and len(cookies)>0:
def cookies2headers(self, cookies):
if cookies and len(cookies) > 0:
self.headers['Set-Cookie'] = [
str(cookie)[11:] for cookie in cookies.values()]
@@ -90,15 +91,15 @@ class HTTP(BaseException):
status = str(status)
if not regex_status.match(status):
status = '500 %s' % (defined_status[500])
headers.setdefault('Content-Type','text/html; charset=UTF-8')
headers.setdefault('Content-Type', 'text/html; charset=UTF-8')
body = self.body
if status[:1] == '4':
if not body:
body = status
if isinstance(body, str):
if len(body)<512 and \
if len(body) < 512 and \
headers['Content-Type'].startswith('text/html'):
body += '<!-- %s //-->' % ('x'*512) ### trick IE
body += '<!-- %s //-->' % ('x' * 512) # trick IE
headers['Content-Length'] = len(body)
rheaders = []
for k, v in headers.iteritems():
@@ -107,9 +108,9 @@ class HTTP(BaseException):
elif not v is None:
rheaders.append((k, str(v)))
responder(status, rheaders)
if env.get('request_method','')=='HEAD':
if env.get('request_method', '') == 'HEAD':
return ['']
elif isinstance(body,str):
elif isinstance(body, str):
return [body]
elif hasattr(body, '__iter__'):
return body