mirror of
https://github.com/tbabej/taskwiki.git
synced 2025-08-19 06:43:06 +02:00
python3: Data structures accesed from vim return bytes
This commit is contained in:
parent
d0014a47a2
commit
edb148cad4
2 changed files with 26 additions and 0 deletions
|
@ -59,6 +59,12 @@ class TaskCache(object):
|
|||
default_data = vim.vars.get('taskwiki_data_location') or '~/.task'
|
||||
extra_warrior_defs = vim.vars.get('taskwiki_extra_warriors', {})
|
||||
|
||||
# Handle bytes (vim returnes bytes for Python3)
|
||||
if six.PY3:
|
||||
default_rc = util.decode_bytes(default_rc)
|
||||
default_data = util.decode_bytes(default_data)
|
||||
extra_warrior_defs = util.decode_bytes(extra_warrior_defs)
|
||||
|
||||
self.buffer = BufferProxy(vim.current.buffer.number)
|
||||
self.task = store.TaskStore(self)
|
||||
self.vwtask = store.VwtaskStore(self)
|
||||
|
|
|
@ -372,3 +372,23 @@ def enforce_dependencies(cache):
|
|||
if taskwarrior_required_version > taskwarrior_installed_version:
|
||||
raise TaskWikiException("Taskwarrior version at least %s is required."
|
||||
% TASKWARRIOR_VERSION)
|
||||
|
||||
def decode_bytes(var):
|
||||
"""
|
||||
Data structures obtained from vim under python3 will return bytestrings.
|
||||
Make sure we can handle that.
|
||||
"""
|
||||
|
||||
if isinstance(var, bytes):
|
||||
return var.decode()
|
||||
|
||||
if isinstance(var, list):
|
||||
return list([decode_bytes(element) for element in var])
|
||||
|
||||
if isinstance(var, dict) or 'vim.dictionary' in str(type(var)):
|
||||
return {
|
||||
decode_bytes(key): decode_bytes(value)
|
||||
for key, value in var.items()
|
||||
}
|
||||
|
||||
return var
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue