defined unicode as str or used basestring

in py3 unicode does not exists is default str type but it exists in py2, wrote code to make it run in both py2 and py3
This commit is contained in:
MirceaDan committed 2018-12-01 17:00:37 -08:00
1 parent f72f948744
commit f416e96414
10 files changed
+33 -6

No files matched your search

+4
View File
@@ -12,6 +12,10 @@ import octoprint_client
from octoprint.cli import get_ctx_obj_option, bulk_options
from octoprint import init_settings, FatalStartupError
try:
unicode
except:
unicode =str
class JsonStringParamType(click.ParamType):
name = "json"
+1 -1
View File
@@ -447,7 +447,7 @@ class FileManager(object):
def list_files(self, destinations=None, path=None, filter=None, recursive=None):
if not destinations:
destinations = self._storage_managers.keys()
if isinstance(destinations, (str, unicode, basestring)):
if isinstance(destinations, basestring):
destinations = [destinations]
result = dict()
+1 -1
View File
@@ -1033,7 +1033,7 @@ class LocalFileStorage(StorageInterface):
def path_in_storage(self, path):
if isinstance(path, (tuple, list)):
path = self.join_path(*path)
if isinstance(path, (str, unicode, basestring)):
if isinstance(path, basestring):
path = to_unicode(path)
if path.startswith(self.basefolder):
path = path[len(self.basefolder):]
+4 -2
View File
@@ -1,6 +1,8 @@
# coding=utf-8
from __future__ import absolute_import
from past.builtins import basestring
from octoprint.logging import handlers
def log_to_handler(logger, handler, level, msg, exc_info=None, extra=None, *args):
@@ -120,7 +122,7 @@ def get_divider_line(c, message=None, length=78, indent=3):
formatted divider line
"""
assert isinstance(c, (str, unicode, bytes)), "c is not text"
assert isinstance(c, basestring), "c is not text"
assert len(c) == 1, "c is not a single character"
assert isinstance(length, int), "length is not an int"
assert isinstance(indent, int), "indent is not an int"
@@ -128,7 +130,7 @@ def get_divider_line(c, message=None, length=78, indent=3):
if message is None:
return c * length
assert isinstance(message, (str, unicode, bytes)), "message is not text"
assert isinstance(message, basestring), "message is not text"
space = length - 2 * (indent + 1)
if space >= len(message):
@@ -11,6 +11,11 @@ import sys
import traceback
import time
try:
unicode
except:
unicode = str
def _log_call(*lines):
_log(lines, prefix=">", stream="call")
+4
View File
@@ -16,6 +16,10 @@ import threading
import time
from past.builtins import basestring
try:
unicode
except:
unicode = str
from frozendict import frozendict
+4 -1
View File
@@ -24,7 +24,10 @@ import tornado.util
import octoprint.util
try:
unicode
except:
unicode = str
def fix_json_encode():
"""
+1 -1
View File
@@ -1497,7 +1497,7 @@ class Settings(object):
return value
if isinstance(value, (int, float)):
return value != 0
if isinstance(value, (str, unicode)):
if isinstance(value, basestring):
return value.lower() in valid_boolean_trues
return value is not None
+4
View File
@@ -31,6 +31,10 @@ except ImportError:
import Queue as queue
from past.builtins import basestring
try:
unicode
except:
unicode = str
logger = logging.getLogger(__name__)
+5
View File
@@ -2,6 +2,11 @@ import sys
PY3 = sys.version_info[0] == 3
try:
unicode
except:
unicode = str
if PY3:
MAXSIZE = sys.maxsize