Skip to content

Commit

Permalink
Fix various warnings about unclosed files etc. There's still hundreds…
Browse files Browse the repository at this point in the history
… of warnings coming from inside ReportLab and PIL
  • Loading branch information
kylemacfarlane committed Oct 11, 2014
1 parent 1eeff04 commit aade0fd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/z3c/rml/attr.py
Expand Up @@ -92,7 +92,7 @@ def get(self):
if (interfaces.IDeprecated.providedBy(self) and
self.deprecatedName in self.context.element.attrib):
name = self.deprecatedName
logger.warn(
logger.warning(
u'Deprecated attribute "%s": %s %s' % (
name, self.deprecatedReason, getFileInfo(self.context)))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/rml/directive.py
Expand Up @@ -108,7 +108,7 @@ def processSubDirectives(self, select=None, ignore=None):
msg = "Directive %r could not be processed and was " \
"ignored. %s" %(element.tag, getFileInfo(self, element))
# Record any tags/elements that could not be processed.
logger.warn(msg)
logger.warning(msg)
if ABORT_ON_INVALID_DIRECTIVE:
raise ValueError(msg)
continue
Expand Down
4 changes: 3 additions & 1 deletion src/z3c/rml/pagetemplate.txt
Expand Up @@ -13,7 +13,8 @@ The first step is to create a page template:

>>> import tempfile
>>> ptFileName = tempfile.mktemp('.pt')
>>> open(ptFileName, 'w').write('''\
>>> file_ = open(ptFileName, 'w')
>>> file_.write('''\
... <?xml version="1.0" encoding="UTF-8" ?>
... <!DOCTYPE document SYSTEM "rml.dtd">
... <document filename="template.pdf"
Expand All @@ -35,6 +36,7 @@ The first step is to create a page template:
... </document>
... ''')
463
>>> file_.close()

The ``context`` namespace will be created during rendering. I get back to this
later. In th enext step we instantiate the page template:
Expand Down
6 changes: 5 additions & 1 deletion src/z3c/rml/reference.py
Expand Up @@ -226,6 +226,8 @@ def extractExamples(directory):
xml = highlightRML(xml)
example['code'] = xml

rmlFile.close()

return examples


Expand All @@ -239,4 +241,6 @@ def main(outPath=None):
directives = sorted(directives.values(), key=lambda d: d['name'])

pdf = template(types=getAttributeTypes(), directives=directives)
open(outPath or 'rml-reference.pdf', 'wb').write(pdf)
file_ = open(outPath or 'rml-reference.pdf', 'wb')
file_.write(pdf)
file_.close()
4 changes: 4 additions & 0 deletions src/z3c/rml/rml2pdf.py
Expand Up @@ -60,6 +60,10 @@ def go(xmlInputName, outputFileName=None, outDir=None, dtdDir=None):
# Create a Reportlab canvas by processing the document
doc.process(outputFile)

if outputFile:
outputFile.close()
xmlFile.close()


def main(args=None):
if args is None:
Expand Down
8 changes: 6 additions & 2 deletions src/z3c/rml/tests/test_rml.py
Expand Up @@ -84,13 +84,17 @@ def __init__(self, basePath, testPath):
unittest.TestCase.__init__(self)

def assertSameImage(self, baseImage, testImage):
base = Image.open(baseImage).getdata()
test = Image.open(testImage).getdata()
base_file = open(baseImage, 'rb')
test_file = open(testImage, 'rb')
base = Image.open(base_file).getdata()
test = Image.open(test_file).getdata()
for i in range(len(base)):
if (base[i] - test[i]) != 0:
self.fail(
'Image is not the same: %s' % os.path.basename(baseImage)
)
base_file.close()
test_file.close()

def runTest(self):
# Convert the base PDF to image(s)
Expand Down

0 comments on commit aade0fd

Please sign in to comment.