2 new revisions:

Revision: 96e552b344e9
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Thu Dec 12 12:20:48 2013 UTC
Log:      Remote: refactored for easier enhancement
http://code.google.com/p/robotframework/source/detail?r=96e552b344e9

Revision: 43b7accb3895
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Thu Dec 12 13:30:36 2013 UTC
Log: Remote: Handle binary arguments by wrapping them with xmlrpclib.Binary...
http://code.google.com/p/robotframework/source/detail?r=43b7accb3895

==============================================================================
Revision: 96e552b344e9
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Thu Dec 12 12:20:48 2013 UTC
Log:      Remote: refactored for easier enhancement
http://code.google.com/p/robotframework/source/detail?r=96e552b344e9

Modified:
 /src/robot/libraries/Remote.py

=======================================
--- /src/robot/libraries/Remote.py      Wed Dec 11 18:49:51 2013 UTC
+++ /src/robot/libraries/Remote.py      Thu Dec 12 12:20:48 2013 UTC
@@ -12,10 +12,10 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

-import xmlrpclib
 import socket
+import sys
 import time
-import sys
+import xmlrpclib
 try:
     from xml.parsers.expat import ExpatError
 except ImportError:   # No expat in IronPython 2.7
@@ -57,25 +57,44 @@
             return ''

     def run_keyword(self, name, args, kwargs):
-        args = self._handle_argument(args)
-        kwargs = self._handle_argument(kwargs)
+        coercer = ArgumentCoercer()
+        args = coercer.coerce(args)
+        kwargs = coercer.coerce(kwargs)
         result = RemoteResult(self._client.run_keyword(name, args, kwargs))
         sys.stdout.write(result.output)
         if result.status != 'PASS':
             raise RemoteError(result.error, result.traceback)
         return result.return_

-    def _handle_argument(self, arg):
-        if isinstance(arg, (basestring, int, long, float)):
-            return arg
-        if is_list_like(arg):
-            return [self._handle_argument(item) for item in arg]
-        if is_dict_like(arg):
-            return dict((self._str(key), self._handle_argument(value))
-                        for key, value in arg.items())
-        return self._str(arg)
+
+class ArgumentCoercer(object):
+
+    def coerce(self, arg):
+        for handles, handle in [(self._is_string, self._pass_through),
+                                (self._is_number, self._pass_through),
+                                (is_list_like, self._coerce_list),
+                                (is_dict_like, self._coerce_dict),
+                                (lambda arg: True, self._to_string)]:
+            if handles(arg):
+                return handle(arg)
+
+    def _is_string(self, arg):
+        return isinstance(arg, basestring)
+
+    def _is_number(self, arg):
+        return isinstance(arg, (int, long, float))
+
+    def _pass_through(self, arg):
+        return arg
+
+    def _coerce_list(self, arg):
+        return [self.coerce(item) for item in arg]
+
+    def _coerce_dict(self, arg):
+        return dict((self._to_string(key), self.coerce(value))
+                    for key, value in arg.items())

-    def _str(self, item):
+    def _to_string(self, item):
         if item is None:
             return ''
         return unic(item)

==============================================================================
Revision: 43b7accb3895
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Thu Dec 12 13:30:36 2013 UTC
Log: Remote: Handle binary arguments by wrapping them with xmlrpclib.Binary.

Update issue 1606
Status: Started
Owner: pekka.klarck
Cc: janne.piiro...@gmail.com
Remote now handles arguments correctly (1a).
http://code.google.com/p/robotframework/source/detail?r=43b7accb3895

Modified:
 /atest/robot/standard_libraries/remote/argument_types.txt
 /atest/testdata/standard_libraries/remote/argument_types.txt
 /atest/testdata/standard_libraries/remote/arguments.py
 /src/robot/libraries/Remote.py

=======================================
--- /atest/robot/standard_libraries/remote/argument_types.txt Thu Dec 12 09:53:20 2013 UTC +++ /atest/robot/standard_libraries/remote/argument_types.txt Thu Dec 12 13:30:36 2013 UTC
@@ -20,7 +20,9 @@
     Check Test Case    ${TESTNAME}

 Binary data
-    Fail    not ready yet    -regression
+    Check Test Case    ${TESTNAME}
+
+Binary data with too big Unicode characters
     Check Test Case    ${TESTNAME}

 Arbitrary object
=======================================
--- /atest/testdata/standard_libraries/remote/argument_types.txt Thu Dec 12 09:53:20 2013 UTC +++ /atest/testdata/standard_libraries/remote/argument_types.txt Thu Dec 12 13:30:36 2013 UTC
@@ -31,8 +31,13 @@
     None    ''

 Binary data
-    '\\x00\\x01\\xff'
-    u'\\x00\\x01\\xff'    '\\x00\\x01\\xff'
+    '\\x00\\x01\\xff'    binary=yes
+    u'\\x00\\x01'    '\\x00\\x01'    binary=yes
+
+Binary data with too big Unicode characters
+    [Template]  Run Keyword And Expect Error
+ ValueError: Cannot represent u'\\x00\\x01\\xff' as binary. One Argument \x00\x01\xff + ValueError: Cannot represent u'\\x00\\x01\\u2603' as binary. One Argument \x00\x01\u2603

 Arbitrary object
     ${MyObject()}    '<MyObject>'
@@ -63,7 +68,7 @@

 *** Keywords ***
 Argument Should Be Accepted
-    [Arguments]    ${argument}    ${expected}=${NONE}
+    [Arguments]    ${argument}    ${expected}=${NONE}    ${binary}=${FALSE}
     ${expected} =    Get Non None    ${expected}   ${argument}
     ${argument} =    Evaluate If String    ${argument}
-    Argument Should Be    ${argument}    ${expected}
+    Argument Should Be    ${argument}    ${expected}    ${binary}
=======================================
--- /atest/testdata/standard_libraries/remote/arguments.py Thu Dec 12 09:53:20 2013 UTC +++ /atest/testdata/standard_libraries/remote/arguments.py Thu Dec 12 13:30:36 2013 UTC
@@ -1,6 +1,7 @@
 import sys
 import inspect
 from SimpleXMLRPCServer import SimpleXMLRPCServer
+from xmlrpclib import Binary


 class RemoteServer(SimpleXMLRPCServer):
@@ -41,10 +42,12 @@

 class Arguments(object):

-    def argument_should_be(self, argument, expected):
+    def argument_should_be(self, argument, expected, binary=False):
+        if binary:
+            assert isinstance(argument, Binary), 'Non-binary argument'
+            argument = str(argument)
         expected = eval(expected)
-        if argument != expected:
-            raise AssertionError('%r != %r' % (argument, expected))
+        assert argument == expected, '%r != %r' % (argument, expected)

     def no_arguments(self):
         return self._format_args()
=======================================
--- /src/robot/libraries/Remote.py      Thu Dec 12 12:20:48 2013 UTC
+++ /src/robot/libraries/Remote.py      Thu Dec 12 13:30:36 2013 UTC
@@ -12,6 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

+import re
 import socket
 import sys
 import time
@@ -68,9 +69,10 @@


 class ArgumentCoercer(object):
+    binary = re.compile('[\x00-\x08\x0B\x0C\x0E-\x1F]')

     def coerce(self, arg):
-        for handles, handle in [(self._is_string, self._pass_through),
+        for handles, handle in [(self._is_string, self._handle_string),
                                 (self._is_number, self._pass_through),
                                 (is_list_like, self._coerce_list),
                                 (is_dict_like, self._coerce_dict),
@@ -84,6 +86,15 @@
     def _is_number(self, arg):
         return isinstance(arg, (int, long, float))

+    def _handle_string(self, arg):
+        if not self.binary.search(arg):
+            return arg
+        try:
+            arg = str(arg)
+        except UnicodeError:
+            raise ValueError("Cannot represent %r as binary." % arg)
+        return xmlrpclib.Binary(arg)
+
     def _pass_through(self, arg):
         return arg

--

--- 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