unicode/basestring confabulation
This commit is contained in:
1 parent
f9916783e9
commit
6bab550830
6 files changed
+22
-23
No files matched your search
@@ -655,7 +655,7 @@ class Profile(object):
|
||||
if value is None:
|
||||
return default
|
||||
|
||||
if isinstance(value, (str, unicode, basestring)):
|
||||
if isinstance(value, basestring):
|
||||
value = value.replace(",", ".").strip()
|
||||
|
||||
try:
|
||||
@@ -670,7 +670,7 @@ class Profile(object):
|
||||
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
elif isinstance(value, (str, unicode, basestring)):
|
||||
elif isinstance(value, basestring):
|
||||
return value.lower() == "true" or value.lower() == "yes" or value.lower() == "on" or value == "1"
|
||||
elif isinstance(value, (int, float)):
|
||||
return value > 0
|
||||
@@ -707,7 +707,7 @@ class Profile(object):
|
||||
|
||||
result = []
|
||||
for k, v in profile.items():
|
||||
if isinstance(v, (str, unicode)):
|
||||
if isinstance(v, basestring):
|
||||
result.append("{k}={v}".format(k=k, v=v.encode("utf-8")))
|
||||
else:
|
||||
result.append("{k}={v}".format(k=k, v=v))
|
||||
@@ -759,7 +759,7 @@ class Profile(object):
|
||||
else:
|
||||
contents = self.get_gcode_template(key, extruder_count=extruder_count)
|
||||
|
||||
return unicode(prefix + re.sub("(.)\{([^\}]*)\}", self.replaceTagMatch, contents).rstrip() + '\n' + postfix).strip().encode('utf-8') + '\n'
|
||||
return (prefix + re.sub("(.)\{([^\}]*)\}", self.replaceTagMatch, contents).rstrip() + '\n' + postfix).strip().encode('utf-8') + '\n'
|
||||
|
||||
def get_start_gcode_prefix(self, contents, extruder_count=1):
|
||||
prefix = ""
|
||||
|
||||
@@ -16,10 +16,6 @@ import threading
|
||||
import time
|
||||
|
||||
from past.builtins import basestring
|
||||
try:
|
||||
unicode
|
||||
except:
|
||||
unicode = str
|
||||
|
||||
from frozendict import frozendict
|
||||
|
||||
@@ -362,7 +358,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
|
||||
def home(self, axes, *args, **kwargs):
|
||||
if not isinstance(axes, (list, tuple)):
|
||||
if isinstance(axes, (str, unicode)):
|
||||
if isinstance(axes, basestring):
|
||||
axes = [axes]
|
||||
else:
|
||||
raise ValueError("axes is neither a list nor a string: {axes}".format(axes=axes))
|
||||
|
||||
@@ -1928,7 +1928,7 @@ class LifecycleManager(object):
|
||||
lifecycle_callback(name, plugin)
|
||||
|
||||
def add_callback(self, events, callback):
|
||||
if isinstance(events, (str, unicode)):
|
||||
if isinstance(events, basestring):
|
||||
events = [events]
|
||||
|
||||
for event in events:
|
||||
@@ -1940,7 +1940,7 @@ class LifecycleManager(object):
|
||||
if callback in self._plugin_lifecycle_callbacks[event]:
|
||||
self._plugin_lifecycle_callbacks[event].remove(callback)
|
||||
else:
|
||||
if isinstance(events, (str, unicode)):
|
||||
if isinstance(events, basestring):
|
||||
events = [events]
|
||||
|
||||
for event in events:
|
||||
|
||||
@@ -10,6 +10,7 @@ import os
|
||||
import mimetypes
|
||||
import re
|
||||
import sys
|
||||
from past.builtins import basestring
|
||||
|
||||
import tornado
|
||||
import tornado.web
|
||||
@@ -627,7 +628,6 @@ class WsgiInputContainer(object):
|
||||
:param body: an optional body to use as ``wsgi.input`` instead of ``request.body``, can be a string or a stream
|
||||
"""
|
||||
from tornado.wsgi import to_wsgi_str
|
||||
import sys
|
||||
import io
|
||||
|
||||
# determine the request_body to supply as wsgi.input
|
||||
|
||||
@@ -977,10 +977,8 @@ class MachineCom(object):
|
||||
continue
|
||||
|
||||
def to_list(data):
|
||||
if isinstance(data, str):
|
||||
data = map(str.strip, data.split("\n"))
|
||||
elif isinstance(data, unicode):
|
||||
data = map(unicode.strip, data.split("\n"))
|
||||
if isinstance(data, basestring):
|
||||
data = list(s.strip() for s in data.split("\n"))
|
||||
|
||||
if isinstance(data, (list, tuple)):
|
||||
return list(data)
|
||||
@@ -2706,6 +2704,11 @@ class MachineCom(object):
|
||||
self.close(is_error=True)
|
||||
return None
|
||||
|
||||
try:
|
||||
ret = ret.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
ret = ret.decode('latin1')
|
||||
|
||||
if ret != "":
|
||||
try:
|
||||
self._log("Recv: " + sanitize_ascii(ret))
|
||||
@@ -3317,7 +3320,7 @@ class MachineCom(object):
|
||||
old_written = written
|
||||
|
||||
try:
|
||||
result = self._serial.write(to_send)
|
||||
result = self._serial.write(to_send.encode('utf-8'))
|
||||
if result is None or not isinstance(result, int):
|
||||
# probably some plugin not returning the written bytes, assuming all of them
|
||||
written += len(cmd)
|
||||
@@ -3326,7 +3329,7 @@ class MachineCom(object):
|
||||
except serial.SerialTimeoutException:
|
||||
self._log("Serial timeout while writing to serial port, trying again.")
|
||||
try:
|
||||
result = self._serial.write(to_send)
|
||||
result = self._serial.write(to_send.encode('utf-8'))
|
||||
if result is None or not isinstance(result, int):
|
||||
# probably some plugin not returning the written bytes, assuming all of them
|
||||
written += len(cmd)
|
||||
|
||||
+5
-5
@@ -6,16 +6,16 @@ import sys
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
try:
|
||||
unicode
|
||||
unicode
|
||||
except:
|
||||
unicode = str
|
||||
unicode = str
|
||||
|
||||
if PY3:
|
||||
MAXSIZE = sys.maxsize
|
||||
|
||||
def bytes_to_str(b):
|
||||
if isinstance(b, bytes):
|
||||
return str(b, 'utf8')
|
||||
return b.decode('utf8')
|
||||
return b
|
||||
|
||||
def str_to_bytes(s):
|
||||
@@ -45,8 +45,8 @@ else:
|
||||
del X
|
||||
|
||||
def bytes_to_str(s):
|
||||
if isinstance(s, unicode):
|
||||
return s.encode('utf-8')
|
||||
if isinstance(s, bytes):
|
||||
return s.decode('utf-8')
|
||||
return s
|
||||
|
||||
def str_to_bytes(s):
|
||||
|
||||
Reference in new issue
Block a user