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
6c79cd9d
Commit
6c79cd9d
authored
Apr 07, 2003
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- avoid re-reading more data than necessary
- remove unused imports - misc. cleanup
parent
64db138b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
lib/python/Products/PageTemplates/PageTemplateFile.py
lib/python/Products/PageTemplates/PageTemplateFile.py
+16
-12
No files found.
lib/python/Products/PageTemplates/PageTemplateFile.py
View file @
6c79cd9d
...
...
@@ -15,19 +15,18 @@
Zope object encapsulating a Page Template from the filesystem.
"""
__version__
=
'$Revision: 1.2
5
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.2
6
$'
[
11
:
-
2
]
import
os
,
AccessControl
,
Acquisition
,
sys
import
os
,
AccessControl
from
Globals
import
package_home
,
DevelopmentMode
from
zLOG
import
LOG
,
ERROR
,
INFO
from
Shared.DC.Scripts.Script
import
Script
,
BindingsUI
from
zLOG
import
LOG
,
ERROR
from
Shared.DC.Scripts.Script
import
Script
from
Shared.DC.Scripts.Signature
import
FuncCode
from
AccessControl
import
getSecurityManager
from
OFS.Traversable
import
Traversable
from
PageTemplate
import
PageTemplate
from
Expressions
import
SecureModuleImporter
from
ComputedAttribute
import
ComputedAttribute
from
ExtensionClass
import
Base
from
Acquisition
import
aq_parent
,
aq_inner
from
App.config
import
getConfiguration
...
...
@@ -51,7 +50,7 @@ class PageTemplateFile(Script, PageTemplate, Traversable):
self
.
ZBindings_edit
(
self
.
_default_bindings
)
if
_prefix
is
None
:
_prefix
=
getConfiguration
().
softwarehome
elif
type
(
_prefix
)
is
not
type
(
''
):
elif
not
isinstance
(
_prefix
,
str
):
_prefix
=
package_home
(
_prefix
)
name
=
kw
.
get
(
'__name__'
)
if
name
:
...
...
@@ -91,7 +90,7 @@ class PageTemplateFile(Script, PageTemplate, Traversable):
pass
# Execute the template in a new security context.
security
=
getSecurityManager
()
security
=
getSecurityManager
()
bound_names
[
'user'
]
=
security
.
getUser
()
security
.
addContext
(
self
)
try
:
...
...
@@ -119,15 +118,18 @@ class PageTemplateFile(Script, PageTemplate, Traversable):
return
f
=
open
(
self
.
filename
,
"rb"
)
try
:
text
=
f
.
read
()
finally
:
text
=
f
.
read
(
XML_PREFIX_MAX_LENGTH
)
except
:
f
.
close
()
raise
t
=
sniff_type
(
text
)
if
t
!=
"text/xml"
and
"
\
r
"
in
text
:
if
t
!=
"text/xml"
:
# For HTML, we really want the file read in text mode:
f
=
open
(
self
.
filename
)
text
=
f
.
read
()
f
.
close
()
f
=
open
(
self
.
filename
)
text
=
''
text
+=
f
.
read
()
f
.
close
()
self
.
pt_edit
(
text
,
t
)
self
.
_cook
()
if
self
.
_v_errors
:
...
...
@@ -180,6 +182,8 @@ XML_PREFIXES = [
"
\
xff
\
xfe
<
\
0
?
\
0
x
\
0
m
\
0
l
\
0
"
,
# utf-16 little endian w/ byte order mark
]
XML_PREFIX_MAX_LENGTH
=
max
(
map
(
len
,
XML_PREFIXES
))
def
sniff_type
(
text
):
for
prefix
in
XML_PREFIXES
:
if
text
.
startswith
(
prefix
):
...
...
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