"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/ZPublisher/Converters.py" between
Zope-5.1.2.tar.gz and Zope-5.2.tar.gz

About: Zope Z Object Publishing Environment - web application platform used for building content management systems, intranets, portals, and custom applications.

Converters.py  (Zope-5.1.2):Converters.py  (Zope-5.2)
skipping to change at line 24 skipping to change at line 24
import html import html
import re import re
from DateTime import DateTime from DateTime import DateTime
from DateTime.interfaces import SyntaxError from DateTime.interfaces import SyntaxError
# This may get overwritten during configuration # This may get overwritten during configuration
default_encoding = 'utf-8' default_encoding = 'utf-8'
def field2string(v): def field2string(v):
"""Converts value to native strings. """Converts value to string."""
if isinstance(v, bytes):
So always to `str` no matter which Python version you are on.
"""
if hasattr(v, 'read'):
return v.read()
elif isinstance(v, bytes):
return v.decode(default_encoding) return v.decode(default_encoding)
else: else:
return str(v) return str(v)
def field2bytes(v): def field2bytes(v):
# Converts value to bytes. """Converts value to bytes."""
if hasattr(v, 'read'): if hasattr(v, 'read'):
return v.read() return v.read()
elif isinstance(v, str): elif isinstance(v, str):
return v.encode(default_encoding) return v.encode(default_encoding)
else: else:
return bytes(v) return bytes(v)
def field2text(value, nl=re.compile('\r\n|\n\r').search): def field2text(value, nl=re.compile('\r\n|\n\r').search):
value = field2string(value) value = field2string(value)
match_object = nl(value) match_object = nl(value)
skipping to change at line 161 skipping to change at line 156
class _unicode_converter: class _unicode_converter:
def __call__(self, v): def __call__(self, v):
# Convert a regular python string. This probably doesn't do # Convert a regular python string. This probably doesn't do
# what you want, whatever that might be. If you are getting # what you want, whatever that might be. If you are getting
# exceptions below, you probably missed the encoding tag # exceptions below, you probably missed the encoding tag
# from a form field name. Use: # from a form field name. Use:
# <input name="description:utf8:ustring" ..... # <input name="description:utf8:ustring" .....
# rather than # rather than
# <input name="description:ustring" ..... # <input name="description:ustring" .....
if hasattr(v, 'read'):
v = v.read()
v = str(v) v = str(v)
return self.convert_unicode(v) return self.convert_unicode(v)
def convert_unicode(self, v): def convert_unicode(self, v):
raise NotImplementedError('convert_unicode') raise NotImplementedError('convert_unicode')
class field2ustring(_unicode_converter): class field2ustring(_unicode_converter):
def convert_unicode(self, v): def convert_unicode(self, v):
return v return v
skipping to change at line 191 skipping to change at line 184
class field2utext(_unicode_converter): class field2utext(_unicode_converter):
def convert_unicode(self, v): def convert_unicode(self, v):
if isinstance(v, bytes): if isinstance(v, bytes):
return str(field2text(v.encode('utf8')), 'utf8') return str(field2text(v.encode('utf8')), 'utf8')
return v return v
field2utext = field2utext() field2utext = field2utext()
class field2ulines: class field2ulines:
def __call__(self, v): def __call__(self, v):
if hasattr(v, 'read'):
v = v.read()
if isinstance(v, (list, tuple)): if isinstance(v, (list, tuple)):
return [field2ustring(x) for x in v] return [field2ustring(x) for x in v]
v = str(v) v = str(v)
return self.convert_unicode(v) return self.convert_unicode(v)
def convert_unicode(self, v): def convert_unicode(self, v):
return field2utext.convert_unicode(v).splitlines() return field2utext.convert_unicode(v).splitlines()
field2ulines = field2ulines() field2ulines = field2ulines()
 End of changes. 4 change blocks. 
12 lines changed or deleted 3 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)