Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
a00dffc5
Commit
a00dffc5
authored
Apr 17, 2003
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- give all nearly-anonymous exceptions local names
- modernize several type-checks - remove unused imports
parent
edf05c7d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
lib/python/ZPublisher/HTTPResponse.py
lib/python/ZPublisher/HTTPResponse.py
+18
-15
No files found.
lib/python/ZPublisher/HTTPResponse.py
View file @
a00dffc5
...
@@ -12,19 +12,22 @@
...
@@ -12,19 +12,22 @@
##############################################################################
##############################################################################
'''CGI Response Output formatter
'''CGI Response Output formatter
$Id: HTTPResponse.py,v 1.7
3 2003/03/18 21:39:06
fdrake Exp $'''
$Id: HTTPResponse.py,v 1.7
4 2003/04/17 17:41:57
fdrake Exp $'''
__version__
=
'$Revision: 1.7
3
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.7
4
$'
[
11
:
-
2
]
import
types
,
os
,
sys
,
re
import
types
,
os
,
sys
,
re
import
zlib
,
struct
import
zlib
,
struct
from
string
import
translate
,
maketrans
from
string
import
translate
,
maketrans
from
types
import
StringType
,
InstanceType
,
LongType
,
UnicodeType
from
BaseResponse
import
BaseResponse
from
BaseResponse
import
BaseResponse
from
zExceptions
import
Unauthorized
from
zExceptions
import
Unauthorized
from
zExceptions.ExceptionFormatter
import
format_exception
from
zExceptions.ExceptionFormatter
import
format_exception
nl2sp
=
maketrans
(
'
\
n
'
,
' '
)
nl2sp
=
maketrans
(
'
\
n
'
,
' '
)
BadRequest
=
'BadRequest'
InternalError
=
'InternalError'
NotFound
=
'NotFound'
# Enable APPEND_TRACEBACKS to make Zope append tracebacks like it used to,
# Enable APPEND_TRACEBACKS to make Zope append tracebacks like it used to,
# but a better solution is to make standard_error_message display error_tb.
# but a better solution is to make standard_error_message display error_tb.
...
@@ -212,7 +215,7 @@ class HTTPResponse(BaseResponse):
...
@@ -212,7 +215,7 @@ class HTTPResponse(BaseResponse):
# It has already been determined.
# It has already been determined.
return
return
if
type
(
status
)
is
types
.
StringType
:
if
isinstance
(
status
,
str
)
:
status
=
status
.
lower
()
status
=
status
.
lower
()
if
status_codes
.
has_key
(
status
):
if
status_codes
.
has_key
(
status
):
status
=
status_codes
[
status
]
status
=
status_codes
[
status
]
...
@@ -280,16 +283,16 @@ class HTTPResponse(BaseResponse):
...
@@ -280,16 +283,16 @@ class HTTPResponse(BaseResponse):
if
not
body
:
if
not
body
:
return
self
return
self
if
type
(
body
)
is
types
.
TupleType
and
len
(
body
)
==
2
:
if
isinstance
(
body
,
tuple
)
and
len
(
body
)
==
2
:
title
,
body
=
body
title
,
body
=
body
if
type
(
body
)
is
not
types
.
StringType
:
if
not
isinstance
(
body
,
str
)
:
if
hasattr
(
body
,
'asHTML'
):
if
hasattr
(
body
,
'asHTML'
):
body
=
body
.
asHTML
()
body
=
body
.
asHTML
()
if
type
(
body
)
is
UnicodeType
:
if
isinstance
(
body
,
unicode
)
:
body
=
self
.
_encode_unicode
(
body
)
body
=
self
.
_encode_unicode
(
body
)
elif
type
(
body
)
is
StringType
:
elif
isinstance
(
body
,
str
)
:
pass
pass
else
:
else
:
try
:
try
:
...
@@ -432,7 +435,7 @@ class HTTPResponse(BaseResponse):
...
@@ -432,7 +435,7 @@ class HTTPResponse(BaseResponse):
If base is None, or the document already has a base, do nothing."""
If base is None, or the document already has a base, do nothing."""
if
base
is
None
:
if
base
is
None
:
base
=
''
base
=
''
elif
not
base
.
endswith
(
'/'
):
elif
not
base
.
endswith
(
'/'
):
base
=
base
+
'/'
base
=
base
+
'/'
self
.
base
=
str
(
base
)
self
.
base
=
str
(
base
)
...
@@ -622,7 +625,7 @@ class HTTPResponse(BaseResponse):
...
@@ -622,7 +625,7 @@ class HTTPResponse(BaseResponse):
def
notFoundError
(
self
,
entry
=
'Unknown'
):
def
notFoundError
(
self
,
entry
=
'Unknown'
):
self
.
setStatus
(
404
)
self
.
setStatus
(
404
)
raise
'NotFound'
,
self
.
_error_html
(
raise
NotFound
,
self
.
_error_html
(
"Resource not found"
,
"Resource not found"
,
"Sorry, the requested resource does not exist."
+
"Sorry, the requested resource does not exist."
+
"<p>Check the URL and try again.</p>"
+
"<p>Check the URL and try again.</p>"
+
...
@@ -632,7 +635,7 @@ class HTTPResponse(BaseResponse):
...
@@ -632,7 +635,7 @@ class HTTPResponse(BaseResponse):
# why reveal that it exists?
# why reveal that it exists?
def
debugError
(
self
,
entry
):
def
debugError
(
self
,
entry
):
raise
'NotFound'
,
self
.
_error_html
(
raise
NotFound
,
self
.
_error_html
(
"Debugging Notice"
,
"Debugging Notice"
,
"Zope has encountered a problem publishing your object.<p>"
"Zope has encountered a problem publishing your object.<p>"
"
\
n
%s"
%
entry
)
"
\
n
%s"
%
entry
)
...
@@ -640,11 +643,11 @@ class HTTPResponse(BaseResponse):
...
@@ -640,11 +643,11 @@ class HTTPResponse(BaseResponse):
def
badRequestError
(
self
,
name
):
def
badRequestError
(
self
,
name
):
self
.
setStatus
(
400
)
self
.
setStatus
(
400
)
if
re
.
match
(
'^[A-Z_0-9]+$'
,
name
):
if
re
.
match
(
'^[A-Z_0-9]+$'
,
name
):
raise
'InternalError'
,
self
.
_error_html
(
raise
InternalError
,
self
.
_error_html
(
"Internal Error"
,
"Internal Error"
,
"Sorry, an internal error occurred in this resource."
)
"Sorry, an internal error occurred in this resource."
)
raise
'BadRequest'
,
self
.
_error_html
(
raise
BadRequest
,
self
.
_error_html
(
"Invalid request"
,
"Invalid request"
,
"The parameter, <em>%s</em>, "
%
name
+
"The parameter, <em>%s</em>, "
%
name
+
"was omitted from the request.<p>"
+
"was omitted from the request.<p>"
+
...
@@ -708,7 +711,7 @@ class HTTPResponse(BaseResponse):
...
@@ -708,7 +711,7 @@ class HTTPResponse(BaseResponse):
del stb
del stb
self.setStatus(t)
self.setStatus(t)
if self.status >= 300 and self.status < 400:
if self.status >= 300 and self.status < 400:
if
type(v) == types.StringType
and absuri_match(v) is not None:
if
isinstance(v, str)
and absuri_match(v) is not None:
if self.status == 300:
if self.status == 300:
self.setStatus(302)
self.setStatus(302)
self.setHeader('
location
', v)
self.setHeader('
location
', v)
...
@@ -717,7 +720,7 @@ class HTTPResponse(BaseResponse):
...
@@ -717,7 +720,7 @@ class HTTPResponse(BaseResponse):
else:
else:
try:
try:
l, b = v
l, b = v
if (
type(l) == types.StringType
if (
isinstance(l, str)
and absuri_match(l) is not None):
and absuri_match(l) is not None):
if self.status == 300:
if self.status == 300:
self.setStatus(302)
self.setStatus(302)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment