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
10cbabab
Commit
10cbabab
authored
Jan 08, 2007
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a PreferredCharset resolver that also
deal with Collector #2180
parent
02d28d67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
lib/python/Products/PageTemplates/configure.zcml
lib/python/Products/PageTemplates/configure.zcml
+1
-1
lib/python/Products/PageTemplates/unicodeconflictresolver.py
lib/python/Products/PageTemplates/unicodeconflictresolver.py
+40
-0
No files found.
lib/python/Products/PageTemplates/configure.zcml
View file @
10cbabab
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<utility
<utility
provides="Products.PageTemplates.interfaces.IUnicodeEncodingConflictResolver"
provides="Products.PageTemplates.interfaces.IUnicodeEncodingConflictResolver"
component="Products.PageTemplates.unicodeconflictresolver.
DefaultUnicodeEncodingConflic
tResolver"
component="Products.PageTemplates.unicodeconflictresolver.
PreferredCharse
tResolver"
/>
/>
</configure>
</configure>
lib/python/Products/PageTemplates/unicodeconflictresolver.py
View file @
10cbabab
...
@@ -12,7 +12,10 @@
...
@@ -12,7 +12,10 @@
##############################################################################
##############################################################################
import
sys
import
sys
from
zope.interface
import
implements
from
zope.interface
import
implements
from
zope.i18n.interfaces
import
IUserPreferredCharsets
from
Products.PageTemplates.interfaces
import
IUnicodeEncodingConflictResolver
from
Products.PageTemplates.interfaces
import
IUnicodeEncodingConflictResolver
default_encoding
=
sys
.
getdefaultencoding
()
default_encoding
=
sys
.
getdefaultencoding
()
...
@@ -50,7 +53,44 @@ class Z2UnicodeEncodingConflictResolver:
...
@@ -50,7 +53,44 @@ class Z2UnicodeEncodingConflictResolver:
encoding
=
getattr
(
context
,
'management_page_charset'
,
default_encoding
)
encoding
=
getattr
(
context
,
'management_page_charset'
,
default_encoding
)
return
unicode
(
text
,
encoding
,
self
.
mode
)
return
unicode
(
text
,
encoding
,
self
.
mode
)
class
PreferredCharsetResolver
:
""" A resolver that tries uses the HTTP_ACCEPT_CHARSET
header.
"""
implements
(
IUnicodeEncodingConflictResolver
)
def
resolve
(
self
,
context
,
text
,
expression
):
request
=
context
.
REQUEST
if
not
hasattr
(
request
,
'__zpt_available_charsets'
):
charsets
=
IUserPreferredCharsets
(
request
).
getPreferredCharsets
()
# add management_page_charset as one fallback
management_charset
=
getattr
(
context
,
'management_page_charset'
,
None
)
if
management_charset
:
charsets
.
append
(
management_charset
)
# add Python's default encoding as last fallback
charsets
.
append
(
default_encoding
)
# cache list of charsets
request
.
__zpt_available_charsets
=
charsets
else
:
charsets
=
request
.
__zpt_available_charsets
for
enc
in
charsets
:
try
:
return
unicode
(
text
,
enc
)
except
UnicodeDecodeError
:
pass
return
text
StrictUnicodeEncodingConflictResolver
=
Z2UnicodeEncodingConflictResolver
(
'strict'
)
StrictUnicodeEncodingConflictResolver
=
Z2UnicodeEncodingConflictResolver
(
'strict'
)
ReplacingUnicodeEncodingConflictResolver
=
Z2UnicodeEncodingConflictResolver
(
'replace'
)
ReplacingUnicodeEncodingConflictResolver
=
Z2UnicodeEncodingConflictResolver
(
'replace'
)
IgnoringUnicodeEncodingConflictResolver
=
Z2UnicodeEncodingConflictResolver
(
'ignore'
)
IgnoringUnicodeEncodingConflictResolver
=
Z2UnicodeEncodingConflictResolver
(
'ignore'
)
PreferredCharsetResolver
=
PreferredCharsetResolver
()
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