rename to_str to to_bytes
This commit is contained in:
1 parent
6bf8384c35
commit
9fa20f0e52
4 files changed
+12
-8
No files matched your search
@@ -20,7 +20,7 @@ import logging
|
||||
from builtins import range, bytes
|
||||
|
||||
from octoprint.settings import settings
|
||||
from octoprint.util import atomic_write, to_str, deprecated
|
||||
from octoprint.util import atomic_write, to_bytes, deprecated
|
||||
from octoprint.access.permissions import Permissions, OctoPrintPermission
|
||||
from octoprint.access.groups import GroupChangeListener, Group
|
||||
|
||||
@@ -148,7 +148,7 @@ class UserManager(GroupChangeListener, object):
|
||||
settings().set(["accessControl", "salt"], salt)
|
||||
settings().save()
|
||||
|
||||
return hashlib.sha512(to_str(password, encoding="utf-8", errors="replace") + to_str(salt)).hexdigest()
|
||||
return hashlib.sha512(to_bytes(password, encoding="utf-8", errors="replace") + to_bytes(salt)).hexdigest()
|
||||
|
||||
def check_password(self, username, password):
|
||||
user = self.find_user(username)
|
||||
|
||||
@@ -22,7 +22,7 @@ from serial import SerialTimeoutException
|
||||
|
||||
from octoprint.settings import settings
|
||||
from octoprint.plugin import plugin_manager
|
||||
from octoprint.util import RepeatedTimer, to_str
|
||||
from octoprint.util import RepeatedTimer, to_bytes
|
||||
|
||||
class VirtualPrinter(object):
|
||||
command_regex = re.compile(r"^([GMTF])(\d+)")
|
||||
@@ -1345,7 +1345,7 @@ class VirtualPrinter(object):
|
||||
line = self.outgoing.get(timeout=timeout)
|
||||
self._seriallog.info(">>> {}".format(line.strip()))
|
||||
self.outgoing.task_done()
|
||||
return to_str(line)
|
||||
return to_bytes(line)
|
||||
except queue.Empty:
|
||||
# queue empty? return empty line
|
||||
return b""
|
||||
|
||||
@@ -561,7 +561,7 @@ def _extended_header_value(value):
|
||||
if PY3:
|
||||
return unquote(value, encoding=encoding)
|
||||
else:
|
||||
return unquote(octoprint.util.to_str(value, encoding="iso-8859-1")).decode(encoding)
|
||||
return unquote(octoprint.util.to_bytes(value, encoding="iso-8859-1")).decode(encoding)
|
||||
else:
|
||||
# no encoding provided, strip potentially present quotes and call it a day
|
||||
return octoprint.util.to_unicode(_strip_value_quotes(value), encoding="utf-8")
|
||||
|
||||
@@ -32,6 +32,7 @@ except ImportError:
|
||||
import Queue as queue
|
||||
|
||||
from past.builtins import basestring
|
||||
|
||||
try:
|
||||
unicode
|
||||
except NameError:
|
||||
@@ -501,19 +502,22 @@ def filter_non_ascii(line):
|
||||
"""
|
||||
|
||||
try:
|
||||
to_str(to_unicode(line, encoding="ascii"), encoding="ascii")
|
||||
to_bytes(to_unicode(line, encoding="ascii"), encoding="ascii")
|
||||
return False
|
||||
except ValueError:
|
||||
return True
|
||||
|
||||
|
||||
def to_str(s_or_u, encoding="utf-8", errors="strict"):
|
||||
"""Make sure ``s_or_u`` is a str."""
|
||||
def to_bytes(s_or_u, encoding="utf-8", errors="strict"):
|
||||
"""Make sure ``s_or_u`` is a bytestring."""
|
||||
if isinstance(s_or_u, unicode):
|
||||
return s_or_u.encode(encoding, errors=errors)
|
||||
else:
|
||||
return s_or_u
|
||||
|
||||
to_str = deprecated("to_str has been renamed to to_bytes", since="1.4.0")(to_bytes)
|
||||
|
||||
return to_bytes(s_or_u, encoding=encoding, errors=errors)
|
||||
|
||||
def to_unicode(s_or_u, encoding="utf-8", errors="strict"):
|
||||
"""Make sure ``s_or_u`` is a unicode string."""
|
||||
|
||||
Reference in new issue
Block a user