Skip to content

Commit 97605da

Browse files
committed
Merge remote-tracking branch 'frodrigo/master'
* frodrigo/master: Introduce langue variants #718 #811 py3: Remove unicode compatibility Fix fix filter on allow_fix_override #824
2 parents 1f1dc40 + fc3b472 commit 97605da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+43
-78
lines changed

analysers/analyser_osmosis_soundex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def analyser_osmosis_common(self):
258258
if not self.scripts:
259259
return
260260

261-
if "language" in self.config.options and self.config.options["language"] == "fr":
261+
if "language" in self.config.options and self.config.options["language"].startswith("fr"):
262262
self.run(sql01_fr)
263263
self.run(sql03.format("fn_soundex2"))
264264
else:

analysers/analyser_sax.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
from io import open # In python3 only, this import is not required
2929
from modules import OsmoseLog
3030

31-
try:
32-
unicode # Python 2
33-
except:
34-
unicode = str
35-
36-
###########################################################################
3731

3832
class Analyser_Sax(Analyser):
3933

@@ -195,6 +189,7 @@ def NodeCreate(self, data):
195189
subclass = e.get("subclass", 0)
196190
text = e.get("text", {})
197191
fix = e.get("fix")
192+
allow_fix_override = e.get('allow_fix_override')
198193

199194
self.error_file.error(
200195
classs,
@@ -203,7 +198,8 @@ def NodeCreate(self, data):
203198
[data["id"]],
204199
["node"],
205200
fix,
206-
{"position": [data], "node": [data]})
201+
{"position": [data], "node": [data]},
202+
allow_override = allow_fix_override)
207203
except:
208204
self._err("Error on error %s from %s" % (str(e), str(err)))
209205
raise
@@ -349,6 +345,7 @@ def RelationCreate(self, data):
349345
subclass = e.get("subclass", 0)
350346
text = e.get("text", {})
351347
fix = e.get("fix")
348+
allow_fix_override = e.get('allow_fix_override')
352349

353350
self.error_file.error(
354351
classs,
@@ -357,7 +354,8 @@ def RelationCreate(self, data):
357354
[data["id"]],
358355
["relation"],
359356
fix,
360-
{"position": [node], "relation": [data]})
357+
{"position": [node], "relation": [data]},
358+
allow_override = allow_fix_override)
361359
except:
362360
self._err("Error on error %s from %s" % (str(e), str(err)))
363361
raise
@@ -433,7 +431,7 @@ def _load_plugins(self):
433431
conf_limit = set()
434432
for i in ("country", "language"):
435433
if i in self.config.options:
436-
if isinstance(self.config.options[i], str) or isinstance(self.config.options[i], unicode):
434+
if isinstance(self.config.options[i], str):
437435
conf_limit.add(self.config.options[i])
438436

439437
# load plugins

mapcss/mapcss2osmose.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ def main(_, mapcss):
787787
asserts = build_tests(tests)
788788

789789
mapcss = ("""#-*- coding: utf-8 -*-
790-
from __future__ import unicode_literals
791790
import modules.mapcss_lib as mapcss
792791
import regex as re
793792

modules/DictCursorUnicode.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,10 @@
2525

2626
class DictRowUnicode50(psycopg2.extras.DictRow):
2727
def __getitem__(self, x):
28-
if sys.version_info < (3, ):
29-
# Hack to make DictRow support of unicode key in Pyhton 2
30-
if isinstance(x, unicode):
31-
return super(DictRowUnicode50, self).__getitem__(x[:50].encode('utf-8'))
32-
elif isinstance(x, str):
33-
return super(DictRowUnicode50, self).__getitem__(x.decode('utf-8')[:50].encode('utf-8'))
34-
else:
35-
return super(DictRowUnicode50, self).__getitem__(x)
28+
if isinstance(x, str):
29+
return super(DictRowUnicode50, self).__getitem__(x[:50])
3630
else:
37-
if isinstance(x, str):
38-
return super(DictRowUnicode50, self).__getitem__(x[:50])
39-
else:
40-
return super(DictRowUnicode50, self).__getitem__(x)
31+
return super(DictRowUnicode50, self).__getitem__(x)
4132

4233
class DictCursorUnicode50(psycopg2.extras.DictCursor):
4334
def __init__(self, *args, **kwargs):

modules/SourceVersion.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
import time, os
2424
import hashlib
2525

26-
try:
27-
unicode # Python 2
28-
except:
29-
unicode = str
3026

3127
def version(*sources):
3228
h = hashlib.md5()
3329
for source in sources:
34-
if (isinstance(source, str) or isinstance(source, unicode)) and os.path.exists(source):
30+
if isinstance(source, str) and os.path.exists(source):
3531
h.update(open(source, 'rb').read())
3632
elif isinstance(source, int):
3733
h.update(str(source).encode('utf-8'))

modules/downloader.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
from datetime import datetime
3030
from . import config
3131

32-
try:
33-
unicode
34-
except:
35-
unicode = str
3632

3733
HTTP_DATE_FMT = "%a, %d %b %Y %H:%M:%S GMT"
3834

@@ -226,15 +222,15 @@ def test_urlopen(self):
226222
def test_urlread(self):
227223
dst = urlread(self.url, 10)
228224
assert dst
229-
self.assertIsInstance(dst, unicode)
225+
self.assertIsInstance(dst, str)
230226
self.check_content(dst)
231227
exp_content = open(update_cache(self.url, 100), "r", encoding="utf-8").read()
232228
self.assertEqual(dst, exp_content, "urlread doesn't give expected result")
233229

234230
def test_urlread_fr(self):
235231
dst = urlread(self.url_fr, 10)
236232
assert dst
237-
self.assertIsInstance(dst, unicode)
233+
self.assertIsInstance(dst, str)
238234
self.check_content(dst)
239235
exp_content = open(update_cache(self.url_fr, 100), "r", encoding="utf-8").read()
240236
self.assertEqual(dst, exp_content, "urlread doesn't give expected result")

modules/languages.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
'fi': ['Latin'],
4646
'fo': ['Latin'],
4747
'fr': [u'[A-Za-zÉÀÈÙÂÊÎÔÛËÏÜŸÇŒÆéàèùâêîôûëïüÿçœæ]'],
48+
'fr_GF': [u'[A-Za-zÉÀÈÙÂÊÎÔÛËÏÜŸÇŒÆÃĨÕŨÖƗéàèùâêîôûëïüÿçœæãĩõũöɨ]'],
49+
'fr_LU': [u'[A-Za-zÉÀÈÙÂÊÎÔÛÄËÏÜŸÇŒÆéàèùâêîôûäëïüÿçœæ]'],
50+
'fr_PF': [u'[A-Za-zÉÀÈÙÂÊÎÔÛËÏÜŸÇŒÆĀĪŌŪéàèùâêîôûëïüÿçœæāīōū]'],
4851
'fy': ['Latin'],
4952
'ga': ['Latin'],
5053
'gl': ['Latin'],
@@ -110,7 +113,11 @@ def scripts(languages):
110113
languages = [languages]
111114
all_scripts = []
112115
for language in languages:
113-
scripts = language2scripts[language]
116+
if language in language2scripts:
117+
scripts = language2scripts[language]
118+
elif '_' in language:
119+
l = language.split('_')[0]
120+
scripts = language2scripts[l]
114121
if not scripts:
115122
return
116123
all_scripts += scripts

modules/oh_sanitizer/main.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
import lark as _lark
99
from lark.lexer import Token as _Token
1010

11-
try:
12-
unicode # Python 2
13-
except:
14-
unicode = str
15-
1611

1712
def get_parser():
1813
"""
@@ -373,7 +368,7 @@ def sanitize_field(field):
373368
"""
374369
# The exceptions catching should be modified when the next version
375370
# 'lark-parser' will be released (it introduce a better exception handling).
376-
if not isinstance(field, str) and not isinstance(field, unicode):
371+
if not isinstance(field, str):
377372
raise TypeError("The field must be a string.")
378373
if _re.match("[0-9]{4} [0-9].+", field):
379374
raise SanitizeError("This field can not be parsed properly.")

osmose_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ class gen(default_country):
506506
], **{'addr:city-admin_level': '8,9'})
507507

508508
france_departement_dom("guadeloupe", 1401835, "FR-GP", dep_code=971, proj=32620, phone_code="590")
509-
france_departement_dom("guyane", 1260551, "FR-GF", dep_code=973, proj=2972, phone_code="594")
509+
france_departement_dom("guyane", 1260551, "FR-GF", dep_code=973, language='fr_GF', proj=2972, phone_code="594")
510510
france_departement_dom("martinique", 1891495, "FR-MQ", dep_code=972, proj=32620, phone_code="596")
511511
france_departement_dom("mayotte", 1259885, "FR-YT", dep_code=976, proj=32738, phone_code="262")
512512
france_departement_dom("reunion", 1785276, "FR-RE", dep_code=974, proj=2975, phone_code="262")
@@ -527,7 +527,7 @@ class gen(default_country):
527527
france_com(["central-america", "saint_martin"], 1891583, "FR-MF", proj=2969, phone_code="590", country="saintmartin")
528528
france_com(["north-america", "saint_pierre_et_miquelon"], 233377, "FR-PM", proj=32621, phone_code="508", country="saintpierreetmiquelon")
529529
france_com(["south-america", "wallis_et_futuna"], 290162, "FR-WF", proj=32701, phone_code="681", country="wallisetfutuna")
530-
france_com(["south-america", "polynesie"], 3412620, "FR-PF", proj=32706, phone_code="689", phone_len=9)
530+
france_com(["south-america", "polynesie"], 3412620, "FR-PF", language='fr_PF', proj=32706, phone_code="689", phone_len=9)
531531
france_com(["australia-oceania", "new-caledonia"], 3407643, "NC", download_repo=GEOFABRIK, proj=3163, country="nouvellecaledonie",
532532
phone_code="687", phone_len=6, phone_format=r"^[+]%s([- ./]*[0-9]){5}[0-9]$", phone_international='00')
533533

@@ -600,7 +600,7 @@ class gen(default_country):
600600
del(lithuania.analyser["osmosis_highway_cul-de-sac_level"]) # follow official highway classification
601601
del(lithuania.analyser["osmosis_highway_broken_level_continuity"]) # follow official highway classification
602602
default_country("europe", "latvia", 72594, {"country": "LV","language": "lv", "proj": 32634}, download_repo=GEOFABRIK)
603-
default_country("europe", "luxembourg", 2171347, {"country": "LU", "language": "lb", "proj": 2169, "boundary_detail_level": 6})
603+
default_country("europe", "luxembourg", 2171347, {"country": "LU", "language": "fr_LU", "proj": 2169, "boundary_detail_level": 6})
604604
default_country("europe", "malta", 365307, {"country": "MT", "language": "en", "driving_side": "left", "proj": 32633})
605605
default_country("europe", "macedonia", 53293, {"country": "MK", "language": "sq", "proj": 32634})
606606
default_country("europe", "moldova", 58974, {"country": "MD", "language": "ro", "proj": 32635}, download_repo=GEOFABRIK)

plugins/Bicycle.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#-*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
32
import modules.mapcss_lib as mapcss
43
import regex as re
54

0 commit comments

Comments
 (0)