[pypy-svn] r79737 - pypy/trunk/lib_pypy

arigo at codespeak.net arigo at codespeak.net
Thu Dec 2 11:14:55 CET 2010


Author: arigo
Date: Thu Dec  2 11:14:53 2010
New Revision: 79737

Modified:
   pypy/trunk/lib_pypy/_hashlib.py
   pypy/trunk/lib_pypy/_locale.py
   pypy/trunk/lib_pypy/_marshal.py
   pypy/trunk/lib_pypy/_minimal_curses.py
   pypy/trunk/lib_pypy/cPickle.py
   pypy/trunk/lib_pypy/cmath.py
   pypy/trunk/lib_pypy/grp.py
   pypy/trunk/lib_pypy/itertools.py
   pypy/trunk/lib_pypy/msvcrt.py
   pypy/trunk/lib_pypy/pwd.py
   pypy/trunk/lib_pypy/pyexpat.py
   pypy/trunk/lib_pypy/resource.py
   pypy/trunk/lib_pypy/syslog.py
Log:
Found the proper way: try except ImportError.  Sorry if e.g. you had
troubles with older pypy-c's.


Modified: pypy/trunk/lib_pypy/_hashlib.py
==============================================================================
--- pypy/trunk/lib_pypy/_hashlib.py	(original)
+++ pypy/trunk/lib_pypy/_hashlib.py	Thu Dec  2 11:14:53 2010
@@ -148,29 +148,29 @@
     return hash(ctx, name)
 
 # shortcut functions
-import __pypy__
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
 
- at __pypy__.builtinify
+ at builtinify
 def openssl_md5(string=''):
     return new('md5', string)
 
- at __pypy__.builtinify
+ at builtinify
 def openssl_sha1(string=''):
     return new('sha1', string)
 
- at __pypy__.builtinify
+ at builtinify
 def openssl_sha224(string=''):
     return new('sha224', string)
 
- at __pypy__.builtinify
+ at builtinify
 def openssl_sha256(string=''):
     return new('sha256', string)
 
- at __pypy__.builtinify
+ at builtinify
 def openssl_sha384(string=''):
     return new('sha384', string)
 
- at __pypy__.builtinify
+ at builtinify
 def openssl_sha512(string=''):
     return new('sha512', string)
-

Modified: pypy/trunk/lib_pypy/_locale.py
==============================================================================
--- pypy/trunk/lib_pypy/_locale.py	(original)
+++ pypy/trunk/lib_pypy/_locale.py	Thu Dec  2 11:14:53 2010
@@ -11,7 +11,8 @@
 # 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
@@ -160,7 +161,7 @@
     ul = ''.join(ul)
     string.letters = ul
 
- at __pypy__.builtinify
+ at builtinify
 def setlocale(category, locale=None):
     "(integer,string=None) -> string. Activates/queries locale processing."
     if locale:
@@ -185,7 +186,7 @@
         groups.append(0)
     return groups
 
- at __pypy__.builtinify
+ at builtinify
 def localeconv():
     "() -> dict. Returns numeric and monetary locale-specific parameters."
 
@@ -219,7 +220,7 @@
     }
     return result
 
- at __pypy__.builtinify
+ at builtinify
 def strcoll(s1, s2):
     "string,string -> int. Compares two strings according to the locale."
 
@@ -238,7 +239,7 @@
     # Collate the strings.
     return _wcscoll(s1, s2)
 
- at __pypy__.builtinify
+ at builtinify
 def strxfrm(s):
     "string -> string. Returns a string that behaves for cmp locale-aware."
 
@@ -252,7 +253,7 @@
         _strxfrm(buf, s, n2)
     return buf.value
 
- at __pypy__.builtinify
+ at builtinify
 def getdefaultlocale():
     # TODO: Port code from CPython for Windows and Mac OS
     raise NotImplementedError()
@@ -274,31 +275,31 @@
         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."""
@@ -309,7 +310,7 @@
         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."""

Modified: pypy/trunk/lib_pypy/_marshal.py
==============================================================================
--- pypy/trunk/lib_pypy/_marshal.py	(original)
+++ pypy/trunk/lib_pypy/_marshal.py	Thu Dec  2 11:14:53 2010
@@ -6,6 +6,10 @@
 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'
@@ -645,15 +649,18 @@
 
 version = 1
 
+ at 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)
 
+ at builtinify
 def load(f):
     um = _Unmarshaller(f.read)
     return um.load()
 
+ at builtinify
 def dumps(x, version=version):
     # XXX 'version' is ignored, we always dump in a version-0-compatible format
     buffer = []
@@ -661,6 +668,7 @@
     m.dump(x)
     return ''.join(buffer)
 
+ at builtinify
 def loads(s):
     um = _FastUnmarshaller(s)
     return um.load()

Modified: pypy/trunk/lib_pypy/_minimal_curses.py
==============================================================================
--- pypy/trunk/lib_pypy/_minimal_curses.py	(original)
+++ pypy/trunk/lib_pypy/_minimal_curses.py	Thu Dec  2 11:14:53 2010
@@ -35,23 +35,24 @@
 
 # ____________________________________________________________
 
-import __pypy__
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
 
- at __pypy__.builtinify
+ at 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)
 
- at __pypy__.builtinify
+ at 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
 
- at __pypy__.builtinify
+ at 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:

Modified: pypy/trunk/lib_pypy/cPickle.py
==============================================================================
--- pypy/trunk/lib_pypy/cPickle.py	(original)
+++ pypy/trunk/lib_pypy/cPickle.py	Thu Dec  2 11:14:53 2010
@@ -4,7 +4,10 @@
 
 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
@@ -32,11 +35,11 @@
     def getvalue(self):
         return self.__f and self.__f.getvalue()
 
- at __pypy__.builtinify
+ at builtinify
 def dump(obj, file, protocol=None):
     Pickler(file, protocol).dump(obj)
 
- at __pypy__.builtinify
+ at builtinify
 def dumps(obj, protocol=None):
     file = StringIO()
     Pickler(file, protocol).dump(obj)

Modified: pypy/trunk/lib_pypy/cmath.py
==============================================================================
--- pypy/trunk/lib_pypy/cmath.py	(original)
+++ pypy/trunk/lib_pypy/cmath.py	Thu Dec  2 11:14:53 2010
@@ -5,9 +5,12 @@
 
 # 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.)
@@ -24,7 +27,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def acos(x):
     """acos(x)
 
@@ -33,7 +36,7 @@
     return -(_prodi(log((x+(_i*sqrt((_one-(x*x))))))))
 
 
- at __pypy__.builtinify
+ at builtinify
 def acosh(x):
     """acosh(x)
 
@@ -43,7 +46,7 @@
     return z+z
 
 
- at __pypy__.builtinify
+ at builtinify
 def asin(x):
     """asin(x)
 
@@ -55,7 +58,7 @@
     return -(_prodi(log((sqrt_1_minus_x_sq+_prodi(x)))))
 
 
- at __pypy__.builtinify
+ at builtinify
 def asinh(x):
     """asinh(x)
 
@@ -65,7 +68,7 @@
     return z+z
 
 
- at __pypy__.builtinify
+ at builtinify
 def atan(x):
     """atan(x)
     
@@ -74,7 +77,7 @@
     return _halfi*log(((_i+x)/(_i-x)))
 
 
- at __pypy__.builtinify
+ at builtinify
 def atanh(x):
     """atanh(x)
 
@@ -83,7 +86,7 @@
     return _half*log((_one+x)/(_one-x))
 
 
- at __pypy__.builtinify
+ at builtinify
 def cos(x):
     """cos(x)
 
@@ -95,7 +98,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def cosh(x):
     """cosh(x)
     
@@ -107,7 +110,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def exp(x):
     """exp(x)
     
@@ -120,7 +123,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def log(x, base=None):
     """log(x)
 
@@ -135,7 +138,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def log10(x):
     """log10(x)
 
@@ -148,7 +151,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def sin(x):
     """sin(x)
 
@@ -160,7 +163,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def sinh(x):
     """sinh(x)
 
@@ -172,7 +175,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def sqrt(x):
     """sqrt(x)
 
@@ -198,7 +201,7 @@
 _sqrt_half = sqrt(_half)
 
 
- at __pypy__.builtinify
+ at builtinify
 def tan(x):
     """tan(x)
 
@@ -219,7 +222,7 @@
     return complex(real, imag)
 
 
- at __pypy__.builtinify
+ at builtinify
 def tanh(x):
     """tanh(x)
 

Modified: pypy/trunk/lib_pypy/grp.py
==============================================================================
--- pypy/trunk/lib_pypy/grp.py	(original)
+++ pypy/trunk/lib_pypy/grp.py	Thu Dec  2 11:14:53 2010
@@ -2,13 +2,17 @@
 """ 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):
@@ -64,7 +68,7 @@
     return Group(res.contents.gr_name, res.contents.gr_passwd,
                  res.contents.gr_gid, mem)
 
- at __pypy__.builtinify
+ at builtinify
 def getgrgid(gid):
     res = libc.getgrgid(gid)
     if not res:
@@ -72,7 +76,7 @@
         raise KeyError(gid)
     return _group_from_gstruct(res)
 
- at __pypy__.builtinify
+ at builtinify
 def getgrnam(name):
     if not isinstance(name, str):
         raise TypeError("expected string")
@@ -81,7 +85,7 @@
         raise KeyError(name)
     return _group_from_gstruct(res)
 
- at __pypy__.builtinify
+ at builtinify
 def getgrall():
     libc.setgrent()
     lst = []

Modified: pypy/trunk/lib_pypy/itertools.py
==============================================================================
--- pypy/trunk/lib_pypy/itertools.py	(original)
+++ pypy/trunk/lib_pypy/itertools.py	Thu Dec  2 11:14:53 2010
@@ -27,7 +27,8 @@
            'ifilterfalse', 'imap', 'islice', 'izip', 'repeat', 'starmap',
            'takewhile', 'tee']
 
-import __pypy__
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
 
 
 class chain(object):
@@ -568,7 +569,7 @@
         return self
 
 
- at __pypy__.builtinify
+ at builtinify
 def tee(iterable, n=2):
     """Return n independent iterators from a single iterable.
     Note : once tee() has made a split, the original iterable

Modified: pypy/trunk/lib_pypy/msvcrt.py
==============================================================================
--- pypy/trunk/lib_pypy/msvcrt.py	(original)
+++ pypy/trunk/lib_pypy/msvcrt.py	Thu Dec  2 11:14:53 2010
@@ -11,13 +11,16 @@
 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
 
@@ -35,7 +38,7 @@
 _locking.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
 _locking.restype = ctypes.c_int
 
- at __pypy__.builtinify
+ at builtinify
 def locking(fd, mode, nbytes):
     '''lock or unlock a number of bytes in a file.'''
     rv = _locking(fd, mode, nbytes)

Modified: pypy/trunk/lib_pypy/pwd.py
==============================================================================
--- pypy/trunk/lib_pypy/pwd.py	(original)
+++ pypy/trunk/lib_pypy/pwd.py	Thu Dec  2 11:14:53 2010
@@ -10,13 +10,17 @@
 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
 
@@ -79,12 +83,12 @@
 _endpwent.argtypes = None
 _endpwent.restype = None
 
- at __pypy__.builtinify
+ at builtinify
 def mkpwent(pw):
     pw = pw.contents
     return struct_passwd(pw)
 
- at __pypy__.builtinify
+ at builtinify
 def getpwuid(uid):
     """
     getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,
@@ -97,7 +101,7 @@
         raise KeyError("getpwuid(): uid not found: %s" % uid)
     return mkpwent(pw)
 
- at __pypy__.builtinify
+ at builtinify
 def getpwnam(name):
     """
     getpwnam(name) -> (pw_name,pw_passwd,pw_uid,
@@ -112,7 +116,7 @@
         raise KeyError("getpwname(): name not found: %s" % name)
     return mkpwent(pw)
 
- at __pypy__.builtinify
+ at builtinify
 def getpwall():
     """
     getpwall() -> list_of_entries

Modified: pypy/trunk/lib_pypy/pyexpat.py
==============================================================================
--- pypy/trunk/lib_pypy/pyexpat.py	(original)
+++ pypy/trunk/lib_pypy/pyexpat.py	Thu Dec  2 11:14:53 2010
@@ -2,11 +2,14 @@
 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'))
 
@@ -425,11 +428,11 @@
         new_parser._set_unknown_encoding_handler()
         return new_parser
 
- at __pypy__.builtinify
+ at builtinify
 def ErrorString(errno):
     return XML_ErrorString(errno)[:200]
 
- at __pypy__.builtinify
+ at builtinify
 def ParserCreate(encoding=None, namespace_separator=None, intern=None):
     if (not isinstance(encoding, str) and
         not encoding is None):

Modified: pypy/trunk/lib_pypy/resource.py
==============================================================================
--- pypy/trunk/lib_pypy/resource.py	(original)
+++ pypy/trunk/lib_pypy/resource.py	Thu Dec  2 11:14:53 2010
@@ -1,4 +1,4 @@
-import sys, __pypy__
+import sys
 if sys.platform == 'win32':
     raise ImportError('resource module not available for win32')
 
@@ -11,6 +11,10 @@
 from errno import EINVAL, EPERM
 import _structseq
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+
 class error(Exception):
     pass
 
@@ -77,7 +81,7 @@
     ru_nvcsw = _structseq.structseqfield(14)
     ru_nivcsw = _structseq.structseqfield(15)
 
- at __pypy__.builtinify
+ at 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)
@@ -90,7 +94,7 @@
         ("rlim_max", rlim_t),
     )
 
- at __pypy__.builtinify
+ at builtinify
 def getrusage(who):
     ru = _struct_rusage()
     ret = _getrusage(who, byref(ru))
@@ -118,7 +122,7 @@
         ru.ru_nivcsw,
         ))
 
- at __pypy__.builtinify
+ at builtinify
 def getrlimit(resource):
     if not(0 <= resource < RLIM_NLIMITS):
         return ValueError("invalid resource specified")
@@ -130,7 +134,7 @@
         raise error(errno)
     return (rlim.rlim_cur, rlim.rlim_max)
 
- at __pypy__.builtinify
+ at builtinify
 def setrlimit(resource, rlim):
     if not(0 <= resource < RLIM_NLIMITS):
         return ValueError("invalid resource specified")
@@ -147,7 +151,7 @@
         else:
             raise error(errno)
 
- at __pypy__.builtinify
+ at builtinify
 def getpagesize():
     pagesize = 0
     if _getpagesize:

Modified: pypy/trunk/lib_pypy/syslog.py
==============================================================================
--- pypy/trunk/lib_pypy/syslog.py	(original)
+++ pypy/trunk/lib_pypy/syslog.py	Thu Dec  2 11:14:53 2010
@@ -5,7 +5,7 @@
 syslog facility.
 """
 
-import sys, __pypy__
+import sys
 if sys.platform == 'win32':
     raise ImportError("No syslog on Windows")
 
@@ -15,6 +15,10 @@
 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)
@@ -34,11 +38,11 @@
 _setlogmask.argtypes = (c_int,)
 _setlogmask.restype = c_int
 
- at __pypy__.builtinify
+ at builtinify
 def openlog(ident, option, facility):
     _openlog(ident, option, facility)
 
- at __pypy__.builtinify
+ at builtinify
 def syslog(arg1, arg2=None):
     if arg2 is not None:
         priority, message = arg1, arg2
@@ -46,19 +50,19 @@
         priority, message = LOG_INFO, arg1
     _syslog(priority, "%s", message)
 
- at __pypy__.builtinify
+ at builtinify
 def closelog():
     _closelog()
 
- at __pypy__.builtinify
+ at builtinify
 def setlogmask(mask):
     return _setlogmask(mask)
 
- at __pypy__.builtinify
+ at builtinify
 def LOG_MASK(pri):
     return (1 << pri)
 
- at __pypy__.builtinify
+ at builtinify
 def LOG_UPTO(pri):
     return (1 << (pri + 1)) - 1
 



More information about the Pypy-commit mailing list