Attempt to handle line endings in a cross-platform manner
This commit is contained in:
parent
de6c2eb924
commit
4198961174
5 changed files with 40 additions and 21 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
SCOURVER="0.22"
|
||||
SCOURVER="0.23"
|
||||
cd ..
|
||||
zip scour/tarballs/scour-$SCOURVER.zip scour/scour.py scour/yocto_css.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
|
||||
cd scour
|
||||
|
|
|
|||
|
|
@ -9,6 +9,16 @@
|
|||
|
||||
<p>Copyright 2009, Jeff Schiller</p>
|
||||
|
||||
<section id="0.23">
|
||||
<header>
|
||||
<h2><a href="#0.23">Version 0.23</a></h2>
|
||||
</header>
|
||||
<p>TBD</p>
|
||||
<ul>
|
||||
<li>...</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section id="0.22">
|
||||
<header>
|
||||
<h2><a href="#0.22">Version 0.22</a></h2>
|
||||
|
|
|
|||
30
scour.py
30
scour.py
|
|
@ -2092,7 +2092,7 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False):
|
|||
if preserveWhitespace:
|
||||
outString += serializeXML(child, options, 0, preserveWhitespace)
|
||||
else:
|
||||
outString += '\n' + serializeXML(child, options, indent + 1, preserveWhitespace)
|
||||
outString += os.linesep + serializeXML(child, options, indent + 1, preserveWhitespace)
|
||||
onNewLine = True
|
||||
# text node
|
||||
elif child.nodeType == 3:
|
||||
|
|
@ -2114,10 +2114,10 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False):
|
|||
|
||||
if onNewLine: outString += (I * ind)
|
||||
outString += '</' + element.nodeName + '>'
|
||||
if indent > 0: outString += '\n'
|
||||
if indent > 0: outString += os.linesep
|
||||
else:
|
||||
outString += '/>'
|
||||
if indent > 0: outString += '\n'
|
||||
if indent > 0: outString += os.linesep
|
||||
|
||||
return outString
|
||||
|
||||
|
|
@ -2273,7 +2273,7 @@ def scourString(in_string, options=None):
|
|||
# http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/
|
||||
# rolled our own serialize function here to save on space, put id first, customize indentation, etc
|
||||
# out_string = doc.documentElement.toprettyxml(' ')
|
||||
out_string = serializeXML(doc.documentElement, options)
|
||||
out_string = serializeXML(doc.documentElement, options) + os.linesep
|
||||
|
||||
# now strip out empty lines
|
||||
lines = []
|
||||
|
|
@ -2284,7 +2284,7 @@ def scourString(in_string, options=None):
|
|||
|
||||
# return the string stripped of empty lines
|
||||
if options.strip_xml_prolog == False:
|
||||
xmlprolog = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
|
||||
xmlprolog = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' + os.linesep
|
||||
else:
|
||||
xmlprolog = ""
|
||||
|
||||
|
|
@ -2385,15 +2385,15 @@ def parse_args(args=None):
|
|||
return options, [infile, outfile]
|
||||
|
||||
def getReport():
|
||||
return ' Number of elements removed: ' + str(numElemsRemoved) + \
|
||||
'\n Number of attributes removed: ' + str(numAttrsRemoved) + \
|
||||
'\n Number of unreferenced id attributes removed: ' + str(numIDsRemoved) + \
|
||||
'\n Number of style properties fixed: ' + str(numStylePropsFixed) + \
|
||||
'\n Number of raster images embedded inline: ' + str(numRastersEmbedded) + \
|
||||
'\n Number of path segments reduced/removed: ' + str(numPathSegmentsReduced) + \
|
||||
'\n Number of bytes saved in path data: ' + str(numBytesSavedInPathData) + \
|
||||
'\n Number of bytes saved in colors: ' + str(numBytesSavedInColors) + \
|
||||
'\n Number of points removed from polygons: ' + str(numPointsRemovedFromPolygon)
|
||||
return ' Number of elements removed: ' + str(numElemsRemoved) + os.linesep + \
|
||||
' Number of attributes removed: ' + str(numAttrsRemoved) + os.linesep + \
|
||||
' Number of unreferenced id attributes removed: ' + str(numIDsRemoved) + os.linesep + \
|
||||
' Number of style properties fixed: ' + str(numStylePropsFixed) + os.linesep + \
|
||||
' Number of raster images embedded inline: ' + str(numRastersEmbedded) + os.linesep + \
|
||||
' Number of path segments reduced/removed: ' + str(numPathSegmentsReduced) + os.linesep + \
|
||||
' Number of bytes saved in path data: ' + str(numBytesSavedInPathData) + os.linesep + \
|
||||
' Number of bytes saved in colors: ' + str(numBytesSavedInColors) + os.linesep + \
|
||||
' Number of points removed from polygons: ' + str(numPointsRemovedFromPolygon)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.platform == "win32":
|
||||
|
|
@ -2423,7 +2423,7 @@ if __name__ == '__main__':
|
|||
# GZ: unless silenced by -q or something?
|
||||
# GZ: not using globals would be good too
|
||||
print >>sys.stderr, ' File:', input.name, \
|
||||
'\n Time taken:', str(end-start) + 's\n', \
|
||||
os.linesep + ' Time taken:', str(end-start) + 's' + os.linesep, \
|
||||
getReport()
|
||||
|
||||
oldsize = len(in_string)
|
||||
|
|
|
|||
17
testscour.py
17
testscour.py
|
|
@ -834,7 +834,8 @@ class CDATAInXml(unittest.TestCase):
|
|||
<script type="application/ecmascript"><![CDATA[
|
||||
alert('pb&j');
|
||||
]]></script>
|
||||
</svg>''',
|
||||
</svg>
|
||||
''',
|
||||
'Improperly serialized the cdata unit tests')
|
||||
|
||||
class WellFormedXMLLesserThanInAttrValue(unittest.TestCase):
|
||||
|
|
@ -933,7 +934,8 @@ class DoNotPrettyPrintWhenWhitespacePreserved(unittest.TestCase):
|
|||
'''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<text xml:space="preserve">This is some <tspan font-style="italic">messed-up</tspan> markup</text>
|
||||
</svg>''',
|
||||
</svg>
|
||||
''',
|
||||
'Whitespace not preserved')
|
||||
|
||||
class DoNotPrettyPrintWhenNestedWhitespacePreserved(unittest.TestCase):
|
||||
|
|
@ -942,7 +944,8 @@ class DoNotPrettyPrintWhenNestedWhitespacePreserved(unittest.TestCase):
|
|||
'''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<text xml:space="preserve"><tspan font-style="italic">Use <tspan font-style="bold">bold</tspan> text</tspan></text>
|
||||
</svg>''',
|
||||
</svg>
|
||||
''',
|
||||
'Whitespace not preserved when nested')
|
||||
|
||||
class GetAttrPrefixRight(unittest.TestCase):
|
||||
|
|
@ -954,7 +957,7 @@ class GetAttrPrefixRight(unittest.TestCase):
|
|||
class EnsurePreserveWhitespaceOnNonTextElements(unittest.TestCase):
|
||||
def runTest(self):
|
||||
s = scour.scourString(open('unittests/no-collapse-lines.svg').read())
|
||||
self.assertEquals( s.count('\n'), 5,
|
||||
self.assertEquals( len(s.splitlines()), 6,
|
||||
'Did not properly preserve whitespace on elements even if they were not textual')
|
||||
|
||||
class HandleEmptyStyleElement(unittest.TestCase):
|
||||
|
|
@ -967,6 +970,12 @@ class HandleEmptyStyleElement(unittest.TestCase):
|
|||
self.assertEquals( fail, False,
|
||||
'Could not handle an empty style element')
|
||||
|
||||
class EnsureLineEndings(unittest.TestCase):
|
||||
def runTest(self):
|
||||
s = scour.scourString(open('unittests/whitespace-important.svg').read())
|
||||
self.assertEquals( len(s.splitlines()), 4,
|
||||
'Did not output line ending character correctly')
|
||||
|
||||
# TODO; write a test for embedding rasters
|
||||
# TODO: write a test for --disable-embed-rasters
|
||||
# TODO: write tests for --keep-editor-data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue