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
aaf60124
Commit
aaf60124
authored
Jan 11, 2007
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Collector #2263: 'field2ulines' did not convert empty string correctly.
parent
148a374a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
3 deletions
+133
-3
doc/CHANGES.txt
doc/CHANGES.txt
+3
-0
lib/python/ZPublisher/Converters.py
lib/python/ZPublisher/Converters.py
+12
-3
lib/python/ZPublisher/tests/test_Converters.py
lib/python/ZPublisher/tests/test_Converters.py
+118
-0
No files found.
doc/CHANGES.txt
View file @
aaf60124
...
...
@@ -8,6 +8,9 @@ Zope Changes
Bugs fixed
- Collector #2263: 'field2ulines' did not convert empty string
correctly.
- Collector #2237: 'make' doesn't tell you to run 'make inplace'
before running 'make instance'.
...
...
lib/python/ZPublisher/Converters.py
View file @
aaf60124
...
...
@@ -154,9 +154,18 @@ class field2utext(_unicode_converter):
return
unicode
(
field2text
(
v
.
encode
(
'utf8'
)),
'utf8'
)
field2utext
=
field2utext
()
class
field2ulines
(
_unicode_converter
):
def
convert_unicode
(
self
,
v
):
return
field2utext
.
convert_unicode
(
v
).
split
(
'
\
n
'
)
class
field2ulines
:
def
__call__
(
self
,
v
):
if
hasattr
(
v
,
'read'
):
v
=
v
.
read
()
if
isinstance
(
v
,
(
ListType
,
TupleType
)):
return
[
field2ustring
(
x
)
for
x
in
v
]
v
=
unicode
(
v
)
return
self
.
convert_unicode
(
v
)
def
convert_unicode
(
self
,
v
):
return
field2utext
.
convert_unicode
(
v
).
splitlines
()
field2ulines
=
field2ulines
()
type_converters
=
{
...
...
lib/python/ZPublisher/tests/test_Converters.py
0 → 100644
View file @
aaf60124
################################################################################
#
# Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
################################################################################
import
unittest
class
ConvertersTests
(
unittest
.
TestCase
):
def
test_field2string_with_string
(
self
):
from
ZPublisher.Converters
import
field2string
to_convert
=
'to_convert'
self
.
assertEqual
(
field2string
(
to_convert
),
to_convert
)
def
test_field2string_with_unicode_default_encoding
(
self
):
from
ZPublisher.Converters
import
field2string
to_convert
=
u'to_convert'
self
.
assertEqual
(
field2string
(
to_convert
),
to_convert
.
encode
(
'iso-8859-15'
))
def
test_field2string_with_filelike_object
(
self
):
from
ZPublisher.Converters
import
field2string
to_convert
=
'to_convert'
class
Filelike
:
def
read
(
self
):
return
to_convert
self
.
assertEqual
(
field2string
(
Filelike
()),
to_convert
)
#TODO def test_field2text....
#TODO def test_field2required....
#TODO def test_field2int....
#TODO def test_field2float....
#TODO def test_field2tokens....
def
test_field2lines_with_list
(
self
):
from
ZPublisher.Converters
import
field2lines
to_convert
=
[
'one'
,
'two'
]
self
.
assertEqual
(
field2lines
(
to_convert
),
to_convert
)
def
test_field2lines_with_tuple
(
self
):
from
ZPublisher.Converters
import
field2lines
to_convert
=
(
'one'
,
'two'
)
self
.
assertEqual
(
field2lines
(
to_convert
),
list
(
to_convert
))
def
test_field2lines_with_empty_string
(
self
):
from
ZPublisher.Converters
import
field2lines
to_convert
=
''
self
.
assertEqual
(
field2lines
(
to_convert
),
[])
def
test_field2lines_with_string_no_newlines
(
self
):
from
ZPublisher.Converters
import
field2lines
to_convert
=
'abc def ghi'
self
.
assertEqual
(
field2lines
(
to_convert
),
[
to_convert
])
def
test_field2lines_with_string_with_newlines
(
self
):
from
ZPublisher.Converters
import
field2lines
to_convert
=
'abc
\
n
def
\
n
ghi'
self
.
assertEqual
(
field2lines
(
to_convert
),
to_convert
.
splitlines
())
#TODO def test_field2date....
#TODO def test_field2date_international....
#TODO def test_field2boolean....
#TODO def test_field2ustring....
#TODO def test_field2utokens....
#TODO def test_field2utext....
def
test_field2ulines_with_list
(
self
):
from
ZPublisher.Converters
import
field2ulines
to_convert
=
[
u'one'
,
'two'
]
self
.
assertEqual
(
field2ulines
(
to_convert
),
[
unicode
(
x
)
for
x
in
to_convert
])
def
test_field2ulines_with_tuple
(
self
):
from
ZPublisher.Converters
import
field2ulines
to_convert
=
(
u'one'
,
'two'
)
self
.
assertEqual
(
field2ulines
(
to_convert
),
[
unicode
(
x
)
for
x
in
to_convert
])
def
test_field2ulines_with_empty_string
(
self
):
from
ZPublisher.Converters
import
field2ulines
to_convert
=
''
self
.
assertEqual
(
field2ulines
(
to_convert
),
[])
def
test_field2ulines_with_string_no_newlines
(
self
):
from
ZPublisher.Converters
import
field2ulines
to_convert
=
u'abc def ghi'
self
.
assertEqual
(
field2ulines
(
to_convert
),
[
to_convert
])
def
test_field2ulines_with_string_with_newlines
(
self
):
from
ZPublisher.Converters
import
field2ulines
to_convert
=
u'abc
\
n
def
\
n
ghi'
self
.
assertEqual
(
field2ulines
(
to_convert
),
to_convert
.
splitlines
())
def
test_suite
():
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
ConvertersTests
),))
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
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