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
861287b6
Commit
861287b6
authored
Oct 21, 2005
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert unintended checkin.
parent
6c4c5570
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
101 deletions
+43
-101
lib/python/Products/ZReST/ZReST.py
lib/python/Products/ZReST/ZReST.py
+43
-59
lib/python/Products/ZReST/tests/__init__.py
lib/python/Products/ZReST/tests/__init__.py
+0
-4
lib/python/Products/ZReST/tests/test_ZReST.py
lib/python/Products/ZReST/tests/test_ZReST.py
+0
-38
No files found.
lib/python/Products/ZReST/ZReST.py
View file @
861287b6
...
...
@@ -47,7 +47,6 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
'''
meta_type
=
'ReStructuredText Document'
security
=
ClassSecurityInfo
()
_v_formatted
=
_v_warnings
=
None
def
__init__
(
self
,
id
,
output_encoding
=
None
,
input_encoding
=
None
):
...
...
@@ -55,7 +54,7 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
self
.
title
=
id
self
.
stylesheet
=
'default.css'
self
.
report_level
=
'2'
self
.
source
=
''
self
.
source
=
self
.
formatted
=
''
from
reStructuredText
import
default_output_encoding
,
\
default_input_encoding
...
...
@@ -90,7 +89,7 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
'''
if
REQUEST
is
not
None
:
REQUEST
.
RESPONSE
.
setHeader
(
'content-type'
,
'text/html; charset=%s'
%
self
.
output_encoding
)
return
self
.
render
()
return
self
.
formatted
security
.
declareProtected
(
'View'
,
'source_txt'
)
def
source_txt
(
self
,
REQUEST
=
None
):
...
...
@@ -114,7 +113,7 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
return
self
.
_er
(
data
,
SUBMIT
,
dtpref_cols
,
dtpref_rows
,
REQUEST
)
if
data
!=
self
.
source
:
self
.
source
=
data
self
.
_clear_cache
()
self
.
render
()
if
REQUEST
is
not
None
:
message
=
"Saved changes."
...
...
@@ -143,7 +142,6 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
setCookie
(
"dtpref_cols"
,
cols
,
path
=
'/'
,
expires
=
e
)
REQUEST
.
other
.
update
({
"dtpref_cols"
:
cols
,
"dtpref_rows"
:
rows
})
return
self
.
manage_main
(
self
,
REQUEST
,
__str__
=
self
.
quotedHTML
(
data
))
security
.
declarePrivate
(
'quotedHTML'
)
def
quotedHTML
(
self
,
text
=
None
,
...
...
@@ -157,18 +155,6 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
if
text
.
find
(
re
)
>=
0
:
text
=
name
.
join
(
text
.
split
(
re
))
return
text
security
.
declarePrivate
(
'_clear_cache'
)
def
_clear_cache
(
self
):
""" Forget results of rendering.
"""
try
:
del
self
.
_v_formatted
except
AttributeError
:
pass
try
:
del
self
.
_v_warnings
except
AttributeError
:
pass
# handle uploads too
security
.
declareProtected
(
'Edit ReStructuredText'
,
'manage_upload'
)
...
...
@@ -179,7 +165,7 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
self
.
source
=
file
else
:
self
.
source
=
file
.
read
()
self
.
_clear_cache
()
self
.
render
()
if
REQUEST
is
not
None
:
message
=
"Saved changes."
...
...
@@ -189,58 +175,55 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
def
render
(
self
):
''' Render the source to HTML
'''
if
self
.
_v_formatted
is
None
:
# format with strings
pub
=
docutils
.
core
.
Publisher
()
pub
.
set_reader
(
'standalone'
,
None
,
'restructuredtext'
)
pub
.
set_writer
(
'html'
)
# go with the defaults
pub
.
get_settings
()
# format with strings
pub
=
docutils
.
core
.
Publisher
()
pub
.
set_reader
(
'standalone'
,
None
,
'restructuredtext'
)
pub
.
set_writer
(
'html'
)
# this is needed, but doesn't seem to do anything
pub
.
settings
.
_destination
=
''
# go with the defaults
pub
.
get_settings
()
# use the stylesheet chosen by the user
pub
.
settings
.
stylesheet
=
self
.
stylesheet
# this is needed, but doesn't seem to do anything
pub
.
settings
.
_destination
=
''
# set the reporting level to something sane
pub
.
settings
.
report_level
=
int
(
self
.
report_level
)
# use the stylesheet chosen by the user
pub
.
settings
.
stylesheet
=
self
.
stylesheet
# disallow use of the .. include directive for security reasons
pub
.
settings
.
file_insertion_enabled
=
0
# set the reporting level to something sane
pub
.
settings
.
report_level
=
int
(
self
.
report_level
)
# don't break if we get error
s
pub
.
settings
.
halt_level
=
6
# disallow use of the .. include directive for security reason
s
pub
.
settings
.
file_insertion_enabled
=
0
# remember warning
s
pub
.
settings
.
warning_stream
=
Warnings
()
# don't break if we get error
s
pub
.
settings
.
halt_level
=
6
pub
.
source
=
docutils
.
io
.
StringInput
(
source
=
self
.
source
,
encoding
=
self
.
input_encoding
)
# remember warnings
pub
.
settings
.
warning_stream
=
Warnings
(
)
# output - not that it's needed
pub
.
settings
.
output_encoding
=
self
.
output_encoding
pub
.
destination
=
docutils
.
io
.
StringOutput
(
encoding
=
self
.
output_encoding
)
pub
.
source
=
docutils
.
io
.
StringInput
(
source
=
self
.
source
,
encoding
=
self
.
input_encoding
)
# parse!
document
=
pub
.
reader
.
read
(
pub
.
source
,
pub
.
parser
,
pub
.
settings
)
# output - not that it's needed
pub
.
settings
.
output_encoding
=
self
.
output_encoding
pub
.
destination
=
docutils
.
io
.
StringOutput
(
encoding
=
self
.
output_encoding
)
# transform
pub
.
apply_transforms
(
document
)
# parse!
document
=
pub
.
reader
.
read
(
pub
.
source
,
pub
.
parser
,
pub
.
settings
)
self
.
_v_warnings
=
''
.
join
(
pub
.
settings
.
warning_stream
.
messages
)
# transform
pub
.
apply_transforms
(
document
)
if
document
.
children
:
item
=
document
.
children
[
0
]
if
item
.
tagname
==
'title'
:
self
.
title
=
item
.
children
[
0
].
astext
()
self
.
warnings
=
''
.
join
(
pub
.
settings
.
warning_stream
.
messages
)
# do the format
self
.
_v_formatted
=
pub
.
writer
.
write
(
document
,
pub
.
destination
)
if
document
.
children
:
item
=
document
.
children
[
0
]
if
item
.
tagname
==
'title'
:
self
.
title
=
item
.
children
[
0
].
astext
()
return
self
.
_v_formatted
# do the format
self
.
formatted
=
pub
.
writer
.
write
(
document
,
pub
.
destination
)
security
.
declareProtected
(
'Edit ReStructuredText'
,
'PUT'
,
'manage_FTPput'
)
...
...
@@ -264,6 +247,7 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
pass
# ignore
data
=
'
\
n
'
.
join
(
new
)
+
'
\
n
'
.
join
(
data
[
i
:])
self
.
source
=
data
self
.
render
()
RESPONSE
.
setStatus
(
204
)
return
RESPONSE
...
...
@@ -279,9 +263,9 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
'.. stylesheet='
+
self
.
stylesheet
,
'.. report_level='
+
self
.
report_level
]
if
self
.
_v_
warnings
:
if
self
.
warnings
:
s
.
append
(
'.. '
)
s
.
append
(
'.. '
+
'
\
n
.. '
.
join
(
self
.
_v_
warnings
.
splitlines
()))
s
.
append
(
'.. '
+
'
\
n
.. '
.
join
(
self
.
warnings
.
splitlines
()))
s
.
append
(
'.. '
)
return
'
\
n
'
.
join
(
s
)
+
'
\
n
'
+
self
.
source
...
...
@@ -306,7 +290,7 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
def
manage_editProperties
(
self
,
REQUEST
):
""" re-render the page after changing the properties (encodings!!!) """
result
=
PropertyManager
.
manage_editProperties
(
self
,
REQUEST
)
self
.
_clear_cache
()
self
.
render
()
return
result
...
...
lib/python/Products/ZReST/tests/__init__.py
deleted
100644 → 0
View file @
6c4c5570
""" Unit tests for ZReST product.
$Id$
"""
lib/python/Products/ZReST/tests/test_ZReST.py
deleted
100644 → 0
View file @
6c4c5570
""" Unit tests for ZReST objects
$Id$
"""
import
unittest
class
TestZReST
(
unittest
.
TestCase
):
def
_getTargetClass
(
self
):
from
Products.ZReST.ZReST
import
ZReST
return
ZReST
def
_makeOne
(
self
,
id
=
'test'
,
*
args
,
**
kw
):
return
self
.
_getTargetClass
()(
id
=
id
,
*
args
,
**
kw
)
def
test_empty
(
self
):
empty
=
self
.
_makeOne
()
# New instances should not have non-volatile cache attributes
self
.
assertRaises
(
AttributeError
,
lambda
:
empty
.
formatted
)
self
.
assertRaises
(
AttributeError
,
lambda
:
empty
.
warnings
)
self
.
assertEqual
(
empty
.
_v_formatted
,
None
)
self
.
assertEqual
(
empty
.
_v_formatted
,
None
)
def
test_formatted_ignored
(
self
):
resty
=
self
.
_makeOne
()
resty
.
formatted
=
'IGNORE ME'
self
.
failIf
(
'IGNORE ME'
in
resty
.
index_html
())
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestZReST
))
return
suite
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultSuite
=
'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