chnaged teh default from binary to text mode

seams like open was defaulting to text mode, since now is specified in clear i made sure it matches with teh previous default
This commit is contained in:
MirceaDan committed 2018-12-01 17:43:19 -08:00
1 parent b6e49b59a7
commit c623e90ebc
23 files changed
+42 -42

No files matched your search

+1 -1
View File
@@ -294,7 +294,7 @@ def init_logging(settings, use_logging_file=True, logging_file=None, default_con
config_from_file = {}
if os.path.exists(logging_file) and os.path.isfile(logging_file):
import yaml
with io.open(logging_file, 'rb') as f:
with io.open(logging_file, 'rt', encoding='utf-8') as f:
config_from_file = yaml.safe_load(f)
# we merge that with the default config
+1 -1
View File
@@ -131,7 +131,7 @@ def git_get_keywords(versionfile_abs):
# _version.py.
keywords = {}
try:
f = io.open(versionfile_abs, 'rb')
f = io.open(versionfile_abs, 'rt', encoding='utf-8')
for line in f.readlines():
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
+1 -1
View File
@@ -184,7 +184,7 @@ class FilebasedGroupManager(GroupManager):
def _load(self):
if os.path.exists(self._groupfile) and os.path.isfile(self._groupfile):
try:
with io.open(self._groupfile, 'rb') as f:
with io.open(self._groupfile, 'rt', encoding='utf-8') as f:
data = yaml.safe_load(f)
if not "groups" in data:
+1 -1
View File
@@ -433,7 +433,7 @@ class FilebasedUserManager(UserManager):
def _load(self):
if os.path.exists(self._userfile) and os.path.isfile(self._userfile):
self._customized = True
with io.open(self._userfile, 'rb') as f:
with io.open(self._userfile, 'rt', encoding='utf-8') as f:
data = yaml.safe_load(f)
for name in data.keys():
attributes = data[name]
+5 -5
View File
@@ -61,9 +61,9 @@ class Daemon:
# redirect standard file descriptors
sys.stdout.flush()
sys.stderr.flush()
si = io.open(os.devnull, 'rb')
so = io.open(os.devnull, 'a+')
se = io.open(os.devnull, 'a+')
si = io.open(os.devnull, 'rt', encoding='utf-8')
so = io.open(os.devnull, 'at+', encoding='utf-8')
se = io.open(os.devnull, 'at+', encoding='utf-8')
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
@@ -143,7 +143,7 @@ class Daemon:
def get_pid(self):
"""Get the pid from the pidfile."""
try:
with io.open(self.pidfile,'rb') as pf:
with io.open(self.pidfile,'rt', encoding='utf-8') as pf:
pid = int(pf.read().strip())
except (IOError, ValueError):
pid = None
@@ -151,7 +151,7 @@ class Daemon:
def set_pid(self, pid):
"""Write the pid to the pidfile."""
with io.open(self.pidfile,'wb+') as f:
with io.open(self.pidfile,'wt+', encoding='utf-8') as f:
f.write(str(pid) + '\n')
def remove_pidfile(self):
+1 -1
View File
@@ -643,7 +643,7 @@ class FileManager(object):
import yaml
try:
with io.open(self._recovery_file, 'rb') as f:
with io.open(self._recovery_file, 'rt', encoding='utf-8') as f:
data = yaml.safe_load(f)
return data
except:
+3 -3
View File
@@ -500,7 +500,7 @@ class LocalFileStorage(StorageInterface):
if os.path.exists(old_metadata_path):
# load the old metadata file
try:
with io.open(old_metadata_path, 'rb') as f:
with io.open(old_metadata_path, 'rt', encoding='utf-8') as f:
import yaml
self._old_metadata = yaml.safe_load(f)
except:
@@ -1522,7 +1522,7 @@ class LocalFileStorage(StorageInterface):
metadata_path = os.path.join(path, ".metadata.json")
if os.path.exists(metadata_path):
with io.open(metadata_path, 'rb') as f:
with io.open(metadata_path, 'rt', encoding='utf-8') as f:
try:
import json
metadata = json.load(f)
@@ -1577,7 +1577,7 @@ class LocalFileStorage(StorageInterface):
# TODO 1.3.10 Remove ".metadata.yaml" files
return
with io.open(metadata_path_yaml, 'rb') as f:
with io.open(metadata_path_yaml, 'rt', encoding='utf-8') as f:
try:
metadata = yaml.safe_load(f)
except:
+1 -1
View File
@@ -1620,7 +1620,7 @@ def is_editable_install(install_dir, package, module, location):
if os.path.isfile(package_link):
expected_target = os.path.normcase(os.path.realpath(location))
try:
with io.open(package_link, 'rb') as f:
with io.open(package_link, 'rt', encoding='utf-8') as f:
contents = f.readlines()
for line in contents:
target = os.path.normcase(os.path.realpath(os.path.join(line.strip(), module)))
+1 -1
View File
@@ -460,7 +460,7 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin,
def _load_profile(self, path):
import yaml
profile_dict = dict()
with io.open(path, 'rb') as f:
with io.open(path, 'rt', encoding='utf-8') as f:
try:
profile_dict = yaml.safe_load(f)
except:
+1 -1
View File
@@ -146,7 +146,7 @@ class LoggingPlugin(octoprint.plugin.AssetPlugin,
config_from_file = {}
if os.path.exists(logging_file) and os.path.isfile(logging_file):
import yaml
with io.open(logging_file, 'rb') as f:
with io.open(logging_file, 'rt', encoding='utf-8') as f:
config_from_file = yaml.safe_load(f)
return config_from_file
@@ -759,7 +759,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
if mtime + self._repository_cache_ttl >= time.time() > mtime:
try:
import json
with io.open(self._repository_cache_path, 'rb') as f:
with io.open(self._repository_cache_path, 'rt', encoding='utf-8') as f:
repo_data = json.load(f)
self._logger.info("Loaded plugin repository data from disk, was still valid")
except:
@@ -833,7 +833,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
if mtime + self._notices_cache_ttl >= time.time() > mtime:
try:
import json
with io.open(self._notices_cache_path, 'rb') as f:
with io.open(self._notices_cache_path, 'rt', encoding='utf-8') as f:
notice_data = json.load(f)
self._logger.info("Loaded notice data from disk, was still valid")
except:
@@ -188,7 +188,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
import yaml
try:
with io.open(self._version_cache_path, 'rb') as f:
with io.open(self._version_cache_path, 'rt', encoding='utf-8') as f:
data = yaml.safe_load(f)
timestamp = os.stat(self._version_cache_path).st_mtime
except:
@@ -1107,7 +1107,7 @@ class VirtualPrinter(object):
handle = None
try:
handle = io.open(file, 'wb')
handle = io.open(file, 'wt', encoding='utf-8')
except:
self._output("error writing to file")
if handle is not None:
@@ -1134,7 +1134,7 @@ class VirtualPrinter(object):
def _sdPrintingWorker(self):
self._selectedSdFilePos = 0
try:
with io.open(self._selectedSdFile, 'rb') as f:
with io.open(self._selectedSdFile, 'rt', encoding='utf-8') as f:
for line in iter(f.readline, ""):
if self._killed or not self._sdPrinting:
break
+1 -1
View File
@@ -431,7 +431,7 @@ class PrinterProfileManager(object):
return None
import yaml
with io.open(path, 'rb') as f:
with io.open(path, 'rt', encoding='utf-8') as f:
profile = yaml.safe_load(f)
if profile is None or not isinstance(profile, dict):
+1 -1
View File
@@ -50,7 +50,7 @@ def getInstalledLanguagePacks():
if os.path.isfile(meta_path):
import yaml
try:
with io.open(meta_path, 'rb') as f:
with io.open(meta_path, 'rt', encoding='utf-8') as f:
meta = yaml.safe_load(f)
except:
pass
+1 -1
View File
@@ -809,7 +809,7 @@ class PreemptiveCache(object):
cache_data = None
with self._lock:
try:
with io.open(self.cachefile, 'rb') as f:
with io.open(self.cachefile, 'rt', encoding='utf-8') as f:
cache_data = yaml.safe_load(f)
except IOError as e:
import errno
+4 -4
View File
@@ -868,7 +868,7 @@ class Settings(object):
def load(self, migrate=False):
if os.path.exists(self._configfile) and os.path.isfile(self._configfile):
with io.open(self._configfile, 'rb') as f:
with io.open(self._configfile, 'rt', encoding='utf-8') as f:
try:
self._config = yaml.safe_load(f)
self._mtime = self.last_modified
@@ -907,7 +907,7 @@ class Settings(object):
if isinstance(overlay, basestring):
if os.path.exists(overlay) and os.path.isfile(overlay):
with io.open(overlay, 'rb') as f:
with io.open(overlay, 'rt', encoding='utf-8') as f:
config = yaml.safe_load(f)
elif isinstance(overlay, dict):
config = overlay
@@ -1795,8 +1795,8 @@ def _validate_folder(folder, create=True, check_writable=True, deep_check_writab
# to determine whether things are *actually* writable
testfile = os.path.join(folder, ".testballoon.txt")
try:
with io.open(testfile, 'wb') as f:
f.write("test")
with io.open(testfile, 'wt', encoding='utf-8') as f:
f.write("test".decode('utf-8'))
os.remove(testfile)
except:
if log_error:
+1 -1
View File
@@ -5,7 +5,7 @@ from builtins import range
def readHex(filename):
data = []
extraAddr = 0
f = io.open(filename, 'rb')
f = io.open(filename, 'rt', encoding='utf-8')
for line in f:
line = line.strip()
if line[0] != ':':
+1 -1
View File
@@ -370,7 +370,7 @@ class PipCaller(CommandlineCaller):
return False, False, False, None
data = dict()
with io.open(testballoon_output_file, 'rb') as f:
with io.open(testballoon_output_file, 'rt', encoding='utf-8') as f:
for line in f:
key, value = line.split("=", 2)
data[key] = value
+1 -1
View File
@@ -40,7 +40,7 @@ path = os.environ.get("TESTBALLOON_OUTPUT", None)
if path is not None:
# environment variable set, write to a log
path = os.path.abspath(path)
with io.open(path, 'w+b') as output:
with io.open(path, 'wb+') as output:
produce_output(output)
else:
# write to stdout
+1 -1
View File
@@ -664,7 +664,7 @@ class LocalStorageTest(unittest.TestCase):
self.assertTrue(os.path.exists(yaml_path)) # TODO 1.3.10 change to assertFalse
import json
with io.open(json_path, 'rb') as f:
with io.open(json_path, 'rt', encoding='utf-8') as f:
json_metadata = json.load(f)
self.assertDictEqual(metadata, json_metadata)
+2 -2
View File
@@ -443,7 +443,7 @@ class TestSettings(unittest.TestCase):
def test_effective_hash(self):
with self.mocked_config():
hash = hashlib.md5()
hash.update(yaml.safe_dump(self.expected_effective))
hash.update(yaml.safe_dump(self.expected_effective).encode('utf-8'))
expected_effective_hash = hash.hexdigest()
print(yaml.safe_dump(self.expected_effective))
@@ -456,7 +456,7 @@ class TestSettings(unittest.TestCase):
def test_config_hash(self):
with self.mocked_config():
hash = hashlib.md5()
hash.update(yaml.safe_dump(self.config))
hash.update(yaml.safe_dump(self.config).encode('utf-8'))
expected_config_hash = hash.hexdigest()
settings = octoprint.settings.Settings()
+8 -8
View File
@@ -128,9 +128,9 @@ class DaemonTest(unittest.TestCase):
mock_stderr.flush.assert_called_once_with()
self.assertListEqual(mock_open.mock_calls,
[mock.call(mock_devnull, "rb"),
mock.call(mock_devnull, "a+"),
mock.call(mock_devnull, "a+")])
[mock.call(mock_devnull, 'rt', encoding='utf-8'),
mock.call(mock_devnull, 'at+', encoding='utf-8'),
mock.call(mock_devnull, 'at+', encoding='utf-8')])
self.assertListEqual(mock_dup2.mock_calls,
[mock.call("new_stdin", "stdin"),
mock.call("new_stdout", "stdout"),
@@ -396,7 +396,7 @@ class DaemonTest(unittest.TestCase):
# assert
self.assertEqual(result, pid)
m.assert_called_once_with(self.pidfile, "rb")
m.assert_called_once_with(self.pidfile, 'rt', encoding='utf-8')
def test_get_pid_ioerror(self):
# setup
@@ -409,7 +409,7 @@ class DaemonTest(unittest.TestCase):
# assert
self.assertIsNone(result)
m.assert_called_once_with(self.pidfile, "rb")
m.assert_called_once_with(self.pidfile, 'rt', encoding='utf-8')
def test_get_pid_valueerror(self):
# setup
@@ -421,7 +421,7 @@ class DaemonTest(unittest.TestCase):
# assert
self.assertIsNone(result)
m.assert_called_once_with(self.pidfile, "rb")
m.assert_called_once_with(self.pidfile, 'rt', encoding='utf-8')
def test_set_pid(self):
# setup
@@ -432,7 +432,7 @@ class DaemonTest(unittest.TestCase):
self.daemon.set_pid(pid)
# assert
m.assert_called_once_with(self.pidfile, "wb+")
m.assert_called_once_with(self.pidfile, 'wt+', encoding='utf-8')
handle = m()
handle.write.assert_called_once_with("{}\n".format(pid))
@@ -445,7 +445,7 @@ class DaemonTest(unittest.TestCase):
self.daemon.set_pid(pid)
# assert
m.assert_called_once_with(self.pidfile, "wb+")
m.assert_called_once_with(self.pidfile, 'wt+', encoding='utf-8')
handle = m()
handle.write.assert_called_once_with("{}\n".format(pid))