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
c75f735c
Commit
c75f735c
authored
Jun 09, 2000
by
Evan Simpson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge Before-traverse-Dev-branch
parent
dbf73423
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
330 additions
and
196 deletions
+330
-196
lib/python/OFS/SimpleItem.py
lib/python/OFS/SimpleItem.py
+30
-19
lib/python/ZPublisher/BaseRequest.py
lib/python/ZPublisher/BaseRequest.py
+116
-134
lib/python/ZPublisher/BeforeTraverse.py
lib/python/ZPublisher/BeforeTraverse.py
+113
-0
lib/python/ZPublisher/HTTPRequest.py
lib/python/ZPublisher/HTTPRequest.py
+71
-43
No files found.
lib/python/OFS/SimpleItem.py
View file @
c75f735c
...
@@ -89,8 +89,8 @@ Aqueduct database adapters, etc.
...
@@ -89,8 +89,8 @@ Aqueduct database adapters, etc.
This module can also be used as a simple template for implementing new
This module can also be used as a simple template for implementing new
item types.
item types.
$Id: SimpleItem.py,v 1.7
5 2000/06/01 17:29:37 jim
Exp $'''
$Id: SimpleItem.py,v 1.7
6 2000/06/09 23:57:46 evan
Exp $'''
__version__
=
'$Revision: 1.7
5
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.7
6
$'
[
11
:
-
2
]
import
regex
,
sys
,
Globals
,
App
.
Management
,
Acquisition
,
App
.
Undo
import
regex
,
sys
,
Globals
,
App
.
Management
,
Acquisition
,
App
.
Undo
import
AccessControl.Role
,
AccessControl
.
Owned
,
App
.
Common
import
AccessControl.Role
,
AccessControl
.
Owned
,
App
.
Common
...
@@ -143,7 +143,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs,
...
@@ -143,7 +143,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs,
# Default propertysheet info:
# Default propertysheet info:
__propsets__
=
()
__propsets__
=
()
manage_options
=
(
manage_options
=
(
App
.
Undo
.
UndoSupport
.
manage_options
App
.
Undo
.
UndoSupport
.
manage_options
+
AccessControl
.
Owned
.
Owned
.
manage_options
+
AccessControl
.
Owned
.
Owned
.
manage_options
...
@@ -338,14 +338,19 @@ class Item(Base, Resource, CopySource, App.Management.Tabs,
...
@@ -338,14 +338,19 @@ class Item(Base, Resource, CopySource, App.Management.Tabs,
return
1
return
1
def
absolute_url
(
self
,
relative
=
0
):
def
absolute_url
(
self
,
relative
=
0
):
id
=
quote
(
self
.
id
)
req
=
self
.
REQUEST
rpp
=
req
.
get
(
'VirtualRootPhysicalPath'
,
(
''
,))
p
=
getattr
(
self
,
'aq_inner'
,
None
)
spp
=
self
.
getPhysicalPath
()
if
p
is
not
None
:
i
=
0
url
=
p
.
aq_parent
.
absolute_url
(
relative
)
for
name
in
rpp
[:
len
(
spp
)]:
if
url
:
id
=
url
+
'/'
+
id
if
spp
[
i
]
==
name
:
i
=
i
+
1
return
id
else
:
break
path
=
map
(
quote
,
spp
[
i
:])
if
relative
:
# Deprecated - use getPhysicalPath
return
join
(
path
,
'/'
)
return
join
([
req
[
'SERVER_URL'
]]
+
req
.
_script
+
path
,
'/'
)
def
getPhysicalPath
(
self
):
def
getPhysicalPath
(
self
):
'''Returns a path (an immutable sequence of strings)
'''Returns a path (an immutable sequence of strings)
...
@@ -462,14 +467,20 @@ class Item_w__name__(Item):
...
@@ -462,14 +467,20 @@ class Item_w__name__(Item):
self
.
__name__
=
id
self
.
__name__
=
id
def
absolute_url
(
self
,
relative
=
0
):
def
absolute_url
(
self
,
relative
=
0
):
id
=
quote
(
self
.
__name__
)
req
=
self
.
REQUEST
rpp
=
req
.
get
(
'VirtualRootPhysicalPath'
,
(
''
,))
p
=
getattr
(
self
,
'aq_inner'
,
None
)
spp
=
self
.
getPhysicalPath
()
if
p
is
not
None
:
i
=
0
url
=
p
.
aq_parent
.
absolute_url
(
relative
)
for
name
in
rpp
[:
len
(
spp
)]:
if
url
:
id
=
url
+
'/'
+
id
if
spp
[
i
]
==
name
:
i
=
i
+
1
return
id
else
:
break
path
=
map
(
quote
,
spp
[
i
:])
if
relative
:
# This is useful for physical path relative to a VirtualRoot
return
join
(
path
,
'/'
)
return
join
([
req
[
'SERVER_URL'
]]
+
req
.
_script
+
path
,
'/'
)
def
getPhysicalPath
(
self
):
def
getPhysicalPath
(
self
):
'''Returns a path (an immutable sequence of strings)
'''Returns a path (an immutable sequence of strings)
...
...
lib/python/ZPublisher/BaseRequest.py
View file @
c75f735c
...
@@ -82,7 +82,7 @@
...
@@ -82,7 +82,7 @@
# attributions are listed in the accompanying credits file.
# attributions are listed in the accompanying credits file.
#
#
##############################################################################
##############################################################################
__version__
=
'$Revision: 1.2
6
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.2
7
$'
[
11
:
-
2
]
from
string
import
join
,
split
,
find
,
rfind
,
lower
,
upper
from
string
import
join
,
split
,
find
,
rfind
,
lower
,
upper
from
urllib
import
quote
from
urllib
import
quote
...
@@ -247,7 +247,7 @@ class BaseRequest:
...
@@ -247,7 +247,7 @@ class BaseRequest:
del
clean
[
-
1
]
del
clean
[
-
1
]
else
:
clean
.
append
(
item
)
else
:
clean
.
append
(
item
)
path
=
clean
path
=
clean
# How did this request come in? (HTTP GET, PUT, POST, etc.)
# How did this request come in? (HTTP GET, PUT, POST, etc.)
method
=
req_method
=
upper
(
request_get
(
'REQUEST_METHOD'
,
'GET'
))
method
=
req_method
=
upper
(
request_get
(
'REQUEST_METHOD'
,
'GET'
))
...
@@ -257,147 +257,130 @@ class BaseRequest:
...
@@ -257,147 +257,130 @@ class BaseRequest:
if
method
==
'GET'
or
method
==
'POST'
:
if
method
==
'GET'
or
method
==
'POST'
:
method
=
'index_html'
method
=
'index_html'
else
:
baseflag
=
1
else
:
baseflag
=
1
URL
=
request
[
'URL'
]
parents
=
request
[
'PARENTS'
]
parents
=
request
[
'PARENTS'
]
object
=
parents
[
-
1
]
object
=
parents
[
-
1
]
del
parents
[:]
del
parents
[:]
roles
=
getattr
(
object
,
'__roles__'
,
UNSPECIFIED_ROLES
)
# if the top object has a __bobo_traverse__ method, then use it
# to possibly traverse to an alternate top-level object.
if
hasattr
(
object
,
'__bobo_traverse__'
):
try
:
object
=
object
.
__bobo_traverse__
(
request
)
except
:
pass
if
not
path
and
not
method
:
return
response
.
forbiddenError
(
self
[
'URL'
])
# Traverse the URL to find the object:
if
hasattr
(
object
,
'__of__'
):
# Try to bind the top-level object to the request
# This is how you get 'self.REQUEST'
object
=
object
.
__of__
(
RequestContainer
(
REQUEST
=
request
))
parents
.
append
(
object
)
steps
=
self
.
steps
self
.
_steps
=
_steps
=
map
(
quote
,
steps
)
path
.
reverse
()
pop
=
path
.
pop
request
[
'TraversalRequestNameStack'
]
=
request
.
path
=
path
entry_name
=
''
try
:
try
:
# We build parents in the wrong order, so we
# We build parents in the wrong order, so we
# need to make sure we reverse it when we're doe.
# need to make sure we reverse it when we're doe.
roles
=
getattr
(
object
,
'__roles__'
,
UNSPECIFIED_ROLES
)
while
1
:
bpth
=
getattr
(
object
,
'__before_publishing_traverse__'
,
None
)
# if the top object has a __bobo_traverse__ method, then use it
if
bpth
is
not
None
:
# to possibly traverse to an alternate top-level object.
bpth
(
object
,
self
)
if
hasattr
(
object
,
'__bobo_traverse__'
):
# Check for method:
try
:
object
=
object
.
__bobo_traverse__
(
request
)
if
path
:
except
:
pass
entry_name
=
pop
()
elif
(
method
and
hasattr
(
object
,
method
)
# Get default object if no path was specified:
and
entry_name
!=
method
if
not
path
:
and
getattr
(
object
,
method
)
is
not
None
):
if
not
method
:
return
response
.
forbiddenError
(
entry_name
)
request
.
_hacked_path
=
1
entry_name
=
method
entry_name
=
method
try
:
else
:
if
hasattr
(
object
,
entry_name
):
if
(
hasattr
(
object
,
'__call__'
)
and
response
.
setBase
(
URL
)
hasattr
(
object
.
__call__
,
'__roles__'
)):
path
=
[
entry_name
]
roles
=
object
.
__call__
.
__roles__
else
:
if
request
.
_hacked_path
:
try
:
i
=
rfind
(
URL
,
'/'
)
if
object
.
has_key
(
entry_name
):
if
i
>
0
:
response
.
setBase
(
URL
[:
i
])
path
=
[
entry_name
]
break
except
:
pass
if
not
entry_name
:
continue
except
:
pass
step
=
quote
(
entry_name
)
_steps
.
append
(
step
)
# Traverse the URL to find the object:
request
[
'URL'
]
=
URL
=
'%s/%s'
%
(
request
[
'URL'
],
step
)
if
hasattr
(
object
,
'__of__'
):
got
=
0
# Try to bind the top-level object to the request
if
entry_name
[:
1
]
==
'_'
:
# This is how you get 'self.REQUEST'
if
debug_mode
:
object
=
object
.
__of__
(
RequestContainer
(
REQUEST
=
request
))
return
response
.
debugError
(
"Object name begins with an underscore at: %s"
%
URL
)
steps
=
self
.
steps
else
:
return
response
.
forbiddenError
(
entry_name
)
path
.
reverse
()
pop
=
path
.
pop
if
hasattr
(
object
,
'__bobo_traverse__'
):
subobject
=
object
.
__bobo_traverse__
(
request
,
entry_name
)
# request['path']=path
if
type
(
subobject
)
is
type
(())
and
len
(
subobject
)
>
1
:
# Add additional parents into the path
while
path
:
parents
[
-
1
:]
=
subobject
[:
-
1
]
entry_name
=
pop
()
object
,
subobject
=
subobject
[
-
2
:]
URL
=
"%s/%s"
%
(
URL
,
quote
(
entry_name
))
else
:
got
=
0
# Can't find it? XXX
if
entry_name
:
if
entry_name
[:
1
]
==
'_'
:
if
debug_mode
:
return
response
.
debugError
(
"Object name begins with an underscore at: %s"
%
URL
)
else
:
return
response
.
forbiddenError
(
entry_name
)
if
hasattr
(
object
,
'__bobo_traverse__'
):
request
[
'URL'
]
=
URL
subobject
=
object
.
__bobo_traverse__
(
request
,
entry_name
)
if
type
(
subobject
)
is
type
(())
and
len
(
subobject
)
>
1
:
# Add additional parents into the path
while
len
(
subobject
)
>
2
:
parents
.
append
(
subobject
[
0
])
subobject
=
subobject
[
1
:]
object
,
subobject
=
subobject
else
:
try
:
# Note - this is necessary to support
# things like DAV. We have to make sure
# that the target object is not acquired
# if the request_method is other than GET
# or POST. Otherwise, you could never use
# PUT to add a new object named 'test' if
# an object 'test' existed above it in the
# heirarchy -- you'd always get the
# existing object :(
if
baseflag
and
hasattr
(
object
,
'aq_base'
):
if
hasattr
(
object
.
aq_base
,
entry_name
):
subobject
=
getattr
(
object
,
entry_name
)
else
:
raise
AttributeError
,
entry_name
else
:
subobject
=
getattr
(
object
,
entry_name
)
except
AttributeError
:
got
=
1
try
:
subobject
=
object
[
entry_name
]
except
(
KeyError
,
IndexError
,
TypeError
,
AttributeError
):
if
debug_mode
:
return
response
.
debugError
(
"Cannot locate object at: %s"
%
URL
)
else
:
return
response
.
notFoundError
(
URL
)
try
:
try
:
try
:
doc
=
subobject
.
__doc__
except
:
doc
=
getattr
(
object
,
entry_name
+
'__doc__'
)
# Note - this is necessary to support
if
not
doc
:
raise
AttributeError
,
entry_name
# things like DAV. We have to make sure
except
:
# that the target object is not acquired
if
debug_mode
:
# if the request_method is other than GET
return
response
.
debugError
(
# or POST. Otherwise, you could never use
"Missing doc string at: %s"
%
URL
)
# PUT to add a new object named 'test' if
else
:
return
response
.
notFoundError
(
"%s"
%
(
URL
))
# an object 'test' existed above it in the
# heirarchy -- you'd always get the
r
=
getattr
(
subobject
,
'__roles__'
,
UNSPECIFIED_ROLES
)
# existing object :(
if
r
is
not
UNSPECIFIED_ROLES
:
roles
=
r
if
baseflag
and
hasattr
(
object
,
'aq_base'
):
elif
not
got
:
if
hasattr
(
object
.
aq_base
,
entry_name
):
roles
=
getattr
(
subobject
,
entry_name
+
'__roles__'
,
roles
)
subobject
=
getattr
(
object
,
entry_name
)
else
:
raise
AttributeError
,
entry_name
else
:
subobject
=
getattr
(
object
,
entry_name
)
except
AttributeError
:
got
=
1
try
:
subobject
=
object
[
entry_name
]
except
(
KeyError
,
IndexError
,
TypeError
,
AttributeError
):
if
debug_mode
:
return
response
.
debugError
(
"Cannot locate object at: %s"
%
URL
)
else
:
return
response
.
notFoundError
(
URL
)
# Promote subobject to object
try
:
parents
.
append
(
object
)
try
:
doc
=
subobject
.
__doc__
object
=
subobject
except
:
doc
=
getattr
(
object
,
entry_name
+
'__doc__'
)
if
not
doc
:
raise
AttributeError
,
entry_name
steps
.
append
(
entry_name
)
except
:
if
debug_mode
:
# Check for method:
return
response
.
debugError
(
if
not
path
:
"Missing doc string at: %s"
%
URL
)
if
(
method
and
hasattr
(
object
,
method
)
else
:
return
response
.
notFoundError
(
"%s"
%
URL
)
and
entry_name
!=
method
and
getattr
(
object
,
method
)
is
not
None
r
=
getattr
(
subobject
,
'__roles__'
,
UNSPECIFIED_ROLES
)
):
if
r
is
not
UNSPECIFIED_ROLES
:
request
.
_hacked_path
=
1
roles
=
r
path
.
append
(
method
)
elif
not
got
:
else
:
roles
=
getattr
(
subobject
,
entry_name
+
'__roles__'
,
roles
)
if
(
hasattr
(
object
,
'__call__'
)
and
hasattr
(
object
.
__call__
,
'__roles__'
)):
# Promote subobject to object
roles
=
object
.
__call__
.
__roles__
object
=
subobject
if
request
.
_hacked_path
:
i
=
rfind
(
URL
,
'/'
)
if
i
>
0
:
response
.
setBase
(
URL
[:
i
])
except
:
# Save the last found object before handling the exception.
if
object
is
not
None
:
parents
.
append
(
object
)
parents
.
append
(
object
)
steps
.
append
(
entry_name
)
finally
:
parents
.
reverse
()
parents
.
reverse
()
raise
parents
.
pop
(
0
)
# Get rid of final method object
parents
.
reverse
()
# Do authorization checks
# Do authorization checks
user
=
groups
=
None
user
=
groups
=
None
i
=
0
i
=
0
...
@@ -459,11 +442,10 @@ class BaseRequest:
...
@@ -459,11 +442,10 @@ class BaseRequest:
if
user
is
None
and
roles
!=
UNSPECIFIED_ROLES
:
if
user
is
None
and
roles
!=
UNSPECIFIED_ROLES
:
response
.
unauthorized
()
response
.
unauthorized
()
steps
=
join
(
steps
[:
-
i
],
'/'
)
if
user
is
not
None
:
if
user
is
not
None
:
if
validated_hook
is
not
None
:
validated_hook
(
self
,
user
)
if
validated_hook
is
not
None
:
validated_hook
(
self
,
user
)
request
[
'AUTHENTICATED_USER'
]
=
user
request
[
'AUTHENTICATED_USER'
]
=
user
request
[
'AUTHENTICATION_PATH'
]
=
steps
request
[
'AUTHENTICATION_PATH'
]
=
join
(
steps
[:
-
i
],
'/'
)
# Remove http request method from the URL.
# Remove http request method from the URL.
request
[
'URL'
]
=
URL
request
[
'URL'
]
=
URL
...
@@ -480,7 +462,7 @@ class BaseRequest:
...
@@ -480,7 +462,7 @@ class BaseRequest:
def
old_validation
(
groups
,
request
,
auth
,
def
old_validation
(
groups
,
request
,
auth
,
roles
=
UNSPECIFIED_ROLES
):
roles
=
UNSPECIFIED_ROLES
):
...
...
lib/python/ZPublisher/BeforeTraverse.py
0 → 100644
View file @
c75f735c
"""BeforeTraverse interface and helper classes"""
# Interface
def
registerBeforeTraverse
(
container
,
object
,
app_handle
,
priority
=
99
):
"""Register an object to be called before a container is traversed.
'app_handle' should be a string or other hashable value that
distinguishes the application of this object, and which must
be used in order to unregister the object.
If the container will be pickled, the object must be a callable class
instance, not a function or method.
'priority' is optional, and determines the relative order in which
registered objects will be called.
"""
btr
=
getattr
(
container
,
'__before_traverse__'
,
{})
btr
[(
priority
,
app_handle
)]
=
object
rewriteBeforeTraverse
(
container
,
btr
)
def
unregisterBeforeTraverse
(
container
,
app_handle
):
"""Unregister a __before_traverse__ hook object, given its 'app_handle'.
Returns a list of unregistered objects."""
btr
=
getattr
(
container
,
'__before_traverse__'
,
{})
objects
=
[]
for
k
in
btr
.
keys
():
if
k
[
1
]
==
app_handle
:
objects
.
append
(
btr
[
k
])
del
btr
[
k
]
if
objects
:
rewriteBeforeTraverse
(
container
,
btr
)
return
objects
def
queryBeforeTraverse
(
container
,
app_handle
):
"""Find __before_traverse__ hook objects, given an 'app_handle'.
Returns a list of (priority, object) pairs."""
btr
=
getattr
(
container
,
'__before_traverse__'
,
{})
objects
=
[]
for
k
in
btr
.
keys
():
if
k
[
1
]
==
app_handle
:
objects
.
append
((
k
[
0
],
btr
[
k
]))
return
objects
# Implementation tools
def
rewriteBeforeTraverse
(
container
,
btr
):
"""Rewrite the list of __before_traverse__ hook objects"""
container
.
__before_traverse__
=
btr
hookname
=
'__before_publishing_traverse__'
dic
=
hasattr
(
container
.
__class__
,
hookname
)
bpth
=
container
.
__dict__
.
get
(
hookname
,
None
)
if
isinstance
(
bpth
,
MultiHook
):
bpth
=
bpth
.
_prior
bpth
=
MultiHook
(
hookname
,
bpth
,
dic
)
setattr
(
container
,
hookname
,
bpth
)
keys
=
btr
.
keys
()
keys
.
sort
()
for
key
in
keys
:
bpth
.
add
(
btr
[
key
])
class
MultiHook
:
"""Class used to multiplex hook.
MultiHook calls the named hook from the class of the container, then
the prior hook, then all the hooks in its list.
"""
def
__init__
(
self
,
hookname
,
prior
,
defined_in_class
):
self
.
_hookname
=
hookname
self
.
_prior
=
prior
self
.
_defined_in_class
=
defined_in_class
self
.
_list
=
[]
def
__call__
(
self
,
container
,
request
):
if
self
.
_defined_in_class
:
# Assume it's an unbound method
getattr
(
container
.
__class__
,
self
.
_hookname
)(
container
,
request
)
prior
=
self
.
_prior
if
prior
is
not
None
:
prior
(
container
,
request
)
for
cob
in
self
.
_list
:
cob
(
container
,
request
)
def
add
(
self
,
cob
):
self
.
_list
.
append
(
cob
)
# Helper class
class
NameCaller
:
"""Class used to proxy sibling objects by name.
When called with a container and request object, it gets the named
attribute from the container and calls it. If the name is not
found, it fails silently.
>>> registerBeforeTraverse(folder, NameCaller('preop'), 'XApp')
"""
def
__init__
(
self
,
name
):
self
.
name
=
name
def
__call__
(
self
,
container
,
request
):
try
:
meth
=
getattr
(
container
,
self
.
name
)
except
AttributeError
:
return
args
=
getattr
(
getattr
(
meth
,
'func_code'
,
None
),
'co_argcount'
,
2
)
apply
(
meth
,
(
container
,
request
,
None
)[:
args
])
lib/python/ZPublisher/HTTPRequest.py
View file @
c75f735c
...
@@ -83,14 +83,14 @@
...
@@ -83,14 +83,14 @@
#
#
##############################################################################
##############################################################################
__version__
=
'$Revision: 1.3
4
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.3
5
$'
[
11
:
-
2
]
import
regex
,
sys
,
os
,
string
import
regex
,
sys
,
os
,
string
,
urllib
from
string
import
lower
,
atoi
,
rfind
,
split
,
strip
,
join
,
upper
,
find
from
string
import
lower
,
atoi
,
rfind
,
split
,
strip
,
join
,
upper
,
find
from
BaseRequest
import
BaseRequest
from
BaseRequest
import
BaseRequest
from
HTTPResponse
import
HTTPResponse
from
HTTPResponse
import
HTTPResponse
from
cgi
import
FieldStorage
from
cgi
import
FieldStorage
from
urllib
import
quote
,
unquote
from
urllib
import
quote
,
unquote
,
splittype
,
splitport
from
Converters
import
get_converter
from
Converters
import
get_converter
from
maybe_lock
import
allocate_lock
from
maybe_lock
import
allocate_lock
xmlrpc
=
None
# Placeholder for module that we'll import if we have to.
xmlrpc
=
None
# Placeholder for module that we'll import if we have to.
...
@@ -120,6 +120,8 @@ hide_key={'HTTP_AUTHORIZATION':1,
...
@@ -120,6 +120,8 @@ hide_key={'HTTP_AUTHORIZATION':1,
'HTTP_CGI_AUTHORIZATION'
:
1
,
'HTTP_CGI_AUTHORIZATION'
:
1
,
}.
has_key
}.
has_key
default_port
=
{
'http'
:
'80'
,
'https'
:
'443'
}
_marker
=
[]
_marker
=
[]
class
HTTPRequest
(
BaseRequest
):
class
HTTPRequest
(
BaseRequest
):
"""
\
"""
\
...
@@ -186,19 +188,46 @@ class HTTPRequest(BaseRequest):
...
@@ -186,19 +188,46 @@ class HTTPRequest(BaseRequest):
return
r
return
r
def
setSite
(
self
,
base
=
None
):
def
setServerURL
(
self
,
protocol
=
None
,
hostname
=
None
,
port
=
None
):
""" blah """
""" Set the parts of generated URLs. """
if
base
is
not
None
:
other
=
self
.
other
self
.
script
=
self
.
base
=
base
server_url
=
other
.
get
(
'SERVER_URL'
,
''
)
if
protocol
is
None
and
hostname
is
None
and
port
is
None
:
# reset the URL
return
server_url
self
.
other
[
'URL'
]
=
self
.
script
oldprotocol
,
oldhost
=
splittype
(
server_url
)
# clear the 'cache' of URLx and BASEx
oldhostname
,
oldport
=
splitport
(
oldhost
[
2
:])
if
protocol
is
None
:
protocol
=
oldprotocol
if
hostname
is
None
:
hostname
=
oldhostname
if
port
is
None
:
port
=
oldport
if
(
port
is
None
or
default_port
[
protocol
]
==
port
):
host
=
hostname
else
:
host
=
hostname
+
':'
+
port
server_url
=
other
[
'SERVER_URL'
]
=
'%s://%s'
%
(
protocol
,
host
)
self
.
_resetURLS
()
return
server_url
def
setVirtualRoot
(
self
,
path
,
hard
=
0
):
""" Treat the current publishing object as a VirtualRoot """
other
=
self
.
other
if
type
(
path
)
is
type
(
''
):
path
=
filter
(
None
,
split
(
path
,
'/'
))
self
.
_script
[:]
=
map
(
quote
,
path
)
del
self
.
_steps
[:]
parents
=
other
[
'PARENTS'
]
if
hard
:
del
parents
[:
-
1
]
other
[
'VirtualRootPhysicalPath'
]
=
parents
[
-
1
].
getPhysicalPath
()
self
.
_resetURLS
()
def
_resetURLS
(
self
):
other
=
self
.
other
other
[
'URL'
]
=
join
([
other
[
'SERVER_URL'
]]
+
self
.
_script
+
self
.
_steps
,
'/'
)
for
x
in
self
.
_urls
:
for
x
in
self
.
_urls
:
del
self
.
other
[
x
]
del
self
.
other
[
x
]
self
.
_urls
=
()
del
self
.
other
[
'PARENTS'
][:]
def
__init__
(
self
,
stdin
,
environ
,
response
,
clean
=
0
):
def
__init__
(
self
,
stdin
,
environ
,
response
,
clean
=
0
):
self
.
_orig_env
=
environ
self
.
_orig_env
=
environ
...
@@ -221,11 +250,16 @@ class HTTPRequest(BaseRequest):
...
@@ -221,11 +250,16 @@ class HTTPRequest(BaseRequest):
other
=
self
.
other
=
{
'RESPONSE'
:
response
}
other
=
self
.
other
=
{
'RESPONSE'
:
response
}
self
.
form
=
{}
self
.
form
=
{}
self
.
steps
=
[]
self
.
steps
=
[]
self
.
_steps
=
[]
################################################################
################################################################
# Get base info first. This isn't likely to cause
# Get base info first. This isn't likely to cause
# errors and might be useful to error handlers.
# errors and might be useful to error handlers.
b
=
script
=
strip
(
get_env
(
'SCRIPT_NAME'
,
''
))
b
=
script
=
strip
(
get_env
(
'SCRIPT_NAME'
,
''
))
# _script and the other _names are meant for URL construction
self
.
_script
=
map
(
quote
,
filter
(
None
,
split
(
script
,
'/'
)))
while
b
and
b
[
-
1
]
==
'/'
:
b
=
b
[:
-
1
]
while
b
and
b
[
-
1
]
==
'/'
:
b
=
b
[:
-
1
]
p
=
rfind
(
b
,
'/'
)
p
=
rfind
(
b
,
'/'
)
if
p
>=
0
:
b
=
b
[:
p
+
1
]
if
p
>=
0
:
b
=
b
[:
p
+
1
]
...
@@ -234,23 +268,24 @@ class HTTPRequest(BaseRequest):
...
@@ -234,23 +268,24 @@ class HTTPRequest(BaseRequest):
server_url
=
get_env
(
'SERVER_URL'
,
None
)
server_url
=
get_env
(
'SERVER_URL'
,
None
)
if
server_url
is
not
None
:
if
server_url
is
not
None
:
server_url
=
strip
(
server_url
)
other
[
'SERVER_URL'
]
=
server_url
=
strip
(
server_url
)
else
:
else
:
if
have_env
(
'HTTPS'
)
and
(
if
have_env
(
'HTTPS'
)
and
(
environ
[
'HTTPS'
]
==
"on"
or
environ
[
'HTTPS'
]
==
"ON"
):
environ
[
'HTTPS'
]
==
"on"
or
environ
[
'HTTPS'
]
==
"ON"
):
server_url
=
'https://
'
protocol
=
'https
'
elif
(
have_env
(
'SERVER_PORT_SECURE'
)
and
elif
(
have_env
(
'SERVER_PORT_SECURE'
)
and
environ
[
'SERVER_PORT_SECURE'
]
==
"1"
):
environ
[
'SERVER_PORT_SECURE'
]
==
"1"
):
server_url
=
'https://
'
protocol
=
'https
'
else
:
server_url
=
'http://
'
else
:
protocol
=
'http
'
if
have_env
(
'HTTP_HOST'
):
if
have_env
(
'HTTP_HOST'
):
server_url
=
server_url
+
strip
(
environ
[
'HTTP_HOST'
])
host
=
strip
(
environ
[
'HTTP_HOST'
])
hostname
,
port
=
splitport
(
host
)
else
:
else
:
server_url
=
server_url
+
strip
(
environ
[
'SERVER_NAME'
])
hostname
=
strip
(
environ
[
'SERVER_NAME'
])
server_port
=
environ
[
'SERVER_PORT'
]
port
=
environ
[
'SERVER_PORT'
]
if
server_port
!=
'80'
:
server_url
=
server_url
+
':'
+
server_port
self
.
setServerURL
(
protocol
=
protocol
,
hostname
=
hostname
,
port
=
port
)
other
[
'SERVER_URL'
]
=
server_url
server_url
=
other
[
'SERVER_URL'
]
if
server_url
[
-
1
:]
==
'/'
:
server_url
=
server_url
[:
-
1
]
if
server_url
[
-
1
:]
==
'/'
:
server_url
=
server_url
[:
-
1
]
...
@@ -437,7 +472,7 @@ class HTTPRequest(BaseRequest):
...
@@ -437,7 +472,7 @@ class HTTPRequest(BaseRequest):
reclist
.
reverse
()
reclist
.
reverse
()
if
not
hasattr
(
x
,
attr
):
if
not
hasattr
(
x
,
attr
):
#If the attribute does not
#If the attribute does not
#exist, set
it
#exist, setit
if
flags
&
SEQUENCE
:
item
=
[
item
]
if
flags
&
SEQUENCE
:
item
=
[
item
]
reclist
.
remove
(
x
)
reclist
.
remove
(
x
)
setattr
(
x
,
attr
,
item
)
setattr
(
x
,
attr
,
item
)
...
@@ -722,13 +757,11 @@ class HTTPRequest(BaseRequest):
...
@@ -722,13 +757,11 @@ class HTTPRequest(BaseRequest):
return
other
[
key
]
return
other
[
key
]
if
key
[:
1
]
==
'U'
and
URLmatch
(
key
)
>=
0
:
if
key
[:
1
]
==
'U'
and
URLmatch
(
key
)
>=
0
:
n
=
atoi
(
key
[
3
:])
path
=
self
.
_script
+
self
.
_steps
URL
=
other
[
'URL'
]
n
=
len
(
path
)
-
atoi
(
key
[
3
:])
for
i
in
range
(
0
,
n
):
if
n
<
0
:
l
=
rfind
(
URL
,
'/'
)
raise
KeyError
,
key
if
l
>=
0
:
URL
=
URL
[:
l
]
URL
=
join
([
other
[
'SERVER_URL'
]]
+
path
[:
n
],
'/'
)
else
:
raise
KeyError
,
key
if
len
(
URL
)
<
len
(
self
.
base
)
and
n
>
1
:
raise
KeyError
,
key
other
[
key
]
=
URL
other
[
key
]
=
URL
self
.
_urls
=
self
.
_urls
+
(
key
,)
self
.
_urls
=
self
.
_urls
+
(
key
,)
return
URL
return
URL
...
@@ -743,20 +776,17 @@ class HTTPRequest(BaseRequest):
...
@@ -743,20 +776,17 @@ class HTTPRequest(BaseRequest):
if
key
[:
1
]
==
'B'
:
if
key
[:
1
]
==
'B'
:
if
BASEmatch
(
key
)
>=
0
:
if
BASEmatch
(
key
)
>=
0
:
n
=
atoi
(
key
[
4
:])
path
=
self
.
_steps
n
=
atoi
(
key
[
4
:])
if
n
:
if
n
:
n
=
n
-
1
n
=
n
-
1
if
len
(
path
)
<
n
:
if
len
(
self
.
steps
)
<
n
:
raise
KeyError
,
key
raise
KeyError
,
key
v
=
self
.
script
v
=
self
.
_script
+
path
[:
n
]
while
v
[
-
1
:]
==
'/'
:
v
=
v
[:
-
1
]
v
=
join
([
v
]
+
self
.
steps
[:
n
],
'/'
)
else
:
else
:
v
=
self
.
base
v
=
self
.
_script
[:
-
1
]
while
v
[
-
1
:]
==
'/'
:
v
=
v
[:
-
1
]
other
[
key
]
=
v
=
join
([
other
[
'SERVER_URL'
]]
+
v
,
'/'
)
other
[
key
]
=
v
self
.
_urls
=
self
.
_urls
+
(
key
,)
self
.
_urls
=
self
.
_urls
+
(
key
,)
return
v
return
v
...
@@ -977,8 +1007,6 @@ def parse_cookie(text,
...
@@ -977,8 +1007,6 @@ def parse_cookie(text,
return apply(parse_cookie,(text[l:],result))
return apply(parse_cookie,(text[l:],result))
import sys
# add class
# add class
class record:
class record:
def __getattr__(self, key, default=None):
def __getattr__(self, key, default=None):
...
...
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