Skip to content

Commit

Permalink
Merge master into python_3
Browse files Browse the repository at this point in the history
  • Loading branch information
LePetitTim committed Apr 16, 2019
2 parents 06b6947 + 730875c commit a74f442
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dist: xenial
sudo: required
language: python
python:
- 2.7
Expand All @@ -10,6 +9,9 @@ before_install:
- sudo apt-get install -y python-software-properties
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then virtualenv --system-site-packages venv -p python3; fi
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then virtualenv --system-site-packages venv; fi
- sudo apt-get update -qq
- sudo apt-get install -y libmapnik-dev mapnik-utils python-mapnik
- virtualenv --system-site-packages venv
- source venv/bin/activate
- pip install -r requirements.txt
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then
Expand Down
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ CHANGELOG
* Add support of Python 3.


2.4.1 (2019-03-13)
==================

* Do not try to get tiles again when tiles doesn't exist.


2.4.0 (2017-03-02)
==================

Expand Down
30 changes: 14 additions & 16 deletions landez/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
import json
from gettext import gettext as _
from pkg_resources import parse_version
<<<<<<< HEAD
try:
from urllib.parse import urlparse, urlencode
from urllib.request import urlopen, Request
except ImportError:
from urlparse import urlparse
from urllib import urlencode
from urllib2 import urlopen, Request
=======
import urllib
import requests
from urlparse import urlparse
>>>>>>> master
from tempfile import NamedTemporaryFile
from .util import flip_y

Expand Down Expand Up @@ -177,15 +183,11 @@ def tile(self, z, x, y):
sleeptime = 1
while r > 0:
try:
request = Request(url)
for header, value in self.headers.items():
request.add_header(header, value)
stream = urlopen(request)
print(stream.getcode())
assert stream.getcode() == 200
return stream.read()
except (AssertionError, IOError)as e:
print(e)
request = requests.get(url, headers=self.headers)
if request.status_code == 200:
return request.content
raise DownloadError(_("Status code : %s, url : %s") % (request.status_code, url))
except requests.exceptions.ConnectionError as e:
logger.debug(_("Download error, retry (%s left). (%s)") % (r, e))
r -= 1
time.sleep(sleeptime)
Expand Down Expand Up @@ -231,13 +233,9 @@ def tile(self, z, x, y):
url += "&bbox=%s" % bbox # commas are not encoded
try:
logger.debug(_("Download '%s'") % url)
request = Request(url)
for header, value in self.headers.items():
request.add_header(header, value)
f = urlopen(request)
header = f.info().typeheader
assert header == self.wmsParams['format'], "Invalid WMS response type : %s" % header
return f.read()
request = requests.get(url, headers=self.headers)
assert request.headers == self.wmsParams['format'], "Invalid WMS response type : %s" % self.headers
return request.content
except (AssertionError, IOError):
raise ExtractionError

Expand Down
8 changes: 7 additions & 1 deletion landez/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
import mock
import unittest
import shutil
import tempfile
Expand Down Expand Up @@ -141,14 +142,19 @@ def test_run(self):
os.remove('big.mbtiles')

def test_run_with_errors(self):
if os.path.exists('tiles.mbtiles'):
os.remove('tiles.mbtiles')
mb = MBTilesBuilder(tiles_url='http://foo.bar')
mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0), zoomlevels=[0, 1])
self.assertRaises(DownloadError, mb.run)
mb = MBTilesBuilder(tiles_url='http://foo.bar', ignore_errors=True)
mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0), zoomlevels=[0, 1])
mb.run()

def test_run_jpeg(self):
@mock.patch('requests.get')
def test_run_jpeg(self, mock_get):
mock_get.return_value.content = 'jpeg'
mock_get.return_value.status_code = 200
output = 'mq.mbtiles'
mb = MBTilesBuilder(filepath=output,
tiles_url='https://proxy-ign.openstreetmap.fr/94GjiyqD/bdortho/{z}/{x}/{y}.jpg')
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
git+https://github.com/mapbox/mbutil.git@master#egg=mbutil
Pillow == 5.1.0
requests == 2.21.0
mock == 0.7.2
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='landez',
version='2.4.1.dev0',
version='2.4.2.dev0',
author='Mathieu Leplatre',
author_email='[email protected]',
url='https://github.com/makinacorpus/landez/',
Expand All @@ -18,6 +18,7 @@
license='LPGL, see LICENSE file.',
install_requires = [
'mbutil',
'requests',
],
extras_require = {
'PIL': ["Pillow"],
Expand Down

0 comments on commit a74f442

Please sign in to comment.