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
482a309b
Commit
482a309b
authored
Jul 30, 2011
by
Nikolay Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
micro optimizations
parent
4dc2e280
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
30 deletions
+27
-30
src/OFS/PropertyManager.py
src/OFS/PropertyManager.py
+3
-2
src/OFS/Traversable.py
src/OFS/Traversable.py
+14
-10
src/ZPublisher/HTTPRequest.py
src/ZPublisher/HTTPRequest.py
+10
-18
No files found.
src/OFS/PropertyManager.py
View file @
482a309b
...
@@ -144,8 +144,9 @@ class PropertyManager(Base, ElementWithAttributes):
...
@@ -144,8 +144,9 @@ class PropertyManager(Base, ElementWithAttributes):
Returns the optional second argument or None if no such property is
Returns the optional second argument or None if no such property is
found.
found.
"""
"""
if
self
.
hasProperty
(
id
):
for
p
in
self
.
_properties
:
return
getattr
(
self
,
id
)
if
id
==
p
[
'id'
]:
return
getattr
(
self
,
id
)
return
d
return
d
security
.
declareProtected
(
access_contents_information
,
'getPropertyType'
)
security
.
declareProtected
(
access_contents_information
,
'getPropertyType'
)
...
...
src/OFS/Traversable.py
View file @
482a309b
...
@@ -39,6 +39,7 @@ from zope.traversing.namespace import namespaceLookup
...
@@ -39,6 +39,7 @@ from zope.traversing.namespace import namespaceLookup
from
zope.traversing.namespace
import
nsParse
from
zope.traversing.namespace
import
nsParse
_marker
=
object
()
_marker
=
object
()
NullResource
=
None
class
Traversable
:
class
Traversable
:
...
@@ -142,30 +143,29 @@ class Traversable:
...
@@ -142,30 +143,29 @@ class Traversable:
If true, then all of the objects along the path are validated with
If true, then all of the objects along the path are validated with
the security machinery. Usually invoked using restrictedTraverse().
the security machinery. Usually invoked using restrictedTraverse().
"""
"""
from
webdav.NullResource
import
NullResource
if
not
path
:
if
not
path
:
return
self
return
self
if
isinstance
(
path
,
str
)
:
if
type
(
path
)
is
str
:
# Unicode paths are not allowed
# Unicode paths are not allowed
path
=
path
.
split
(
'/'
)
path
=
path
.
split
(
'/'
)
else
:
else
:
path
=
list
(
path
)
path
=
list
(
path
)
REQUEST
=
{
'TraversalRequestNameStack'
:
path
}
REQUEST
=
{
'TraversalRequestNameStack'
:
path
}
path
.
reverse
()
#
path.reverse()
path_pop
=
path
.
pop
path_pop
=
path
.
pop
if
len
(
path
)
>
1
and
not
path
[
0
]:
if
len
(
path
)
>
1
and
not
path
[
-
1
]:
# Remove trailing slash
# Remove trailing slash
path_pop
(
0
)
path_pop
()
if
restricted
:
if
restricted
:
validate
=
getSecurityManager
().
validate
validate
=
getSecurityManager
().
validate
if
not
path
[
-
1
]:
if
not
path
[
0
]:
# If the path starts with an empty string, go to the root first.
# If the path starts with an empty string, go to the root first.
path_pop
()
path_pop
(
0
)
obj
=
self
.
getPhysicalRoot
()
obj
=
self
.
getPhysicalRoot
()
if
restricted
:
if
restricted
:
validate
(
None
,
None
,
None
,
obj
)
# may raise Unauthorized
validate
(
None
,
None
,
None
,
obj
)
# may raise Unauthorized
...
@@ -174,8 +174,7 @@ class Traversable:
...
@@ -174,8 +174,7 @@ class Traversable:
resource
=
_marker
resource
=
_marker
try
:
try
:
while
path
:
for
name
in
path
:
name
=
path_pop
()
__traceback_info__
=
path
,
name
__traceback_info__
=
path
,
name
if
name
[
0
]
==
'_'
:
if
name
[
0
]
==
'_'
:
...
@@ -190,7 +189,7 @@ class Traversable:
...
@@ -190,7 +189,7 @@ class Traversable:
obj
=
next
obj
=
next
continue
continue
bobo_traverse
=
getattr
(
obj
,
'__bobo_traverse__'
,
None
)
bobo_traverse
=
None
try
:
try
:
if
name
and
name
[:
1
]
in
'@+'
and
name
!=
'+'
and
nsParse
(
name
)[
1
]:
if
name
and
name
[:
1
]
in
'@+'
and
name
!=
'+'
and
nsParse
(
name
)[
1
]:
# Process URI segment parameters.
# Process URI segment parameters.
...
@@ -209,6 +208,7 @@ class Traversable:
...
@@ -209,6 +208,7 @@ class Traversable:
else
:
else
:
next
=
UseTraversalDefault
# indicator
next
=
UseTraversalDefault
# indicator
try
:
try
:
bobo_traverse
=
getattr
(
obj
,
'__bobo_traverse__'
,
None
)
if
bobo_traverse
is
not
None
:
if
bobo_traverse
is
not
None
:
next
=
bobo_traverse
(
REQUEST
,
name
)
next
=
bobo_traverse
(
REQUEST
,
name
)
if
restricted
:
if
restricted
:
...
@@ -256,6 +256,10 @@ class Traversable:
...
@@ -256,6 +256,10 @@ class Traversable:
# The item lookup may return a NullResource,
# The item lookup may return a NullResource,
# if this is the case we save it and return it
# if this is the case we save it and return it
# if all other lookups fail.
# if all other lookups fail.
global
NullResource
if
NullResource
is
None
:
from
webdav.NullResource
import
NullResource
if
isinstance
(
next
,
NullResource
):
if
isinstance
(
next
,
NullResource
):
resource
=
next
resource
=
next
raise
KeyError
(
name
)
raise
KeyError
(
name
)
...
...
src/ZPublisher/HTTPRequest.py
View file @
482a309b
...
@@ -332,7 +332,7 @@ class HTTPRequest(BaseRequest):
...
@@ -332,7 +332,7 @@ class HTTPRequest(BaseRequest):
self
.
environ
=
environ
self
.
environ
=
environ
get_env
=
environ
.
get
get_env
=
environ
.
get
self
.
response
=
response
self
.
response
=
response
other
=
self
.
other
=
{
'RESPONSE'
:
response
}
other
=
self
.
other
=
{
'RE
QUEST'
:
self
,
'RE
SPONSE'
:
response
}
self
.
form
=
{}
self
.
form
=
{}
self
.
taintedform
=
{}
self
.
taintedform
=
{}
self
.
steps
=
[]
self
.
steps
=
[]
...
@@ -379,9 +379,8 @@ class HTTPRequest(BaseRequest):
...
@@ -379,9 +379,8 @@ class HTTPRequest(BaseRequest):
while
b
and
b
[
0
]
==
'/'
:
while
b
and
b
[
0
]
==
'/'
:
b
=
b
[
1
:]
b
=
b
[
1
:]
server_url
=
get_env
(
'SERVER_URL'
,
None
)
if
'SERVER_URL'
in
environ
:
if
server_url
is
not
None
:
other
[
'SERVER_URL'
]
=
server_url
=
environ
[
'SERVER_URL'
].
strip
()
other
[
'SERVER_URL'
]
=
server_url
=
server_url
.
strip
()
else
:
else
:
if
'HTTPS'
in
environ
and
(
if
'HTTPS'
in
environ
and
(
environ
[
'HTTPS'
]
==
"on"
or
environ
[
'HTTPS'
]
==
"ON"
):
environ
[
'HTTPS'
]
==
"on"
or
environ
[
'HTTPS'
]
==
"ON"
):
...
@@ -1255,8 +1254,6 @@ class HTTPRequest(BaseRequest):
...
@@ -1255,8 +1254,6 @@ class HTTPRequest(BaseRequest):
"""
#"
"""
#"
other
=
self
.
other
other
=
self
.
other
if
key
in
other
:
if
key
in
other
:
if
key
==
'REQUEST'
:
return
self
return
other
[
key
]
return
other
[
key
]
if
key
[:
1
]
==
'U'
:
if
key
[:
1
]
==
'U'
:
...
@@ -1266,7 +1263,7 @@ class HTTPRequest(BaseRequest):
...
@@ -1266,7 +1263,7 @@ class HTTPRequest(BaseRequest):
path
=
self
.
_script
+
self
.
_steps
path
=
self
.
_script
+
self
.
_steps
n
=
len
(
path
)
-
int
(
n
)
n
=
len
(
path
)
-
int
(
n
)
if
n
<
0
:
if
n
<
0
:
r
aise
KeyError
,
key
r
eturn
default
if
pathonly
:
if
pathonly
:
path
=
[
''
]
+
path
[:
n
]
path
=
[
''
]
+
path
[:
n
]
else
:
else
:
...
@@ -1284,9 +1281,6 @@ class HTTPRequest(BaseRequest):
...
@@ -1284,9 +1281,6 @@ class HTTPRequest(BaseRequest):
return
environ
[
key
]
return
environ
[
key
]
return
''
return
''
if
key
==
'REQUEST'
:
return
self
if
key
[:
1
]
==
'B'
:
if
key
[:
1
]
==
'B'
:
match
=
BASEmatch
(
key
)
match
=
BASEmatch
(
key
)
if
match
is
not
None
:
if
match
is
not
None
:
...
@@ -1296,7 +1290,7 @@ class HTTPRequest(BaseRequest):
...
@@ -1296,7 +1290,7 @@ class HTTPRequest(BaseRequest):
if
n
:
if
n
:
n
=
n
-
1
n
=
n
-
1
if
len
(
path
)
<
n
:
if
len
(
path
)
<
n
:
r
aise
KeyError
,
key
r
eturn
default
v
=
self
.
_script
+
path
[:
n
]
v
=
self
.
_script
+
path
[:
n
]
else
:
else
:
...
@@ -1394,12 +1388,10 @@ class HTTPRequest(BaseRequest):
...
@@ -1394,12 +1388,10 @@ class HTTPRequest(BaseRequest):
self
.
_lazies
[
key
]
=
callable
self
.
_lazies
[
key
]
=
callable
def
has_key
(
self
,
key
,
returnTaints
=
0
):
def
has_key
(
self
,
key
,
returnTaints
=
0
):
try
:
v
=
self
.
get
(
key
,
_marker
,
returnTaints
=
returnTaints
)
self
.
__getitem__
(
key
,
returnTaints
=
returnTaints
)
if
v
is
_marker
:
except
:
return
False
return
0
return
True
else
:
return
1
def
keys
(
self
,
returnTaints
=
0
):
def
keys
(
self
,
returnTaints
=
0
):
keys
=
{}
keys
=
{}
...
@@ -1525,7 +1517,7 @@ class HTTPRequest(BaseRequest):
...
@@ -1525,7 +1517,7 @@ class HTTPRequest(BaseRequest):
base64
.
decodestring
(
auth
.
split
()[
-
1
]).
split
(
':'
,
1
)
base64
.
decodestring
(
auth
.
split
()[
-
1
]).
split
(
':'
,
1
)
return
name
,
password
return
name
,
password
def
taintWrapper
(
self
,
enabled
=
TAINTING_ENABLED
):
def
taintWrapper
(
self
,
enabled
=
False
):
return
enabled
and
TaintRequestWrapper
(
self
)
or
self
return
enabled
and
TaintRequestWrapper
(
self
)
or
self
def
shiftNameToApplication
(
self
):
def
shiftNameToApplication
(
self
):
...
...
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