🐛 Some more unicode vs bytes fixes
This commit is contained in:
1 parent
1b876f1cf3
commit
3c5aa60d2b
4 files changed
+15
-6
No files matched your search
@@ -29,6 +29,8 @@ class AsyncLogHandlerMixin(logging.Handler):
|
||||
class CleaningTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs["encoding"] = kwargs.get("encoding", "utf-8")
|
||||
|
||||
super(CleaningTimedRotatingFileHandler, self).__init__(*args, **kwargs)
|
||||
|
||||
# clean up old files on handler start
|
||||
@@ -40,6 +42,10 @@ class CleaningTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler
|
||||
class OctoPrintLogHandler(AsyncLogHandlerMixin, CleaningTimedRotatingFileHandler):
|
||||
rollover_callbacks = []
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs["encoding"] = kwargs.get("encoding", "utf-8")
|
||||
super(OctoPrintLogHandler, self).__init__(*args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def registerRolloverCallback(cls, callback, *args, **kwargs):
|
||||
cls.rollover_callbacks.append((callback, args, kwargs))
|
||||
@@ -67,6 +73,7 @@ class SerialLogHandler(AsyncLogHandlerMixin, logging.handlers.RotatingFileHandle
|
||||
cls.do_rollover = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs["encoding"] = kwargs.get("encoding", "utf-8")
|
||||
super(SerialLogHandler, self).__init__(*args, **kwargs)
|
||||
self.cleanupFiles()
|
||||
|
||||
|
||||
@@ -109,7 +109,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
]
|
||||
|
||||
def on_startup(self, host, port):
|
||||
console_logging_handler = logging.handlers.RotatingFileHandler(self._settings.get_plugin_logfile_path(postfix="console"), maxBytes=2*1024*1024)
|
||||
console_logging_handler = logging.handlers.RotatingFileHandler(self._settings.get_plugin_logfile_path(postfix="console"),
|
||||
maxBytes=2*1024*1024,
|
||||
encoding="utf-8")
|
||||
console_logging_handler.setFormatter(logging.Formatter("%(asctime)s %(message)s"))
|
||||
console_logging_handler.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
@@ -1315,7 +1315,7 @@ var getQueryParameterByName = function(name, url) {
|
||||
* E.g. turns a null byte in the string into "\x00".
|
||||
*
|
||||
* Characters 0 to 31 excluding 9, 10 and 13 will be escaped, as will
|
||||
* 127 and 255. That should leave printable characters and unicode
|
||||
* 127, 128 to 159 and 255. That should leave printable characters and unicode
|
||||
* alone.
|
||||
*
|
||||
* Originally based on
|
||||
@@ -1330,7 +1330,7 @@ var escapeUnprintableCharacters = function(str) {
|
||||
var charCode;
|
||||
|
||||
while (!isNaN(charCode = str.charCodeAt(index))) {
|
||||
if ((charCode < 32 && charCode != 9 && charCode != 10 && charCode != 13) || charCode == 127 || charCode == 255) {
|
||||
if ((charCode < 32 && charCode !== 9 && charCode !== 10 && charCode !== 13) || charCode === 127 || (charCode >= 128 && charCode <= 159) || charCode === 255) {
|
||||
// special hex chars
|
||||
result += "\\x" + (charCode > 15 ? "" : "0") + charCode.toString(16)
|
||||
} else {
|
||||
|
||||
@@ -2713,10 +2713,10 @@ class MachineCom(object):
|
||||
|
||||
if ret != "":
|
||||
try:
|
||||
self._log("Recv: " + sanitize_ascii(ret))
|
||||
self._log("Recv: {}".format(sanitize_ascii(ret)))
|
||||
except ValueError as e:
|
||||
self._log("WARN: While reading last line: %s" % e)
|
||||
self._log("Recv: " + repr(ret))
|
||||
self._log("WARN: While reading last line: {}".format(e))
|
||||
self._log("Recv: {!r}".format(ret))
|
||||
|
||||
for name, hook in self._received_message_hooks.items():
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user