Commits

Philip Jenvey committed 51c4bcb

we no longer use with_unicode_literals

Comments (0)

Files changed (2)

rpython/tool/sourcetools.py

 # XXX We should try to generalize and single out one approach to dynamic
 # XXX code compilation.
 
-import types
 import sys, os, inspect, new
 import py
 
     result.func_defaults = f.func_defaults
     result.func_dict.update(f.func_dict)
     return result
-
-
-def _convert_const_maybe(x, encoding):
-    if isinstance(x, str):
-        return x.decode(encoding)
-    elif isinstance(x, tuple):
-        items = [_convert_const_maybe(item, encoding) for item in x]
-        return tuple(items)
-    return x
-
-def with_unicode_literals(fn=None, **kwds):
-    """Decorator that replace all string literals with unicode literals.
-    Similar to 'from __future__ import string literals' at function level.
-    Useful to limit changes in the py3k branch.
-    """
-    encoding = kwds.pop('encoding', 'ascii')
-    if kwds:
-        raise TypeError("Unexpected keyword argument(s): %s" % ', '.join(kwds.keys()))
-    def decorator(fn):
-        co = fn.func_code
-        new_consts = []
-        for const in co.co_consts:
-            new_consts.append(_convert_const_maybe(const, encoding))
-        new_consts = tuple(new_consts)
-        new_code = types.CodeType(co.co_argcount, co.co_nlocals, co.co_stacksize,
-                                  co.co_flags, co.co_code, new_consts, co.co_names,
-                                  co.co_varnames, co.co_filename, co.co_name,
-                                  co.co_firstlineno, co.co_lnotab)
-        fn.func_code = new_code
-        return fn
-    #
-    # support the usage of @with_unicode_literals instead of @with_unicode_literals()
-    if fn is not None:
-        assert type(fn) is types.FunctionType
-        return decorator(fn)
-    else:
-        return decorator

rpython/tool/test/test_sourcetools.py

-# -*- encoding: utf-8 -*-
-import py
 from rpython.tool.sourcetools import (
-    func_with_new_name, func_renamer, rpython_wrapper, with_unicode_literals)
+    func_renamer, func_with_new_name, rpython_wrapper)
 
 def test_rename():
     def f(x, y=5):
         ('decorated', 40, 2),
         ('bar', 40, 2),
         ]
-
-        
-def test_with_unicode_literals():
-    @with_unicode_literals()
-    def foo():
-        return 'hello'
-    assert type(foo()) is unicode
-    #
-    @with_unicode_literals
-    def foo():
-        return 'hello'
-    assert type(foo()) is unicode
-    #
-    def foo():
-        return 'hello àèì'
-    py.test.raises(UnicodeDecodeError, "with_unicode_literals(foo)")
-    #
-    @with_unicode_literals(encoding='utf-8')
-    def foo():
-        return 'hello àèì'
-    assert foo() == u'hello àèì'
-    #
-    @with_unicode_literals
-    def foo():
-        return ('a', 'b')
-    assert type(foo()[0]) is unicode
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.