Browse Source

Drop Python 2.x support

- Fix urllib for Python 3.
master
Bogdan Cordier 1 year ago
parent
commit
3fbdadd5d1
5 changed files with 14 additions and 29 deletions
  1. 10
    15
      hadaly/app.py
  2. 0
    2
      hadaly/editor.py
  3. 0
    1
      hadaly/painter.py
  4. 4
    10
      hadaly/search.py
  5. 0
    1
      hadaly/viewer.py

+ 10
- 15
hadaly/app.py View File

@@ -1,5 +1,4 @@
1 1
 # -*- coding: utf-8 -*-
2
-from __future__ import division, unicode_literals, absolute_import
3 2
 import shutil
4 3
 
5 4
 from kivy import require
@@ -13,10 +12,6 @@ from .meta import version as app_version
13 12
 import urllib
14 13
 import re
15 14
 
16
-try:
17
-    from urlparse import urlparse
18
-except ImportError:
19
-    from urllib.parse import urlparse
20 15
 from lxml import html
21 16
 import tempfile
22 17
 
@@ -357,7 +352,7 @@ class HadalyApp(App):
357 352
         return result
358 353
 
359 354
     def request(self, url):
360
-        url = urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
355
+        url = urllib.parse.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
361 356
         req = UrlRequest(url, debug=True)
362 357
         req.wait()
363 358
         return req.result
@@ -366,9 +361,9 @@ class HadalyApp(App):
366 361
         pb = ProgressBar(id='_pb')
367 362
         self.progress_dialog = Popup(title='Downloading...',
368 363
                                      size_hint=(0.5, 0.2), content=pb, auto_dismiss=False)
369
-        url = urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
364
+        url = urllib.parse.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
370 365
         path = os.path.join(self.tempdir,
371
-                            os.path.basename(urlparse(url).path))
366
+                            os.path.basename(urllib.parse.urlparse(url).path))
372 367
         headers = {"User-Agent": "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"}
373 368
         req = UrlRequest(url, self.reload_slide, file_path=path, on_progress=self.show_download_progress,
374 369
                          req_headers=headers, debug=True)
@@ -382,12 +377,12 @@ class HadalyApp(App):
382 377
 
383 378
     def reload_slide(self, request, data):
384 379
         Logger.debug('Application: Download finished, reloading slide source.')
385
-        slide_path = urlparse(request.url)
380
+        slide_path = urllib.parse.urlparse(request.url)
386 381
         filename = os.path.basename(slide_path[2])
387 382
 
388 383
         slides = [slide for slide in self.root.get_screen('editor').slides_view.grid_layout.children]
389 384
         for slide in slides:
390
-            img_src = urlparse(slide.img.img_src)
385
+            img_src = urllib.parse.urlparse(slide.img.img_src)
391 386
             if img_src[0] == 'http' and img_src[2].endswith(filename):
392 387
                 Logger.debug('Application: Found slide ! Updating image source...')
393 388
                 slide.img.img_src = os.path.join(self.tempdir, filename)
@@ -434,7 +429,7 @@ class HadalyApp(App):
434 429
         url = engines[engine].format(term=term,
435 430
                                      rpp=self.config.get('search', 'search_rpp'),
436 431
                                      page=page)
437
-        clean_url = urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
432
+        clean_url = urllib.parse.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
438 433
 
439 434
         UrlRequest(clean_url, on_success=self.parse_results, debug=True)
440 435
 
@@ -443,7 +438,7 @@ class HadalyApp(App):
443 438
         search_screen = self.root.get_screen('search')
444 439
         results = []
445 440
 
446
-        if 'metmuseum' in urlparse(request.url).hostname:
441
+        if 'metmuseum' in urllib.parse.urlparse(request.url).hostname:
447 442
 
448 443
             try:
449 444
                 total_pages = tree.xpath(
@@ -464,13 +459,13 @@ class HadalyApp(App):
464 459
                         object.xpath('./div[@class="list-view-object-info"]/div[@class="artist"]/text()')[::2][0]
465 460
                 except IndexError:
466 461
                     result['artist'] = 'Unknown'
467
-                result['thumb'] = urllib.quote(object.xpath('./div[@class="list-view-thumbnail"]//img/@src')[0],
462
+                result['thumb'] = urllib.parse.quote(object.xpath('./div[@class="list-view-thumbnail"]//img/@src')[0],
468 463
                                                safe="%/:=&?~#+!$,;'@()*[]")
469 464
                 object_info = object.xpath('./div[@class="list-view-object-info"]/div[@class="objectinfo"]/text()')
470 465
                 result['year'] = object_info[0].strip('Dates: ')
471 466
                 results.append(result)
472 467
 
473
-        elif 'getty' in urlparse(request.url).hostname:
468
+        elif 'getty' in urllib.parse.urlparse(request.url).hostname:
474 469
 
475 470
             try:
476 471
                 search_screen.box.total_pages = tree.xpath('//td[@class="cs-page"]//input/@count')[0]
@@ -490,7 +485,7 @@ class HadalyApp(App):
490 485
             obj_link = tree.xpath(
491 486
                 '//div[@class="cs-result-data-brief"]//td[* = "Title:" or * = "Primary Title:"]/following-sibling::td[1]/p[@class="cs-record-link"]/a/@href')
492 487
 
493
-            results = [{'title': a, 'artist': b, 'year': c, 'thumb': urllib.quote(d, safe="%/:=&?~#+!$,;'@()*[]"),
488
+            results = [{'title': a, 'artist': b, 'year': c, 'thumb': urllib.parse.quote(d, safe="%/:=&?~#+!$,;'@()*[]"),
494 489
                         'obj_link': e}
495 490
                        for a, b, c, d, e in zip(titles, artists, dates, thumb, obj_link)]
496 491
 

+ 0
- 2
hadaly/editor.py View File

@@ -1,6 +1,4 @@
1 1
 # -*- coding: utf-8 -*-
2
-from __future__ import division, unicode_literals, absolute_import
3
-
4 2
 import os
5 3
 from functools import partial
6 4
 

+ 0
- 1
hadaly/painter.py View File

@@ -1,5 +1,4 @@
1 1
 # -*- coding: utf-8 -*-
2
-from __future__ import division, unicode_literals
3 2
 
4 3
 import math
5 4
 from kivy.uix.widget import Widget

+ 4
- 10
hadaly/search.py View File

@@ -1,10 +1,4 @@
1 1
 # -*- coding: utf-8 -*-
2
-from __future__ import division, unicode_literals, absolute_import
3
-
4
-try:
5
-    from urlparse import urlparse, parse_qs
6
-except ImportError:
7
-    from urllib.parse import urlparse, parse_qs
8 2
 import urllib
9 3
 from lxml import html
10 4
 
@@ -112,7 +106,7 @@ class SearchItemInfo(Popup):
112 106
         if self.provider == 'MET':
113 107
             # Check if high-res is available.
114 108
             url = self.photo['thumb'].replace('web-thumb', 'original')
115
-            req = urllib.urlopen(url)
109
+            req = urllib.request.urlopen(url)
116 110
             if req.getcode() == 404:
117 111
                 Logger.debug('Search: High-res image not available.')
118 112
                 self.app.show_popup(_('Error'), _('High-res image not available, downloading inferior quality.'))
@@ -124,12 +118,12 @@ class SearchItemInfo(Popup):
124 118
 
125 119
         elif self.provider == 'Getty':
126 120
 
127
-            req = urllib.urlopen(self.photo['obj_link'])
121
+            req = urllib.request.urlopen(self.photo['obj_link'])
128 122
             tree = html.parse(req)
129 123
             img_link = tree.xpath('//div[@class="cs-result-image"]//span[@class="nav"]/a/@href')
130 124
             if img_link:
131
-                link = urlparse(tree.xpath('//div[@class="cs-result-image"]//span[@class="nav"]/a/@href')[0])
132
-                url = parse_qs(link.query)['dlimgurl'][0]
125
+                link = urllib.parse.urlparse(tree.xpath('//div[@class="cs-result-image"]//span[@class="nav"]/a/@href')[0])
126
+                url = urllib.parse.parse_qs(link.query)['dlimgurl'][0]
133 127
             else:
134 128
                 url = self.photo['thumb']
135 129
             slide.img_src = url

+ 0
- 1
hadaly/viewer.py View File

@@ -1,5 +1,4 @@
1 1
 # -*- coding: utf-8 -*-
2
-from __future__ import division, unicode_literals, absolute_import
3 2
 
4 3
 from kivy.uix.screenmanager import Screen
5 4
 from kivy.uix.scatter import Matrix

Loading…
Cancel
Save