Skip to content

Commit

Permalink
Attempt to fix unicode/bytes problems
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemacfarlane committed Oct 11, 2014
1 parent 9123fff commit 7a42f98
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/z3c/rml/attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ def fromUnicode(self, value):
value, getFileInfo(self.context)))


class String(RMLAttribute, zope.schema.Bytes):
"""A simple Bytes string."""


class Text(RMLAttribute, zope.schema.Text):
"""A simple unicode string."""


class String(Text):
"""Formerly a simple Bytes string, now the same as Text."""


class Integer(RMLAttribute, zope.schema.Int):
"""An integer. A minimum and maximum value can be specified."""
# By making min and max simple attributes, we avoid some validation
Expand Down Expand Up @@ -336,7 +336,7 @@ def fromUnicode(self, value):
return value
# Open/Download the file
fileObj = self.open(value)
sio = six.StringIO(fileObj.read())
sio = six.BytesIO(fileObj.read())
fileObj.close()
sio.seek(0)
return sio
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/rml/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def process(self, outputFile=None, maxPasses=2):

# Create a temporary output file, so that post-processors can
# massage the output
self.outputFile = tempOutput = six.StringIO()
self.outputFile = tempOutput = six.BytesIO()

# Process common sub-directives
self.processSubDirectives(select=('docinit', 'stylesheet'))
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/rml/occurence.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class IOccurence(zope.interface.Interface):
description=u'The description of the occurence.',
required=True)

tag = zope.schema.BytesLine(
tag = zope.schema.TextLine(
title=u'Tag',
description=u'The tag of the sub-directive within the directive',
required=True)
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/rml/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def process(self, inputFile1):
page = mergerPage
output.addPage(page)

outputFile = six.StringIO()
outputFile = six.BytesIO()
output.write(outputFile)
return outputFile

Expand Down
3 changes: 2 additions & 1 deletion src/z3c/rml/pagetemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The first step is to create a page template:
...
... </document>
... ''')
463

The ``context`` namespace will be created during rendering. I get back to this
later. In th enext step we instantiate the page template:
Expand All @@ -45,7 +46,7 @@ All we have to do now is to render the template. The context of the template
is effectively the keyword arguments dictionary:

>>> rmlPageTemplate(names=(u'Roy', u'Daniel', u'Julian', u'Stephan'))
'%PDF-1.4...'
b'%PDF-1.4...'

You can uncomment the following line to write out the PDF in the current
working directory:
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/rml/pdfinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def process(self, inputFile1):
merger.append(
inputFile1, pages=(prev_insert, num_pages))

outputFile = six.StringIO()
outputFile = six.BytesIO()
merger.write(outputFile)
return outputFile

Expand Down
2 changes: 1 addition & 1 deletion src/z3c/rml/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def extractExamples(directory):
for filename in os.listdir(directory):
if not filename.endswith('.rml'):
continue
rmlFile = open(os.path.join(directory, filename), 'r')
rmlFile = open(os.path.join(directory, filename), 'rb')
root = etree.parse(rmlFile).getroot()
elements = root.xpath('//@doc:example/parent::*',
namespaces={'doc': EXAMPLE_NS})
Expand Down
4 changes: 2 additions & 2 deletions src/z3c/rml/rml2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def parseString(xml, removeEncodingLine=True, filename=None):
doc = document.Document(root)
if filename:
doc.filename = filename
output = six.StringIO()
output = six.BytesIO()
doc.process(output)
output.seek(0)
return output
Expand All @@ -44,7 +44,7 @@ def go(xmlInputName, outputFileName=None, outDir=None, dtdDir=None):
if dtdDir is not None:
sys.stderr.write('The ``dtdDir`` option is not yet supported.')

xmlFile = open(xmlInputName, 'r')
xmlFile = open(xmlInputName, 'rb')
root = etree.parse(xmlFile).getroot()
doc = document.Document(root)
doc.filename = xmlInputName
Expand Down

0 comments on commit 7a42f98

Please sign in to comment.