Revision: caf67bedf5af
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Thu Oct 10 09:50:02 2013 UTC
Log: Support \U escapes with ordinals over 0xFFFF also with narror builds.

Also fixed \x, \u and \U not to work like \x+1 or \u+123.

Update issue 1524
Small fixes.y
http://code.google.com/p/robotframework/source/detail?r=caf67bedf5af

Modified:
 /src/robot/utils/escaping.py
 /utest/utils/test_escaping.py

=======================================
--- /src/robot/utils/escaping.py        Wed Sep 18 07:58:48 2013 UTC
+++ /src/robot/utils/escaping.py        Thu Oct 10 09:50:02 2013 UTC
@@ -80,23 +80,23 @@

     def _unescape_character(self, text, length, escape):
         try:
-            char = self._get_character(text, length)
+            char = self._get_character(text[:length], length)
         except ValueError:
             return escape + text
         else:
             return char + text[length:]

     def _get_character(self, text, length):
-        ordinal = self._get_ordinal(text, length)
-        try:
-            return unichr(ordinal)
-        except (OverflowError, TypeError):
+        if len(text) < length or not text.isalnum():
             raise ValueError
-
-    def _get_ordinal(self, text, length):
-        if len(text) < length:
+        ordinal = int(text, 16)
+        # No Unicode code points above 0x10FFFF
+        if ordinal > 0x10FFFF:
             raise ValueError
-        return int(text[:length], 16)
+ # unichr only supports ordinals up to 0xFFFF with narrow Python builds
+        if ordinal > 0xFFFF:
+            return eval("u'\\U%08x'" % ordinal)
+        return unichr(ordinal)


 class EscapeFinder(object):
=======================================
--- /utest/utils/test_escaping.py       Wed Sep 18 09:01:36 2013 UTC
+++ /utest/utils/test_escaping.py       Thu Oct 10 09:50:02 2013 UTC
@@ -80,7 +80,7 @@
             assert_unescape(inp, exp)

     def test_invalid_x(self):
-        for inp in r'\x \xxx xx\xxx \x0 \x0g \X00'.split():
+        for inp in r'\x \xxx xx\xxx \x0 \x0g \X00 \x-1 \x+1'.split():
             assert_unescape(inp, inp.replace('\\', ''))

     def test_valid_x(self):
@@ -90,7 +90,15 @@
             assert_unescape(inp, exp)

     def test_invalid_u(self):
-        for inp in r'\u \ukekkonen b\uu \u0 \u123 \u123x'.split():
+        for inp in r'''\u
+                       \ukekkonen
+                       b\uu
+                       \u0
+                       \u123
+                       \u123x
+                       \u-123
+                       \u+123
+                       \u1.23'''.split():
             assert_unescape(inp, inp.replace('\\', ''))

     def test_valid_u(self):
@@ -100,21 +108,27 @@
             assert_unescape(inp, exp)

     def test_invalid_U(self):
-        for inp in r'\U \Ukekkonen b\Uu \U0 \U1234567 \U1234567x'.split():
+        for inp in r'''\U
+                       \Ukekkonen
+                       b\Uu
+                       \U0
+                       \U1234567
+                       \U1234567x
+                       \U-1234567
+                       \U+1234567
+                       \U1.234567'''.split():
             assert_unescape(inp, inp.replace('\\', ''))

     def test_valid_U(self):
-        try:
- u00010905 = unichr(int('00010905', 16)) # PHOENICIAN LETTER WAU
-        except ValueError:  # occurs on "narrow" Python builds
-            u00010905 = 'U00010905'
         for inp, exp in [(r'\U00000000', u'\x00'),
                          (r'\U0000ABba', u'\uabba'),
-                         (r'\U00010905', u00010905),
+                         (r'\U0001f3e9', u'\U0001f3e9'),
+                         (r'\U0010FFFF', u'\U0010ffff'),
                          (r'\U000000e4iti', u'\xe4iti')]:
             assert_unescape(inp, exp)

     def test_U_above_valid_range(self):
+        assert_unescape(r'\U00110000', 'U00110000')
         assert_unescape(r'\U12345678', 'U12345678')
         assert_unescape(r'\UffffFFFF', 'UffffFFFF')

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to