Handle unicode characters. Specify utf-8 encoding on python scripts. Added unit test for non-ASCII characters.
This commit is contained in:
parent
321f16c46d
commit
d242407701
5 changed files with 703 additions and 5 deletions
685
fulltests/OperaMarketShareEEhover.svg
Normal file
685
fulltests/OperaMarketShareEEhover.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 547 KiB |
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
SCOURVER="0.10"
|
||||
SCOURVER="0.11"
|
||||
cd ..
|
||||
tar cvf scour/tarballs/scour-$SCOURVER.tar scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
|
||||
gzip scour/tarballs/scour-$SCOURVER.tar
|
||||
|
|
|
|||
7
scour.py
7
scour.py
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Scour
|
||||
#
|
||||
|
|
@ -71,7 +72,7 @@ from decimal import *
|
|||
getcontext().prec = 6
|
||||
|
||||
APP = 'scour'
|
||||
VER = '0.10'
|
||||
VER = '0.11'
|
||||
COPYRIGHT = 'Copyright Jeff Schiller, 2009'
|
||||
|
||||
NS = { 'SVG': 'http://www.w3.org/2000/svg',
|
||||
|
|
@ -1046,7 +1047,7 @@ def scourXmlFile(filename, options=[]):
|
|||
# print 'IN=',in_string
|
||||
out_string = scourString(in_string, options)
|
||||
# print 'OUT=',out_string
|
||||
return xml.dom.minidom.parseString(out_string)
|
||||
return xml.dom.minidom.parseString(out_string.encode('utf-8'))
|
||||
|
||||
def printHeader():
|
||||
print APP , VER
|
||||
|
|
@ -1119,7 +1120,7 @@ if __name__ == '__main__':
|
|||
# do the work
|
||||
in_string = input.read()
|
||||
out_string = scourString(in_string, options)
|
||||
output.write(out_string)
|
||||
output.write(out_string.encode("utf-8"))
|
||||
|
||||
# Close input and output files
|
||||
input.close()
|
||||
|
|
|
|||
10
testscour.py
10
testscour.py
|
|
@ -1,4 +1,6 @@
|
|||
#!/usr/local/bin/python
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Test Harness for Scour
|
||||
#
|
||||
# Copyright 2009 Jeff Schiller
|
||||
|
|
@ -492,6 +494,12 @@ class ChangeLineToVerticalLineSegmentInPath(unittest.TestCase):
|
|||
self.assertEquals(path[2][1][0], 100.0,
|
||||
'Did not calculate vertical line segment in path correctly' )
|
||||
|
||||
class HandleNonAsciiUtf8(unittest.TestCase):
|
||||
def runTest(self):
|
||||
doc = scour.scourXmlFile('unittests/utf8.svg')
|
||||
desc = unicode(doc.getElementsByTagNameNS(SVGNS, 'desc')[0].firstChild.wholeText).strip()
|
||||
self.assertEquals( desc, u'ú',
|
||||
'Did not handle non-ASCII characters' )
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
4
unittests/utf8.svg
Normal file
4
unittests/utf8.svg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<desc>ú</desc>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 112 B |
Loading…
Add table
Add a link
Reference in a new issue