Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lg_char_escaping(self):
formatter = Formatter(True)
self.assertEqual('foosome info',
formatter.format('\\some info\\')
)
self.assertEqual(
'\\some info\\',
Formatter.escape('some info')
)
message = '{} '.format(message)
elif isinstance(question, ConfirmationQuestion):
message = '{} (yes/no) [{}] '.format(
message,
'yes' if default else 'no'
)
elif isinstance(question, ChoiceQuestion) and question.multiselect:
choices = question.choices
default = default.split(',')
for i, value in enumerate(default):
default[i] = choices[int(value.strip())]
message = '{} [{}]:'.format(
message,
Formatter.escape(', '.join(default))
)
elif isinstance(question, ChoiceQuestion):
choices = question.choices
message = '{} [{}]:'.format(
message,
Formatter.escape(choices[int(default)])
)
if isinstance(question, ChoiceQuestion):
if len(question.choices) > 1:
width = max(*map(self.len, [str(k) for k, _ in enumerate(question.choices)]))
else:
width = self.len('0')
messages = [message]
for key, value in enumerate(question.choices):
messages = [messages]
lines = []
# Add type
if type is not None:
messages[0] = '[%s] %s' % (type, messages[0])
if indent_on_type:
for key, message in enumerate(messages[1:]):
key = key + 1
messages[key] = ' ' * (Helper.len(type) + 1 + 2) + message
# Wrap and add newlines for each element
for key, message in enumerate(messages):
message = Formatter.escape(message)
wrap_limit = self._line_length - Helper.len(prefix)
lines += os.linesep.join(textwrap.wrap(message, wrap_limit)).split(os.linesep)
if messages and key < len(messages) - 1:
lines.append('')
if padding and self.is_decorated():
lines.insert(0, '')
lines.append('')
new_lines = []
for line in lines:
line = '%s%s' % (prefix, line)
line += ' ' * (self._line_length - Helper.len_without_decoration(self.get_formatter(), line))
elif isinstance(question, ChoiceQuestion) and question.multiselect:
choices = question.choices
default = default.split(',')
for i, value in enumerate(default):
default[i] = choices[int(value.strip())]
message = '{} [{}]:'.format(
message,
Formatter.escape(', '.join(default))
)
elif isinstance(question, ChoiceQuestion):
choices = question.choices
message = '{} [{}]:'.format(
message,
Formatter.escape(choices[int(default)])
)
if isinstance(question, ChoiceQuestion):
if len(question.choices) > 1:
width = max(*map(self.len, [str(k) for k, _ in enumerate(question.choices)]))
else:
width = self.len('0')
messages = [message]
for key, value in enumerate(question.choices):
messages.append(' [{:{}}] {}'.format(key, width, value))
output.writeln(messages)
message = question.prompt
def format_block(self, messages, style, large=False):
messages = [messages] if not isinstance(messages, (list, tuple)) else messages
l = 0
lines = []
for message in messages:
message = Formatter.escape(message)
lines.append((' %s ' if large else ' %s ') % message)
l = max(len(message) + (4 if large else 2), l)
messages = [' ' * l] if large else []
for line in lines:
messages.append(line + ' ' * (l - len(line)))
if large:
messages.append(' ' * l)
messages = map(lambda m: '<%s>%s' % (style, m, style), messages)
return '\n'.join(messages)