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
cb362793
Commit
cb362793
authored
Nov 18, 2008
by
Paul Winkler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simpler, faster implementation of DocumentTemplate.DT_Var.newline_to_br(), with tests.
parent
9d22d6e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
2 deletions
+75
-2
doc/CHANGES.txt
doc/CHANGES.txt
+3
-0
lib/python/DocumentTemplate/DT_Var.py
lib/python/DocumentTemplate/DT_Var.py
+2
-2
lib/python/DocumentTemplate/tests/test_DT_Var.py
lib/python/DocumentTemplate/tests/test_DT_Var.py
+70
-0
No files found.
doc/CHANGES.txt
View file @
cb362793
...
@@ -520,6 +520,9 @@ Zope Changes
...
@@ -520,6 +520,9 @@ Zope Changes
- Added lib/python/webdav/litmus-results.txt explaining current
- Added lib/python/webdav/litmus-results.txt explaining current
test results from the litmus WebDAV torture test.
test results from the litmus WebDAV torture test.
- DocumentTemplate.DT_Var.newline_to_br(): Simpler, faster implementation.
Zope 2.10.0 beta 1 (2006/05/30)
Zope 2.10.0 beta 1 (2006/05/30)
Restructuring
Restructuring
...
...
lib/python/DocumentTemplate/DT_Var.py
View file @
cb362793
...
@@ -358,8 +358,8 @@ def newline_to_br(v, name='(Unknown name)', md={}):
...
@@ -358,8 +358,8 @@ def newline_to_br(v, name='(Unknown name)', md={}):
# quoted later on anyway.
# quoted later on anyway.
if
isinstance
(
v
,
TaintedString
):
v
=
v
.
quoted
()
if
isinstance
(
v
,
TaintedString
):
v
=
v
.
quoted
()
v
=
ustr
(
v
)
v
=
ustr
(
v
)
if
v
.
find
(
'
\
r
'
)
>=
0
:
v
=
''
.
join
(
v
.
split
(
'
\
r
'
)
)
v
=
v
.
replace
(
'
\
r
'
,
''
)
if
v
.
find
(
'
\
n
'
)
>=
0
:
v
=
'<br />
\
n
'
.
join
(
v
.
split
(
'
\
n
'
)
)
v
=
v
.
replace
(
'
\
n
'
,
'<br />
\
n
'
)
return
v
return
v
def
whole_dollars
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
def
whole_dollars
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
...
...
lib/python/DocumentTemplate/tests/test_DT_Var.py
0 → 100644
View file @
cb362793
##############################################################################
#
# Copyright (c) 2008 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Tests for functions and classes in DT_Var.
$Id$
"""
import
unittest
,
doctest
from
DocumentTemplate
import
DT_Var
class
TestNewlineToBr
(
doctest
.
DocTestCase
):
def
test_newline_to_br
(
self
):
r"""
newline_to_br should work identically with either DOS-style or
Unix-style newlines.
>>> text = '''
... line one
... line two
...
... line three
... '''
>>> print DT_Var.newline_to_br(text)
<br />
line one<br />
line two<br />
<br />
line three<br />
<BLANKLINE>
>>> dos = text.replace('\n', '\r\n')
>>> DT_Var.newline_to_br(text) == DT_Var.newline_to_br(dos)
True
"""
def
test_newline_to_br_tainted
(
self
):
"""
>>> text = '''
... <li>line one</li>
... <li>line two</li>
... '''
>>> from ZPublisher.TaintedString import TaintedString
>>> tainted = TaintedString(text)
>>> print DT_Var.newline_to_br(tainted)
<br />
<li>line one</li><br />
<li>line two</li><br />
<BLANKLINE>
"""
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
doctest
.
DocTestSuite
())
return
suite
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