Fix unicode/text prompt_toolkit changes

Currently it appears that a new prompt_toolkit version
only works with text (unicode) so ensure that we convert
any formed strings into text to ensure prompt toolkit
doesn't raise an exception when prompting.

Change-Id: Id4139a03532bd4f8c9a1bc38dd10a24590153de5
This commit is contained in:
Joshua Harlow 2016-10-17 15:09:08 -07:00
parent 88976a5f69
commit ac74dd2d89

View File

@ -58,6 +58,15 @@ Notes:
""" """
def to_unicode(blob, encoding='utf8'):
if isinstance(blob, six.text_type):
return blob
elif isinstance(blob, six.binary_type):
return blob.decode(encoding)
else:
raise TypeError("Unable to convert %r to a text type" % blob)
class NoEmptyValidator(Validator): class NoEmptyValidator(Validator):
def validate(self, document): def validate(self, document):
text = document.text.strip() text = document.text.strip()
@ -105,8 +114,7 @@ def yes_no_prompt(title, default=True):
def clean_changes(changes): def clean_changes(changes):
for line in changes: for line in changes:
if isinstance(line, six.binary_type): line = to_unicode(line)
line = line.decode("utf8")
sha, descr = line.split(" ", 1) sha, descr = line.split(" ", 1)
yield sha, descr yield sha, descr
@ -171,26 +179,28 @@ def maybe_create_release(release_repo_path, deliverable_info,
" may lose comments and some existing" " may lose comments and some existing"
" yaml indenting/structure)? ") " yaml indenting/structure)? ")
else: else:
notes_link = NOTES_URL_TPL % (short_project, latest_cycle) notes_link = to_unicode(
NOTES_URL_TPL % (short_project, latest_cycle))
notes_link = prompt( notes_link = prompt(
"Release notes link: ", "Release notes link: ",
validator=NoEmptyValidator(), validator=NoEmptyValidator(),
default=notes_link) default=notes_link)
if deliverable_info: if deliverable_info:
launchpad_project = deliverable_info['launchpad'] launchpad_project = to_unicode(deliverable_info['launchpad'])
announce_email = deliverable_info['send-announcements-to'] announce_email = to_unicode(
deliverable_info['send-announcements-to'])
else: else:
launchpad_project = prompt( launchpad_project = prompt(
"Launchpad project name: ", "Launchpad project name: ",
validator=NoEmptyValidator(), validator=NoEmptyValidator(),
default=short_project) default=to_unicode(short_project))
announce_email = prompt( announce_email = prompt(
"Announcement email address: ", "Announcement email address: ",
validator=NoEmptyValidator(), validator=NoEmptyValidator(),
default=ANNOUNCE_EMAIL) default=ANNOUNCE_EMAIL)
team = prompt("Project team: ", team = prompt("Project team: ",
validator=NoEmptyValidator(), validator=NoEmptyValidator(),
default=launchpad_project) default=to_unicode(launchpad_project))
include_pypi_link = yes_no_prompt("Include pypi link? ") include_pypi_link = yes_no_prompt("Include pypi link? ")
newest_release = collections.OrderedDict([ newest_release = collections.OrderedDict([
('launchpad', launchpad_project), ('launchpad', launchpad_project),
@ -212,7 +222,7 @@ def maybe_create_release(release_repo_path, deliverable_info,
suggested_version = '' suggested_version = ''
version = prompt("Release version: ", version = prompt("Release version: ",
validator=NoEmptyValidator(), validator=NoEmptyValidator(),
default=suggested_version) default=to_unicode(suggested_version))
highlights = prompt("Highlights (esc then enter to" highlights = prompt("Highlights (esc then enter to"
" exit): ", multiline=True) " exit): ", multiline=True)
highlights = highlights.strip() highlights = highlights.strip()