##// END OF EJS Templates
add dirty trick for readline import on OSX...
add dirty trick for readline import on OSX also made the libedit warning extremely loud, so people don't miss it. We still get reports of people never having noticed the warning, and getting confused when readline is broken on OSX. The reason for the dirty trick: pip installs to site-packages by default, but site-packages dirs always come *after* lib-dynload (and extras, etc.), which is where the system readline is installed. That means that a non-setuptools install (pip or setup.py install) *cannot* override any package that ships with OSX, including: numpy, readline, twisted, pyobjc without installing to a non-standard path (not even user site-packages via `--user`). The method for the dirty trick: 1. remove lib-dynload from sys.path before trying to import readline the first time 2. after import, restore lib-dynload to its place in sys.path 3. if import failed without lib-dynload, try it one more time

File last commit:

r4757:d82fb264
r5206:387dcd6a
Show More
_simplegeneric.py
109 lines | 3.0 KiB | text/x-python | PythonLexer
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 """This is version 0.7 of Philip J. Eby's simplegeneric module
Thomas Kluyver
Patch bundled simplegeneric for Python 3 compatibility.
r4757 (http://pypi.python.org/pypi/simplegeneric), patched to work with Python 3,
which doesn't support old-style classes.
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 """
vivainio
Add license notes, closes #203
r911 #Name: simplegeneric
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 #Version: 0.7
vivainio
Add license notes, closes #203
r911 #Summary: Simple generic functions (similar to Python's own len(), pickle.dump(), etc.)
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 #Home-page: http://pypi.python.org/pypi/simplegeneric
vivainio
Add license notes, closes #203
r911 #Author: Phillip J. Eby
#Author-email: peak@eby-sarna.com
#License: PSF or ZPL
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415
vivainio
Add license notes, closes #203
r911 __all__ = ["generic"]
Thomas Kluyver
Patch bundled simplegeneric for Python 3 compatibility.
r4757 try:
from types import ClassType, InstanceType
except ImportError:
classtypes = type
else:
classtypes = type, ClassType
vivainio
Add license notes, closes #203
r911
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def generic(func):
"""Create a simple generic function"""
_sentinel = object()
def _by_class(*args, **kw):
cls = args[0].__class__
for t in type(cls.__name__, (cls,object), {}).__mro__:
f = _gbt(t, _sentinel)
if f is not _sentinel:
return f(*args, **kw)
else:
return func(*args, **kw)
Thomas Kluyver
Patch bundled simplegeneric for Python 3 compatibility.
r4757 _by_type = {object: func}
try:
_by_type[InstanceType] = _by_class
except NameError: # Python 3
pass
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 _gbt = _by_type.get
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 def when_type(*types):
"""Decorator to add a method that will be called for the given types"""
for t in types:
if not isinstance(t, classtypes):
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 raise TypeError(
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 "%r is not a type or class" % (t,)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 )
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 def decorate(f):
for t in types:
if _by_type.setdefault(t,f) is not f:
raise TypeError(
"%r already has method for type %r" % (func, t)
)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 return f
return decorate
_by_object = {}
_gbo = _by_object.get
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 def when_object(*obs):
"""Decorator to add a method to be called for the given object(s)"""
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 def decorate(f):
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 for o in obs:
if _by_object.setdefault(id(o), (o,f))[1] is not f:
raise TypeError(
"%r already has method for object %r" % (func, o)
)
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 return f
return decorate
def dispatch(*args, **kw):
f = _gbo(id(args[0]), _sentinel)
if f is _sentinel:
for t in type(args[0]).__mro__:
f = _gbt(t, _sentinel)
if f is not _sentinel:
return f(*args, **kw)
else:
return func(*args, **kw)
else:
return f[1](*args, **kw)
Thomas Kluyver
Update bundled simplegeneric to version 0.7.
r4756 dispatch.__name__ = func.__name__
walter.doerwald
IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now...
r415 dispatch.__dict__ = func.__dict__.copy()
dispatch.__doc__ = func.__doc__
dispatch.__module__ = func.__module__
dispatch.when_type = when_type
dispatch.when_object = when_object
dispatch.default = func
dispatch.has_object = lambda o: id(o) in _by_object
dispatch.has_type = lambda t: t in _by_type
return dispatch
def test_suite():
import doctest
return doctest.DocFileSuite(
'README.txt',
optionflags=doctest.ELLIPSIS|doctest.REPORT_ONLY_FIRST_FAILURE,
)