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
9ee89323
Commit
9ee89323
authored
Mar 04, 2008
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix PEP 8 line length violations.
parent
df127f9e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
34 deletions
+77
-34
lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
...thon/Products/PageTemplates/tests/testZopePageTemplate.py
+77
-34
No files found.
lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
View file @
9ee89323
...
...
@@ -18,11 +18,14 @@ from zope.publisher.http import HTTPCharsets
from
Testing.makerequest
import
makerequest
from
Testing.ZopeTestCase
import
ZopeTestCase
,
installProduct
from
Products.PageTemplates.ZopePageTemplate
import
ZopePageTemplate
,
manage_addPageTemplate
from
Products.PageTemplates.utils
import
encodingFromXMLPreamble
,
charsetFromMetaEquiv
from
Products.PageTemplates.ZopePageTemplate
import
ZopePageTemplate
from
Products.PageTemplates.ZopePageTemplate
import
manage_addPageTemplate
from
Products.PageTemplates.utils
import
encodingFromXMLPreamble
from
Products.PageTemplates.utils
import
charsetFromMetaEquiv
from
zope.component
import
provideUtility
from
Products.PageTemplates.interfaces
import
IUnicodeEncodingConflictResolver
from
Products.PageTemplates.unicodeconflictresolver
import
PreferredCharsetResolver
from
Products.PageTemplates.unicodeconflictresolver
\
import
PreferredCharsetResolver
ascii_str
=
'<html><body>hello world</body></html>'
...
...
@@ -50,7 +53,8 @@ html_template_w_header = '''
'''
html_iso_8859_15_w_header
=
html_template_w_header
%
'iso-8859-15'
html_utf8_w_header
=
unicode
(
html_template_w_header
,
'iso-8859-15'
).
encode
(
'utf-8'
)
%
'utf-8'
html_utf8_w_header
=
unicode
(
html_template_w_header
,
'iso-8859-15'
).
encode
(
'utf-8'
)
%
'utf-8'
html_template_wo_header
=
'''
<html>
...
...
@@ -61,7 +65,8 @@ html_template_wo_header = '''
'''
html_iso_8859_15_wo_header
=
html_template_wo_header
html_utf8_wo_header
=
unicode
(
html_template_wo_header
,
'iso-8859-15'
).
encode
(
'utf-8'
)
html_utf8_wo_header
=
unicode
(
html_template_wo_header
,
'iso-8859-15'
).
encode
(
'utf-8'
)
xml_with_upper_attr
=
'''<?xml version="1.0"?>
<foo>
...
...
@@ -84,16 +89,32 @@ class ZPTUtilsTests(unittest.TestCase):
def
testExtractEncodingFromXMLPreamble
(
self
):
extract
=
encodingFromXMLPreamble
self
.
assertEqual
(
extract
(
'<?xml version="1.0" ?>'
),
'utf-8'
)
self
.
assertEqual
(
extract
(
'<?xml encoding="utf-8" version="1.0" ?>'
),
'utf-8'
)
self
.
assertEqual
(
extract
(
'<?xml encoding="UTF-8" version="1.0" ?>'
),
'utf-8'
)
self
.
assertEqual
(
extract
(
'<?xml encoding="ISO-8859-15" version="1.0" ?>'
),
'iso-8859-15'
)
self
.
assertEqual
(
extract
(
'<?xml encoding="iso-8859-15" version="1.0" ?>'
),
'iso-8859-15'
)
self
.
assertEqual
(
extract
(
'<?xml encoding="utf-8" '
'version="1.0" ?>'
),
'utf-8'
)
self
.
assertEqual
(
extract
(
'<?xml encoding="UTF-8" '
'version="1.0" ?>'
),
'utf-8'
)
self
.
assertEqual
(
extract
(
'<?xml encoding="ISO-8859-15" '
'version="1.0" ?>'
),
'iso-8859-15'
)
self
.
assertEqual
(
extract
(
'<?xml encoding="iso-8859-15" '
'version="1.0" ?>'
),
'iso-8859-15'
)
def
testExtractCharsetFromMetaHTTPEquivTag
(
self
):
extract
=
charsetFromMetaEquiv
self
.
assertEqual
(
extract
(
'<html><META http-equiv="content-type" content="text/html; charset=UTF-8"></html>'
),
'utf-8'
)
self
.
assertEqual
(
extract
(
'<html><META http-equiv="content-type" content="text/html; charset=iso-8859-15"></html>'
),
'iso-8859-15'
)
self
.
assertEqual
(
extract
(
'<html><META http-equiv="content-type" content="text/html"></html>'
),
None
)
self
.
assertEqual
(
extract
(
'<html><META http-equiv="content-type" '
'content="text/html; '
'charset=UTF-8"></html>'
),
'utf-8'
)
self
.
assertEqual
(
extract
(
'<html><META http-equiv="content-type" '
'content="text/html; '
'charset=iso-8859-15"></html>'
),
'iso-8859-15'
)
self
.
assertEqual
(
extract
(
'<html><META http-equiv="content-type" '
'content="text/html"></html>'
),
None
)
self
.
assertEqual
(
extract
(
'<html>...<html>'
),
None
)
...
...
@@ -102,62 +123,79 @@ class ZPTUnicodeEncodingConflictResolution(ZopeTestCase):
def
afterSetUp
(
self
):
zope
.
component
.
provideAdapter
(
DefaultTraversable
,
(
None
,))
zope
.
component
.
provideAdapter
(
HTTPCharsets
,
(
None
,))
provideUtility
(
PreferredCharsetResolver
,
IUnicodeEncodingConflictResolver
)
provideUtility
(
PreferredCharsetResolver
,
IUnicodeEncodingConflictResolver
)
def
testISO_8859_15
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
'<div tal:content="python: request.get(
\
'
data
\
'
)" />'
,
text
=
(
'<div tal:content="python: '
'request.get(
\
'
data
\
'
)" />'
),
encoding
=
'ascii'
)
zpt
=
self
.
app
[
'test'
]
self
.
app
.
REQUEST
.
set
(
'HTTP_ACCEPT_CHARSET'
,
'ISO-8859-15,utf-8'
)
self
.
app
.
REQUEST
.
set
(
'data'
,
''
)
result
=
zpt
.
pt_render
()
self
.
assertEqual
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)),
True
)
self
.
failUnless
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)))
def
testUTF8
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
'<div tal:content="python: request.get(
\
'
data
\
'
)" />'
,
text
=
(
'<div tal:content="python: '
'request.get(
\
'
data
\
'
)" />'
),
encoding
=
'ascii'
)
zpt
=
self
.
app
[
'test'
]
self
.
app
.
REQUEST
.
set
(
'HTTP_ACCEPT_CHARSET'
,
'utf-8,ISO-8859-15'
)
self
.
app
.
REQUEST
.
set
(
'data'
,
unicode
(
''
,
'iso-8859-15'
).
encode
(
'utf-8'
))
self
.
app
.
REQUEST
.
set
(
'data'
,
unicode
(
''
,
'iso-8859-15'
).
encode
(
'utf-8'
))
result
=
zpt
.
pt_render
()
self
.
assertEqual
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)),
True
)
self
.
failUnless
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)))
def
testUTF8WrongPreferredCharset
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
'<div tal:content="python: request.get(
\
'
data
\
'
)" />'
,
text
=
(
'<div tal:content="python: '
'request.get(
\
'
data
\
'
)" />'
),
encoding
=
'ascii'
)
zpt
=
self
.
app
[
'test'
]
self
.
app
.
REQUEST
.
set
(
'HTTP_ACCEPT_CHARSET'
,
'iso-8859-15'
)
self
.
app
.
REQUEST
.
set
(
'data'
,
unicode
(
''
,
'iso-8859-15'
).
encode
(
'utf-8'
))
self
.
app
.
REQUEST
.
set
(
'data'
,
unicode
(
''
,
'iso-8859-15'
).
encode
(
'utf-8'
))
result
=
zpt
.
pt_render
()
self
.
assertEqual
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)),
False
)
self
.
failIf
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)))
def
testStructureWithAccentedChars
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
'<div tal:content="structure python: %s" />'
%
"''"
,
text
=
(
'<div tal:content="structure '
'python: %s" />'
%
"''"
),
encoding
=
'iso-8859-15'
)
zpt
=
self
.
app
[
'test'
]
self
.
app
.
REQUEST
.
set
(
'HTTP_ACCEPT_CHARSET'
,
'iso-8859-15,utf-8'
)
self
.
app
.
REQUEST
.
set
(
'data'
,
unicode
(
''
,
'iso-8859-15'
).
encode
(
'utf-8'
))
self
.
app
.
REQUEST
.
set
(
'data'
,
unicode
(
''
,
'iso-8859-15'
).
encode
(
'utf-8'
))
result
=
zpt
.
pt_render
()
self
.
assertEqual
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)),
True
)
self
.
failUnless
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)))
def
testBug151020
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
'<div tal:content="structure python: %s" />'
%
"''"
,
text
=
(
'<div tal:content="structure '
'python: %s" />'
%
"''"
),
encoding
=
'iso-8859-15'
)
zpt
=
self
.
app
[
'test'
]
self
.
app
.
REQUEST
.
set
(
'HTTP_ACCEPT_CHARSET'
,
'x-user-defined, iso-8859-15,utf-8'
)
self
.
app
.
REQUEST
.
set
(
'data'
,
unicode
(
''
,
'iso-8859-15'
).
encode
(
'utf-8'
))
self
.
app
.
REQUEST
.
set
(
'HTTP_ACCEPT_CHARSET'
,
'x-user-defined, iso-8859-15,utf-8'
)
self
.
app
.
REQUEST
.
set
(
'data'
,
unicode
(
''
,
'iso-8859-15'
).
encode
(
'utf-8'
))
result
=
zpt
.
pt_render
()
self
.
assertEqual
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)),
True
)
self
.
failUnless
(
result
.
startswith
(
unicode
(
'<div></div>'
,
'iso-8859-15'
)))
class
ZopePageTemplateFileTests
(
ZopeTestCase
):
def
testPT_RenderWithAscii
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
ascii_str
,
encoding
=
'ascii'
)
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
ascii_str
,
encoding
=
'ascii'
)
zpt
=
self
.
app
[
'test'
]
result
=
zpt
.
pt_render
()
# use startswith() because the renderer appends a trailing \n
...
...
@@ -168,21 +206,25 @@ class ZopePageTemplateFileTests(ZopeTestCase):
# Check workaround for unicode incompatibility of ZRPythonExpr.
# See http://mail.zope.org/pipermail/zope/2007-February/170537.html
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
'<span tal:content="python: unicode(
\
'
\
xfe
\
'
,
\
'
iso-8859-15
\
'
)" />'
,
text
=
(
'<span tal:content="python: '
'unicode(
\
'
\
xfe
\
'
,
\
'
iso-8859-15
\
'
)" />'
),
encoding
=
'iso-8859-15'
)
zpt
=
self
.
app
[
'test'
]
result
=
zpt
.
pt_render
()
# should not raise a UnicodeDecodeError
def
testPT_RenderWithISO885915
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
iso885915_str
,
encoding
=
'iso-8859-15'
)
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
iso885915_str
,
encoding
=
'iso-8859-15'
)
zpt
=
self
.
app
[
'test'
]
result
=
zpt
.
pt_render
()
# use startswith() because the renderer appends a trailing \n
self
.
assertEqual
(
result
.
encode
(
'iso-8859-15'
).
startswith
(
iso885915_str
),
True
)
self
.
failUnless
(
result
.
encode
(
'iso-8859-15'
).
startswith
(
iso885915_str
))
self
.
assertEqual
(
zpt
.
output_encoding
,
'iso-8859-15'
)
def
testPT_RenderWithUTF8
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
utf8_str
,
encoding
=
'utf-8'
)
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
utf8_str
,
encoding
=
'utf-8'
)
zpt
=
self
.
app
[
'test'
]
result
=
zpt
.
pt_render
()
# use startswith() because the renderer appends a trailing \n
...
...
@@ -206,7 +248,8 @@ class ZopePageTemplateFileTests(ZopeTestCase):
self
.
assertEqual
(
zpt
.
read
(),
xml_unicode
)
def
_createZPT
(
self
):
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
utf8_str
,
encoding
=
'utf-8'
)
manage_addPageTemplate
(
self
.
app
,
'test'
,
text
=
utf8_str
,
encoding
=
'utf-8'
)
zpt
=
self
.
app
[
'test'
]
return
zpt
...
...
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