Revision: 2604
Author: janne.t.harkonen
Date: Thu Mar  4 05:45:32 2010
Log: fix unicode behavior with Jython, cleanup
http://code.google.com/p/robotframework/source/detail?r=2604

Modified:
 /trunk/src/robot/utils/misc.py

=======================================
--- /trunk/src/robot/utils/misc.py      Mon Feb 22 05:30:03 2010
+++ /trunk/src/robot/utils/misc.py      Thu Mar  4 05:45:32 2010
@@ -196,24 +196,33 @@

     Rationale: os.path.relpath is not available before Python 2.6
     """
-    target = target.encode('UTF-8')
+    pathname =  _get_pathname(target, base)
+    url = urllib.pathname2url(pathname.encode('UTF-8'))
+    if os.path.isabs(pathname):
+        pre = url.startswith('/') and 'file:' or 'file:///'
+        url = pre + url
+    # Want consistent url on all platforms/interpreters
+    return url.replace('%5C', '/').replace('%3A', ':').replace('|', ':')
+
+def _get_pathname(target, base):
     target = normpath(target)
     base = normpath(base)
     if os.path.isfile(base):
         base = os.path.dirname(base)
     if base == target:
-        return urllib.pathname2url(os.path.basename(target))
+        return os.path.basename(target)
     base_drive, base_path = os.path.splitdrive(base)
     # if in Windows and base and link on different drives
     if os.path.splitdrive(target)[0] != base_drive:
-        return 'file:' + urllib.pathname2url(target)
+        return target
     common_len = len(_common_path(base, target))
     if base_path == os.sep:
-        return urllib.pathname2url(target[common_len:])
+        return target[common_len:]
     if common_len == len(base_drive) + len(os.sep):
         common_len -= len(os.sep)
     dirs_up = os.sep.join([os.pardir] * base[common_len:].count(os.sep))
- return urllib.pathname2url(os.path.join(dirs_up, target[common_len + len(os.sep):]))
+    return os.path.join(dirs_up, target[common_len + len(os.sep):])
+


 def _common_path(p1, p2):

Reply via email to