Commits

Armin Rigo committed 379d125

Found the proper way: try except ImportError. Sorry if e.g. you had
troubles with older pypy-c's.

Comments (0)

Files changed (13)

lib_pypy/_hashlib.py

     return hash(ctx, name)
 
 # shortcut functions
-import __pypy__
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
 
-@__pypy__.builtinify
+@builtinify
 def openssl_md5(string=''):
     return new('md5', string)
 
-@__pypy__.builtinify
+@builtinify
 def openssl_sha1(string=''):
     return new('sha1', string)
 
-@__pypy__.builtinify
+@builtinify
 def openssl_sha224(string=''):
     return new('sha224', string)
 
-@__pypy__.builtinify
+@builtinify
 def openssl_sha256(string=''):
     return new('sha256', string)
 
-@__pypy__.builtinify
+@builtinify
 def openssl_sha384(string=''):
     return new('sha384', string)
 
-@__pypy__.builtinify
+@builtinify
 def openssl_sha512(string=''):
     return new('sha512', string)
-

lib_pypy/_locale.py

 # load the platform-specific cache made by running locale.ctc.py
 from ctypes_config_cache._locale_cache import *
 
-import __pypy__
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
 
 
 # Ubuntu Gusty i386 structure
     ul = ''.join(ul)
     string.letters = ul
 
-@__pypy__.builtinify
+@builtinify
 def setlocale(category, locale=None):
     "(integer,string=None) -> string. Activates/queries locale processing."
     if locale:
         groups.append(0)
     return groups
 
-@__pypy__.builtinify
+@builtinify
 def localeconv():
     "() -> dict. Returns numeric and monetary locale-specific parameters."
 
     }
     return result
 
-@__pypy__.builtinify
+@builtinify
 def strcoll(s1, s2):
     "string,string -> int. Compares two strings according to the locale."
 
     # Collate the strings.
     return _wcscoll(s1, s2)
 
-@__pypy__.builtinify
+@builtinify
 def strxfrm(s):
     "string -> string. Returns a string that behaves for cmp locale-aware."
 
         _strxfrm(buf, s, n2)
     return buf.value
 
-@__pypy__.builtinify
+@builtinify
 def getdefaultlocale():
     # TODO: Port code from CPython for Windows and Mac OS
     raise NotImplementedError()
         raise ValueError("unsupported langinfo constant")
 
 if HAS_LIBINTL:
-    @__pypy__.builtinify
+    @builtinify
     def gettext(msg):
         """gettext(msg) -> string
         Return translation of msg."""
         return _gettext(msg)
 
-    @__pypy__.builtinify
+    @builtinify
     def dgettext(domain, msg):
         """dgettext(domain, msg) -> string
         Return translation of msg in domain."""
         return _dgettext(domain, msg)
 
-    @__pypy__.builtinify
+    @builtinify
     def dcgettext(domain, msg, category):
         """dcgettext(domain, msg, category) -> string
         Return translation of msg in domain and category."""
         return _dcgettext(domain, msg, category)
 
-    @__pypy__.builtinify
+    @builtinify
     def textdomain(domain):
         """textdomain(domain) -> string
         Set the C library's textdomain to domain, returning the new domain."""
         return _textdomain(domain)
 
-    @__pypy__.builtinify
+    @builtinify
     def bindtextdomain(domain, dir):
         """bindtextdomain(domain, dir) -> string
         Bind the C library's domain to dir."""
         return dirname
 
     if HAS_BIND_TEXTDOMAIN_CODESET:
-        @__pypy__.builtinify
+        @builtinify
         def bind_textdomain_codeset(domain, codeset):
             """bind_textdomain_codeset(domain, codeset) -> string
             Bind the C library's domain to codeset."""

lib_pypy/_marshal.py

 import types
 from _codecs import utf_8_decode, utf_8_encode
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+
 TYPE_NULL     = '0'
 TYPE_NONE     = 'N'
 TYPE_FALSE    = 'F'
 
 version = 1
 
+@builtinify
 def dump(x, f, version=version):
     # XXX 'version' is ignored, we always dump in a version-0-compatible format
     m = _Marshaller(f.write)
     m.dump(x)
 
+@builtinify
 def load(f):
     um = _Unmarshaller(f.read)
     return um.load()
 
+@builtinify
 def dumps(x, version=version):
     # XXX 'version' is ignored, we always dump in a version-0-compatible format
     buffer = []
     m.dump(x)
     return ''.join(buffer)
 
+@builtinify
 def loads(s):
     um = _FastUnmarshaller(s)
     return um.load()

lib_pypy/_minimal_curses.py

 
 # ____________________________________________________________
 
-import __pypy__
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
 
-@__pypy__.builtinify
+@builtinify
 def setupterm(termstr, fd):
     err = ctypes.c_int(0)
     result = clib.setupterm(termstr, fd, ctypes.byref(err))
     if result == ERR:
         raise error("setupterm() failed (err=%d)" % err.value)
 
-@__pypy__.builtinify
+@builtinify
 def tigetstr(cap):
     result = clib.tigetstr(cap)
     if ctypes.cast(result, ctypes.c_void_p).value == ERR:
         return None
     return ctypes.cast(result, ctypes.c_char_p).value
 
-@__pypy__.builtinify
+@builtinify
 def tparm(str, i1=0, i2=0, i3=0, i4=0, i5=0, i6=0, i7=0, i8=0, i9=0):
     result = clib.tparm(str, i1, i2, i3, i4, i5, i6, i7, i8, i9)
     if result is None:

lib_pypy/cPickle.py

 
 from pickle import *
 from pickle import __doc__, __version__, format_version, compatible_formats
-import __pypy__
+
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
 
 BadPickleGet = KeyError
 UnpickleableError = PicklingError
     def getvalue(self):
         return self.__f and self.__f.getvalue()
 
-@__pypy__.builtinify
+@builtinify
 def dump(obj, file, protocol=None):
     Pickler(file, protocol).dump(obj)
 
-@__pypy__.builtinify
+@builtinify
 def dumps(obj, protocol=None):
     file = StringIO()
     Pickler(file, protocol).dump(obj)

lib_pypy/cmath.py

 
 # much code borrowed from mathmodule.c
 
-import math, __pypy__
+import math
 from math import e, pi
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
 
 # constants
 _one = complex(1., 0.)
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def acos(x):
     """acos(x)
 
     return -(_prodi(log((x+(_i*sqrt((_one-(x*x))))))))
 
 
-@__pypy__.builtinify
+@builtinify
 def acosh(x):
     """acosh(x)
 
     return z+z
 
 
-@__pypy__.builtinify
+@builtinify
 def asin(x):
     """asin(x)
 
     return -(_prodi(log((sqrt_1_minus_x_sq+_prodi(x)))))
 
 
-@__pypy__.builtinify
+@builtinify
 def asinh(x):
     """asinh(x)
 
     return z+z
 
 
-@__pypy__.builtinify
+@builtinify
 def atan(x):
     """atan(x)
     
     return _halfi*log(((_i+x)/(_i-x)))
 
 
-@__pypy__.builtinify
+@builtinify
 def atanh(x):
     """atanh(x)
 
     return _half*log((_one+x)/(_one-x))
 
 
-@__pypy__.builtinify
+@builtinify
 def cos(x):
     """cos(x)
 
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def cosh(x):
     """cosh(x)
     
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def exp(x):
     """exp(x)
     
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def log(x, base=None):
     """log(x)
 
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def log10(x):
     """log10(x)
 
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def sin(x):
     """sin(x)
 
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def sinh(x):
     """sinh(x)
 
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def sqrt(x):
     """sqrt(x)
 
 _sqrt_half = sqrt(_half)
 
 
-@__pypy__.builtinify
+@builtinify
 def tan(x):
     """tan(x)
 
     return complex(real, imag)
 
 
-@__pypy__.builtinify
+@builtinify
 def tanh(x):
     """tanh(x)
 
 """ This module provides ctypes version of cpython's grp module
 """
 
-import sys, __pypy__
+import sys
 if sys.platform == 'win32':
     raise ImportError("No grp module on Windows")
 
 from ctypes import Structure, c_char_p, c_int, POINTER
 from ctypes_support import standard_c_lib as libc
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+
 gid_t = c_int
 
 class GroupStruct(Structure):
     return Group(res.contents.gr_name, res.contents.gr_passwd,
                  res.contents.gr_gid, mem)
 
-@__pypy__.builtinify
+@builtinify
 def getgrgid(gid):
     res = libc.getgrgid(gid)
     if not res:
         raise KeyError(gid)
     return _group_from_gstruct(res)
 
-@__pypy__.builtinify
+@builtinify
 def getgrnam(name):
     if not isinstance(name, str):
         raise TypeError("expected string")
         raise KeyError(name)
     return _group_from_gstruct(res)
 
-@__pypy__.builtinify
+@builtinify
 def getgrall():
     libc.setgrent()
     lst = []

lib_pypy/itertools.py

            'ifilterfalse', 'imap', 'islice', 'izip', 'repeat', 'starmap',
            'takewhile', 'tee']
 
-import __pypy__
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
 
 
 class chain(object):
         return self
 
 
-@__pypy__.builtinify
+@builtinify
 def tee(iterable, n=2):
     """Return n independent iterators from a single iterable.
     Note : once tee() has made a split, the original iterable

lib_pypy/msvcrt.py

 from ctypes_support import standard_c_lib as _c
 from ctypes_support import get_errno
 import errno
-import __pypy__
 
 try:
     open_osfhandle = _c._open_osfhandle
 except AttributeError: # we are not on windows
     raise ImportError
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+
 open_osfhandle.argtypes = [ctypes.c_int, ctypes.c_int]
 open_osfhandle.restype = ctypes.c_int
 
 _locking.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
 _locking.restype = ctypes.c_int
 
-@__pypy__.builtinify
+@builtinify
 def locking(fd, mode, nbytes):
     '''lock or unlock a number of bytes in a file.'''
     rv = _locking(fd, mode, nbytes)
 exception is raised if the entry asked for cannot be found.
 """
 
-import sys, __pypy__
+import sys
 if sys.platform == 'win32':
     raise ImportError("No pwd module on Windows")
 
 from ctypes_support import standard_c_lib as libc
 from ctypes import Structure, POINTER, c_int, c_char_p
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+
 uid_t = c_int
 gid_t = c_int
 
 _endpwent.argtypes = None
 _endpwent.restype = None
 
-@__pypy__.builtinify
+@builtinify
 def mkpwent(pw):
     pw = pw.contents
     return struct_passwd(pw)
 
-@__pypy__.builtinify
+@builtinify
 def getpwuid(uid):
     """
     getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,
         raise KeyError("getpwuid(): uid not found: %s" % uid)
     return mkpwent(pw)
 
-@__pypy__.builtinify
+@builtinify
 def getpwnam(name):
     """
     getpwnam(name) -> (pw_name,pw_passwd,pw_uid,
         raise KeyError("getpwname(): name not found: %s" % name)
     return mkpwent(pw)
 
-@__pypy__.builtinify
+@builtinify
 def getpwall():
     """
     getpwall() -> list_of_entries

lib_pypy/pyexpat.py

 import ctypes
 import ctypes.util
 from ctypes import c_char_p, c_int, c_void_p, POINTER, c_char, c_wchar_p
-import sys, __pypy__
+import sys
 
 # load the platform-specific cache made by running pyexpat.ctc.py
 from ctypes_config_cache._pyexpat_cache import *
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
 
 lib = ctypes.CDLL(ctypes.util.find_library('expat'))
 
         new_parser._set_unknown_encoding_handler()
         return new_parser
 
-@__pypy__.builtinify
+@builtinify
 def ErrorString(errno):
     return XML_ErrorString(errno)[:200]
 
-@__pypy__.builtinify
+@builtinify
 def ParserCreate(encoding=None, namespace_separator=None, intern=None):
     if (not isinstance(encoding, str) and
         not encoding is None):

lib_pypy/resource.py

-import sys, __pypy__
+import sys
 if sys.platform == 'win32':
     raise ImportError('resource module not available for win32')
 
 from errno import EINVAL, EPERM
 import _structseq
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+
 class error(Exception):
     pass
 
     ru_nvcsw = _structseq.structseqfield(14)
     ru_nivcsw = _structseq.structseqfield(15)
 
-@__pypy__.builtinify
+@builtinify
 def rlimit_check_bounds(rlim_cur, rlim_max):
     if rlim_cur > rlim_t_max:
         raise ValueError("%d does not fit into rlim_t" % rlim_cur)
         ("rlim_max", rlim_t),
     )
 
-@__pypy__.builtinify
+@builtinify
 def getrusage(who):
     ru = _struct_rusage()
     ret = _getrusage(who, byref(ru))
         ru.ru_nivcsw,
         ))
 
-@__pypy__.builtinify
+@builtinify
 def getrlimit(resource):
     if not(0 <= resource < RLIM_NLIMITS):
         return ValueError("invalid resource specified")
         raise error(errno)
     return (rlim.rlim_cur, rlim.rlim_max)
 
-@__pypy__.builtinify
+@builtinify
 def setrlimit(resource, rlim):
     if not(0 <= resource < RLIM_NLIMITS):
         return ValueError("invalid resource specified")
         else:
             raise error(errno)
 
-@__pypy__.builtinify
+@builtinify
 def getpagesize():
     pagesize = 0
     if _getpagesize:

lib_pypy/syslog.py

 syslog facility.
 """
 
-import sys, __pypy__
+import sys
 if sys.platform == 'win32':
     raise ImportError("No syslog on Windows")
 
 from ctypes_support import standard_c_lib as libc
 from ctypes import c_int, c_char_p
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+
 # Real prototype is:
 # void syslog(int priority, const char *format, ...);
 # But we also need format ("%s") and one format argument (message)
 _setlogmask.argtypes = (c_int,)
 _setlogmask.restype = c_int
 
-@__pypy__.builtinify
+@builtinify
 def openlog(ident, option, facility):
     _openlog(ident, option, facility)
 
-@__pypy__.builtinify
+@builtinify
 def syslog(arg1, arg2=None):
     if arg2 is not None:
         priority, message = arg1, arg2
         priority, message = LOG_INFO, arg1
     _syslog(priority, "%s", message)
 
-@__pypy__.builtinify
+@builtinify
 def closelog():
     _closelog()
 
-@__pypy__.builtinify
+@builtinify
 def setlogmask(mask):
     return _setlogmask(mask)
 
-@__pypy__.builtinify
+@builtinify
 def LOG_MASK(pri):
     return (1 << pri)
 
-@__pypy__.builtinify
+@builtinify
 def LOG_UPTO(pri):
     return (1 << (pri + 1)) - 1