Revision: 3636
Author: pekka.klarck
Date: Fri May 28 04:35:33 2010
Log: inlided wrap utility
http://code.google.com/p/robotframework/source/detail?r=3636
Modified:
/trunk/src/robot/utils/argumentparser.py
/trunk/src/robot/utils/text.py
/trunk/utest/utils/test_argumentparser.py
=======================================
--- /trunk/src/robot/utils/argumentparser.py Thu May 27 07:11:21 2010
+++ /trunk/src/robot/utils/argumentparser.py Fri May 28 04:35:33 2010
@@ -20,11 +20,11 @@
import glob
import string
import codecs
+import textwrap
from robot.errors import DataError, Information, FrameworkError
from misc import plural_or_not
-from text import wrap
from unic import unic
@@ -377,17 +377,18 @@
return ret
def _get_available_escapes(self):
- names = ESCAPES.keys()
- names.sort()
- return ', '.join([ '%s (%s)' % (n, ESCAPES[n]) for n in names ])
+ names = sorted(ESCAPES.keys(), key=str.lower)
+ return ', '.join('%s (%s)' % (n, ESCAPES[n]) for n in names)
def _raise_help(self):
msg = self._usage
if self._version:
msg = msg.replace('<VERSION>', self._version)
def replace_escapes(res):
- escapes = 'Available escapes:\n' +
self._get_available_escapes()
- return wrap(escapes, len(res.group(2)), len(res.group(1)))
+ escapes = 'Available escapes: ' + self._get_available_escapes()
+ lines = textwrap.wrap(escapes, width=len(res.group(2)))
+ indent = ' ' * len(res.group(1))
+ return '\n'.join(indent + line for line in lines)
msg = re.sub('( *)(<-+ESCAPES-+>)', replace_escapes, msg)
raise Information(msg)
=======================================
--- /trunk/src/robot/utils/text.py Thu May 27 07:11:21 2010
+++ /trunk/src/robot/utils/text.py Fri May 28 04:35:33 2010
@@ -74,26 +74,3 @@
value = value[:_MAX_ASSIGN_LENGTH] + '...'
return '%s = %s' % (variable, value)
-
-def wrap(text, width, indent=0):
- """Wraps given text so that it fits into given width with optional
indent.
-
- Preserves existing line breaks and most spaces in the text. Expects
that
- existing line breaks are posix newlines (\n).
-
- Based on a recipe from ActiveState Python Cookbook at
- http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/148061
- """
- text = reduce(lambda line, word, width=width: '%s%s%s' %
- (line,
- ' \n'[(len(line)-line.rfind('\n')-1
- + len(word.split('\n',1)[0]
- ) >= width)],
- word),
- text.split(' ')
- )
- if not indent > 0:
- return text
- pre = ' ' * indent
- joiner = '\n' + pre
- return pre + joiner.join(text.splitlines())
=======================================
--- /trunk/utest/utils/test_argumentparser.py Thu Mar 25 02:03:41 2010
+++ /trunk/utest/utils/test_argumentparser.py Fri May 28 04:35:33 2010
@@ -264,12 +264,11 @@
--he"""
expected = """Name
--escape x:y blaa
blaa .............................................. end
- Available escapes:
- amp (&), apos ('), at (@), bslash (\), colon (:), comma
(,),
- curly1 ({), curly2 (}), dollar ($), exclam (!), gt (>),
hash
- (#), lt (<), paren1 ((), paren2 ()), percent (%), pipe
(|),
- quest (?), quot ("), semic (;), slash (/), space ( ),
- square1 ([), square2 (]), star (*)
+ Available escapes: amp (&), apos ('), at (@), bslash
(\),
+ colon (:), comma (,), curly1 ({), curly2 (}), dollar
($),
+ exclam (!), gt (>), hash (#), lt (<), paren1 ((), paren2
+ ()), percent (%), pipe (|), quest (?), quot ("), semic
(;),
+ slash (/), space ( ), square1 ([), square2 (]), star (*)
-- next line --
--he"""
assert_raises_with_msg(Information, expected,