Show More
@@ -16,6 +16,7 b' __docformat__ = "restructuredtext en"' | |||||
16 | #------------------------------------------------------------------------------- |
|
16 | #------------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | import copy |
|
18 | import copy | |
|
19 | import logging | |||
19 | import sys |
|
20 | import sys | |
20 | from types import FunctionType |
|
21 | from types import FunctionType | |
21 |
|
22 | |||
@@ -33,6 +34,8 b' import codeutil' | |||||
33 | import py3compat |
|
34 | import py3compat | |
34 | from importstring import import_item |
|
35 | from importstring import import_item | |
35 |
|
36 | |||
|
37 | from IPython.config import Application | |||
|
38 | ||||
36 | if py3compat.PY3: |
|
39 | if py3compat.PY3: | |
37 | buffer = memoryview |
|
40 | buffer = memoryview | |
38 |
|
41 | |||
@@ -142,6 +145,14 b' def CannedBuffer(CannedBytes):' | |||||
142 | # Functions |
|
145 | # Functions | |
143 | #------------------------------------------------------------------------------- |
|
146 | #------------------------------------------------------------------------------- | |
144 |
|
147 | |||
|
148 | def _error(*args, **kwargs): | |||
|
149 | if Application.initialized(): | |||
|
150 | logger = Application.instance().log | |||
|
151 | else: | |||
|
152 | logger = logging.getLogger() | |||
|
153 | if not logger.handlers: | |||
|
154 | logging.basicConfig() | |||
|
155 | logger.error(*args, **kwargs) | |||
145 |
|
156 | |||
146 | def can(obj): |
|
157 | def can(obj): | |
147 | """prepare an object for pickling""" |
|
158 | """prepare an object for pickling""" | |
@@ -150,8 +161,8 b' def can(obj):' | |||||
150 | try: |
|
161 | try: | |
151 | cls = import_item(cls) |
|
162 | cls = import_item(cls) | |
152 | except Exception: |
|
163 | except Exception: | |
153 | # not importable |
|
164 | _error("cannning class not importable: %r", cls, exc_info=True) | |
154 | print "not importable: %r" % cls |
|
165 | cls = None | |
155 | continue |
|
166 | continue | |
156 | if isinstance(obj, cls): |
|
167 | if isinstance(obj, cls): | |
157 | return canner(obj) |
|
168 | return canner(obj) | |
@@ -182,8 +193,8 b' def uncan(obj, g=None):' | |||||
182 | try: |
|
193 | try: | |
183 | cls = import_item(cls) |
|
194 | cls = import_item(cls) | |
184 | except Exception: |
|
195 | except Exception: | |
185 | # not importable |
|
196 | _error("uncanning class not importable: %r", cls, exc_info=True) | |
186 | print "not importable: %r" % cls |
|
197 | cls = None | |
187 | continue |
|
198 | continue | |
188 | if isinstance(obj, cls): |
|
199 | if isinstance(obj, cls): | |
189 | return uncanner(obj, g) |
|
200 | return uncanner(obj, g) |
General Comments 0
You need to be logged in to leave comments.
Login now