comparison flys-backend/contrib/shpimporter/utils.py @ 4935:c0a58558b817 dami

Importer: - Handle regular expressions for attribute names - Convert Strings to UTF-8 - Add regular expressions for hws_points values
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 31 Jan 2013 12:23:41 +0100
parents 1f6e544f7a7f
children 174fbaa3d344
comparison
equal deleted inserted replaced
4934:11b459a3eb5c 4935:c0a58558b817
18 if (idx+len(SHP)) == len(f): 18 if (idx+len(SHP)) == len(f):
19 shapes.append((f.replace(SHP, ''), root + "/" + f)) 19 shapes.append((f.replace(SHP, ''), root + "/" + f))
20 20
21 return shapes 21 return shapes
22 22
23 def getUTF8(string):
24 """
25 Tries to convert the string to a UTF-8 encoding by first checking if it
26 is UTF-8 and then trying cp1252
27 """
28 try:
29 return unicode.encode(unicode(string, "UTF-8"), "UTF-8")
30 except UnicodeDecodeError:
31 # Probably European Windows names so lets try again
32 return unicode.encode(unicode(string, "cp1252"), "UTF-8")
33
23 def getUTF8Path(path): 34 def getUTF8Path(path):
24 """ 35 """
25 Tries to convert path to utf-8 by first checking the filesystemencoding 36 Tries to convert path to utf-8 by first checking the filesystemencoding
26 and trying the default windows encoding afterwards. 37 and trying the default windows encoding afterwards.
27 Returns a valid UTF-8 encoded unicode object or throws a UnicodeDecodeError 38 Returns a valid UTF-8 encoded unicode object or throws a UnicodeDecodeError

http://dive4elements.wald.intevation.org