Skip to content

Commit

Permalink
Drop usage of six in modRana code
Browse files Browse the repository at this point in the history
There is still some usage in the bundled code though.
  • Loading branch information
M4rtinK committed Apr 13, 2020
1 parent 899aed5 commit 4ce4d45
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 50 deletions.
5 changes: 2 additions & 3 deletions core/routing_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import time
from core import constants
from core.way import Way
from core.backports import six

from urllib.request import urlopen

Expand Down Expand Up @@ -199,9 +198,9 @@ def _googleDirections(start, destination, waypoints, params):

# check if start and destination are string,
# otherwise convert to lat,lon strings from Points
if not isinstance(start, six.string_types):
if not isinstance(start, str):
start = "%f,%f" % (start.lat, start.lon)
if not isinstance(destination, six.string_types):
if not isinstance(destination, str):
destination = "%f,%f" % (destination.lat, destination.lon)

if not waypoints: waypoints = []
Expand Down
10 changes: 4 additions & 6 deletions core/tile_storage/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Various tile handling utility functions"""
import six
from six import b
import os
import logging

Expand All @@ -17,13 +15,13 @@ def is_an_image(tile_data):
# NOTE: magic numbers taken from imghdr source code

# as most tiles are PNGs, check for PNG first
if h[:8] == b("\211PNG\r\n\032\n"):
if h[:8] == b"\211PNG\r\n\032\n":
return "png"
elif h[6:10] in (b('JFIF'), b('Exif')): # JPEG in JFIF or Exif format
elif h[6:10] in (b'JFIF', b'Exif'): # JPEG in JFIF or Exif format
return "jpg"
elif h[:6] in (b('GIF87a'), b('GIF89a')): # GIF ('87 and '89 variants)
elif h[:6] in (b'GIF87a', b'GIF89a'): # GIF ('87 and '89 variants)
return "gif"
elif h[:2] in (b('MM'), b('II'), b('BM')): # tiff or BMP
elif h[:2] in (b'MM', b'II', b'BM'): # tiff or BMP
return "bmp"
else: # probably not an image file
return False
Expand Down
12 changes: 4 additions & 8 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

from core import constants
from core import qrc
from core.backports.six import b
from core.backports import six

StringIO = six.moves.cStringIO

from urllib.parse import urlparse as urllib_parse

Expand Down Expand Up @@ -165,13 +161,13 @@ def is_the_string_an_image(s):
# NOTE: magic numbers taken from imghdr source code

# as most tiles are PNGs, check for PNG first
if s[:8] == b("\211PNG\r\n\032\n"):
if s[:8] == b"\211PNG\r\n\032\n":
return True
elif s[6:10] in (b('JFIF'), b('Exif')): # JPEG in JFIF or Exif format
elif s[6:10] in (b'JFIF', b'Exif'): # JPEG in JFIF or Exif format
return True
elif s[:6] in (b('GIF87a'), b('GIF89a')): # GIF ('87 and '89 variants)
elif s[:6] in (b'GIF87a', b'GIF89a'): # GIF ('87 and '89 variants)
return True
elif s[:2] in (b('MM'), b('II'), b('BM')): # tiff or BMP
elif s[:2] in (b'MM', b'II', b'BM'): # tiff or BMP
return True
else: # probably not an image file
return False
Expand Down
3 changes: 1 addition & 2 deletions modrana.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def set_correct_CWD():
from core import threads
from core import gs
from core import singleton
from core.backports import six
# record that imports-done timestamp
importsDoneTimestamp = time.time()

Expand Down Expand Up @@ -866,7 +865,7 @@ def _remove_non_persistent_options(self, inputDict):
ASSUMPTION: keys are strings of length>=1
"""
try:
return dict((k, v) for k, v in six.iteritems(inputDict) if k[0] != '#')
return dict((k, v) for k, v in inputDict.items() if k[0] != '#')
except Exception:
log.exception('options: error while filtering options\nsome nonpersistent keys might have been left in\nNOTE: keys should be strings of length>=1')
return self.d
Expand Down
5 changes: 0 additions & 5 deletions modules/gui_modules/gui_qt5/gui_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,11 +864,6 @@ def _addressSearchCB(self, results):
self._addressSearchInProgress = False
self._addressSignal.emit()

#addressStatus = QtCore.Property(six.text_type,
# lambda x: x._addressSearchStatus, notify=_addressSignal)
#
#addressInProgress = QtCore.Property(bool,
# lambda x: x._addressSearchInProgress, notify=_addressSignal)

class ModRana(object):
"""
Expand Down
3 changes: 1 addition & 2 deletions modules/mod_location/gps_module/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# BSD terms apply: see the file COPYING in the distribution root for details.

import time, calendar, math
from core.backports import six

# some multipliers for interpreting GPS output
METERS_TO_FEET = 3.2808399 # Meters to U.S./British feet
Expand Down Expand Up @@ -61,7 +60,7 @@ def isotime(s):
msec = s - date
date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(s))
return date + "." + repr(msec)[3:]
elif type(s) == type("") or type(s) == type(six.u("")):
elif type(s) == type("") or type(s) == type(u""):
if s[-1] == "Z":
s = s[:-1]
if "." in s:
Expand Down
5 changes: 2 additions & 3 deletions modules/mod_mapLayers/mod_mapLayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from modules.base_module import RanaModule
from core.signal import Signal
from core.backports import six
from core.layers import MapLayer, MapLayerGroup
from .overlay_groups import OverlayGroup

Expand Down Expand Up @@ -167,7 +166,7 @@ def _parseLayers(self):
# check if there is at least one valid layer

layerDefinitions = self.modrana.configs.map_config.get('layers', {})
for layerId, layerDefinition in six.iteritems(layerDefinitions):
for layerId, layerDefinition in layerDefinitions.items():
if self._hasRequiredKeys(layerDefinition, MAP_LAYER_REQUIRED_KEYS):
self._layers[layerId] = MapLayer(layerId, layerDefinition)
else:
Expand All @@ -184,7 +183,7 @@ def _parseGroups(self):
# configuration file has any
if self.modrana.configs.map_config:
groupsDict = self.modrana.configs.map_config.get('groups', {})
for groupId, groupDefinition in six.iteritems(groupsDict):
for groupId, groupDefinition in groupsDict.items():
if self._hasRequiredKeys(groupDefinition, MAP_LAYER_GROUP_REQUIRED_KEYS):
self._groups[groupId] = MapLayerGroup(self, groupId, groupDefinition)

Expand Down
8 changes: 4 additions & 4 deletions modules/mod_mapTiles/mod_mapTiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------
from modules.base_module import RanaModule

import threading
import time

from queue import Queue

import urllib3

from core import utils
from core import tiles
from core import constants
from core.backports import six
from core.signal import Signal
from core import threads

from .tile_downloader import Downloader

StringIO = six.moves.cStringIO

#import socket
#timeout = 30 # this sets timeout for all sockets
#socket.setdefaulttimeout(timeout)
Expand Down Expand Up @@ -109,7 +109,7 @@ def __init__(self, *args, **kwargs):

self._tileDownloaded = Signal()

self._dlRequestQueue = six.moves.queue.Queue()
self._dlRequestQueue = Queue()
self._downloader = None

@property
Expand Down
3 changes: 1 addition & 2 deletions modules/mod_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from modules.base_module import RanaModule

from core.signal import Signal
from core.backports import six
from core import qrc

from core import utils
Expand Down Expand Up @@ -165,7 +164,7 @@ def _loadConfigFile(self, path):
if 'colors' in config:
colors = config['colors']
colorObjects = {}
for key, color in six.iteritems(colors):
for key, color in colors.items():
if len(color) == 2: # hex color/color name and alpha as float 0-1
colorString = color[0]
colorObjects[key] = colorString
Expand Down
30 changes: 15 additions & 15 deletions modules/mod_tileserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
#---------------------------------------------------------------------------
import random
import sys
from threading import Thread
from core.backports import six

# TODO replace this with something Python 3 compatible
SimpleHTTPServer = six.moves.SimpleHTTPServer
SocketServer = six.moves.socketserver

from threading import Thread
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
from urllib.error import HTTPError
from io import StringIO

from modules.base_module import RanaModule
from modules import tileserver_callback_proxy

import logging
server_log = logging.getLogger("mod.tileserver.server")


def getModule(*args, **kwargs):
return Tileserver(*args, **kwargs)
Expand Down Expand Up @@ -64,7 +64,7 @@ def runServer(self):
# self.tileserverPort = random.randint(8000,9000)


# Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
# Handler = SimpleHTTPRequestHandler


try:
Expand Down Expand Up @@ -109,26 +109,26 @@ def shutdown(self):
self.stopServer()


class Server(SocketServer.TCPServer):
class Server(TCPServer):
# def __init__(self, tuple, callback):
# SocketServer.TCPServer.init(tuple, "")
# self.callback = callback

class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Proxy(SimpleHTTPRequestHandler):
def __init__(self, request, client_address):
try:
SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, request, client_address, self)
SimpleHTTPRequestHandler.__init__(self, request, client_address, self)
except:
SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, request, client_address, self)
SimpleHTTPRequestHandler.__init__(self, request, client_address, self)

def do_GET(self):
split = self.path.split("/")
layer = split[1]
z = int(split[2])
x = int(split[3])
y = int(split[4].split(".")[0])
self.log.debug(self.path)
self.log.debug(tileserver_callback_proxy.cb._mapTiles)
server_log.debug(self.path)
server_log.debug(tileserver_callback_proxy.cb._mapTiles)
try:
tileData = tileserver_callback_proxy.cb._mapTiles.getTile(layer, z, x, y)
if tileData:
Expand All @@ -141,12 +141,12 @@ def do_GET(self):
# self.send_header('Date', self.date_time_string())
self.end_headers()

self.log.debug("GET returning file")
server_log.debug("GET returning file")

self.wfile.write(StringIO(tileData).read())
return True
else:
self.log.debug("GET tile not found")
server_log.debug("GET tile not found")
return False
except HTTPError:
e = sys.exc_info()[1]
Expand Down

0 comments on commit 4ce4d45

Please sign in to comment.