Fix pubs init TypeError

The error was due to python 2 and 3 not playing nice when opening files.
This is probably linked to some botched unicode handling on our part somewhere
else is the package, and needs to be addressed when the `configs` module is
rewritten.

Also addresses some other minor unicode bugs.

Fix #27.
Related #18.
main
Fabien Benureau 9 years ago
parent 29c6eaa8b5
commit b71494ed42

@ -1,10 +1,11 @@
import os
import sys
import collections
from .p3 import configparser, ConfigParser, _read_config
from .content import check_file, _open
from . import __version__
# constant stuff (DFT = DEFAULT)
@ -23,7 +24,7 @@ DFT_CONFIG = collections.OrderedDict([
('import_copy', True),
('import_move', False),
('color', True),
('version', 5),
('version', __version__),
('version_warning', True),
('open_cmd', 'open'),
('edit_cmd', DFT_EDIT_CMD),
@ -66,12 +67,18 @@ class Config(object):
if not check_file(path, fail=False):
raise IOError(("The configuration file {} does not exist."
" Did you run 'pubs init' ?").format(path))
with _open(path, 'r+') as f:
b_flag = ''
if sys.version_info[0] == 2: # HACK, FIXME please
b_flag = 'b'
with _open(path, 'r{}+'.format(b_flag)) as f:
_read_config(self._cfg, f)
return self
def save(self, path=DFT_CONFIG_PATH):
with _open(path, 'w+') as f:
b_flag = ''
if sys.version_info[0] == 2: # HACK, FIXME please
b_flag = 'b'
with _open(path, 'w{}+'.format(b_flag)) as f:
self._cfg.write(f)
def __setattr__(self, name, value):

@ -34,7 +34,9 @@ CORE_CMDS = collections.OrderedDict([
def _update_check(config, ui):
if config.version_warning:
code_version = __version__.split('.')
repo_version = ('0.{}.0'.format(config.version)).split('.') # FIXME
if len(config.version) == 1: # support for deprecated version scheme.
config.version = '0.{}.0'.format(config.version)
repo_version = config.version.split('.')
if repo_version > code_version:
ui.warning(

@ -6,7 +6,7 @@ import codecs
from .content import editor_input
from . import color
from .p3 import _get_raw_stdout, _get_raw_stderr, input
from .p3 import _get_raw_stdout, _get_raw_stderr, input, ustr
# package-shared ui that can be accessed using :
@ -93,7 +93,7 @@ class InputUI(PrintUI):
except EOFError:
self.error(u'Standard input ended while waiting for answer.')
self.exit(1)
return data.decode('utf-8')
return ustr(data) #.decode('utf-8')
def input_choice_ng(self, options, option_chars=None, default=None, question=''):
"""Ask the user to chose between a set of options. The iser is asked

@ -83,7 +83,8 @@ class UnicodeStringIOWrapper(object):
def _force_binary_mode(mode):
if 'b' in mode:
raise ValueError('Open should not happen in binary mode.')
return mode # python 2 fix.
# raise ValueError('Open should not happen in binary mode.')
return mode + 'b'

Loading…
Cancel
Save