Skip to content

Commit

Permalink
[WIP]Revise section exceptions (#578)
Browse files Browse the repository at this point in the history
* Fix typo.

modified:   src/ZPublisher/HTTPResponse.py

* Fix typo.

modified:   src/ZPublisher/HTTPResponse.py

* Fix typo.

modified:   src/ZPublisher/HTTPResponse.py

* Fix case.

* Make method static.

modified:   src/ZPublisher/HTTPResponse.py

* Simplify HTTPResponse.exception

- simplify comparison
- remove redundant parenthesis

modified:   src/ZPublisher/HTTPResponse.py

* Remove redundant parenthesis.

modified:   src/ZPublisher/HTTPResponse.py
  • Loading branch information
jugmac00 authored and dataflake committed May 2, 2019
1 parent 2139f2c commit b1b338b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/ZPublisher/HTTPResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
uncompressableMimeMajorTypes = ('image',)

# The environment variable DONT_GZIP_MAJOR_MIME_TYPES can be set to a list
# of comma seperated mime major types which should also not be compressed
# of comma separated mime major types which should also not be compressed

otherTypes = os.environ.get('DONT_GZIP_MAJOR_MIME_TYPES', '').lower()
if otherTypes:
Expand Down Expand Up @@ -415,7 +415,7 @@ def addHeader(self, name, value):
Retain any previously set headers with the same name.
Note that this API appneds to the 'accumulated_headers' attribute;
Note that this API appends to the 'accumulated_headers' attribute;
it does not update the 'headers' mapping.
"""
name, value = _scrubHeader(name, value)
Expand All @@ -428,7 +428,7 @@ def setBase(self, base):
If base is None, set to the empty string.
If base is not None, ensure that it has a trailing slach.
If base is not None, ensure that it has a trailing slash.
"""
if base is None:
base = ''
Expand All @@ -438,7 +438,7 @@ def setBase(self, base):
self.base = str(base)

def insertBase(self):
# Only insert a base tag if content appears to be html.
# Only insert a base tag if content appears to be HTML.
content_type = self.headers.get('content-type', '').split(';')[0]
if content_type and (content_type != 'text/html'):
return
Expand Down Expand Up @@ -724,7 +724,8 @@ def _unauthorized(self):
if realm:
self.setHeader('WWW-Authenticate', 'basic realm="%s"' % realm, 1)

def _html(self, title, body):
@staticmethod
def _html(title, body):
return ("<html>\n"
"<head>\n<title>%s</title>\n</head>\n"
"<body>\n%s\n</body>\n"
Expand Down Expand Up @@ -855,7 +856,7 @@ def exception(self, fatal=0, info=None, abort=1):
self._unauthorized()

self.setStatus(t)
if self.status >= 300 and self.status < 400:
if 300 <= self.status < 400:
if isinstance(v, str) and absuri_match(v) is not None:
if self.status == 300:
self.setStatus(302)
Expand All @@ -872,7 +873,7 @@ def exception(self, fatal=0, info=None, abort=1):
else:
try:
l, b = v
if (isinstance(l, str) and absuri_match(l) is not None):
if isinstance(l, str) and absuri_match(l) is not None:
if self.status == 300:
self.setStatus(302)
self.setHeader('location', l)
Expand Down Expand Up @@ -1044,7 +1045,7 @@ def finalize(self):
if content_length is None and not self._streaming:
self.setHeader('content-length', len(self.body))

return ('%s %s' % (self.status, self.errmsg), self.listHeaders())
return '%s %s' % (self.status, self.errmsg), self.listHeaders()

def listHeaders(self):
result = []
Expand Down

0 comments on commit b1b338b

Please sign in to comment.