Show More
@@ -13,3 +13,8 b' except AttributeError:' | |||||
13 | if version_info < (2,1,0): |
|
13 | if version_info < (2,1,0): | |
14 | raise ImportError(msg + ", but you have %s" % tornado.version) |
|
14 | raise ImportError(msg + ", but you have %s" % tornado.version) | |
15 | del msg |
|
15 | del msg | |
|
16 | ||||
|
17 | # check for pyzmq 2.1.4 | |||
|
18 | from IPython.zmq import check_for_zmq | |||
|
19 | check_for_zmq('2.1.4', 'IPython.frontend.html.notebook') | |||
|
20 | del check_for_zmq |
@@ -35,13 +35,7 b' import zmq' | |||||
35 | # Install the pyzmq ioloop. This has to be done before anything else from |
|
35 | # Install the pyzmq ioloop. This has to be done before anything else from | |
36 | # tornado is imported. |
|
36 | # tornado is imported. | |
37 | from zmq.eventloop import ioloop |
|
37 | from zmq.eventloop import ioloop | |
38 | # FIXME: ioloop.install is new in pyzmq-2.1.7, so remove this conditional |
|
38 | ioloop.install() | |
39 | # when pyzmq dependency is updated beyond that. |
|
|||
40 | if hasattr(ioloop, 'install'): |
|
|||
41 | ioloop.install() |
|
|||
42 | else: |
|
|||
43 | import tornado.ioloop |
|
|||
44 | tornado.ioloop.IOLoop = ioloop.IOLoop |
|
|||
45 |
|
39 | |||
46 | from tornado import httpserver |
|
40 | from tornado import httpserver | |
47 | from tornado import web |
|
41 | from tornado import web |
@@ -12,6 +12,40 b'' | |||||
12 | import warnings |
|
12 | import warnings | |
13 | from distutils.version import LooseVersion as V |
|
13 | from distutils.version import LooseVersion as V | |
14 |
|
14 | |||
|
15 | ||||
|
16 | def patch_pyzmq(): | |||
|
17 | """backport a few patches from newer pyzmq | |||
|
18 | ||||
|
19 | These can be removed as we bump our minimum pyzmq version | |||
|
20 | """ | |||
|
21 | ||||
|
22 | import zmq | |||
|
23 | ||||
|
24 | # ioloop.install, introduced in pyzmq 2.1.7 | |||
|
25 | from zmq.eventloop import ioloop | |||
|
26 | ||||
|
27 | def install(): | |||
|
28 | import tornado.ioloop | |||
|
29 | tornado.ioloop.IOLoop = ioloop.IOLoop | |||
|
30 | ||||
|
31 | if not hasattr(ioloop, 'install'): | |||
|
32 | ioloop.install = install | |||
|
33 | ||||
|
34 | # fix missing DEALER/ROUTER aliases in pyzmq < 2.1.9 | |||
|
35 | if not hasattr(zmq, 'DEALER'): | |||
|
36 | zmq.DEALER = zmq.XREQ | |||
|
37 | if not hasattr(zmq, 'ROUTER'): | |||
|
38 | zmq.ROUTER = zmq.XREP | |||
|
39 | ||||
|
40 | # fallback on stdlib json if jsonlib is selected, because jsonlib breaks things. | |||
|
41 | # jsonlib support is removed from pyzmq >= 2.2.0 | |||
|
42 | ||||
|
43 | from zmq.utils import jsonapi | |||
|
44 | if jsonapi.jsonmod.__name__ == 'jsonlib': | |||
|
45 | import json | |||
|
46 | jsonapi.jsonmod = json | |||
|
47 | ||||
|
48 | ||||
15 | def check_for_zmq(minimum_version, module='IPython.zmq'): |
|
49 | def check_for_zmq(minimum_version, module='IPython.zmq'): | |
16 | try: |
|
50 | try: | |
17 | import zmq |
|
51 | import zmq | |
@@ -24,12 +58,6 b" def check_for_zmq(minimum_version, module='IPython.zmq'):" | |||||
24 | raise ImportError("%s requires pyzmq >= %s, but you have %s"%( |
|
58 | raise ImportError("%s requires pyzmq >= %s, but you have %s"%( | |
25 | module, minimum_version, pyzmq_version)) |
|
59 | module, minimum_version, pyzmq_version)) | |
26 |
|
60 | |||
27 | # fix missing DEALER/ROUTER aliases in pyzmq < 2.1.9 |
|
|||
28 | if not hasattr(zmq, 'DEALER'): |
|
|||
29 | zmq.DEALER = zmq.XREQ |
|
|||
30 | if not hasattr(zmq, 'ROUTER'): |
|
|||
31 | zmq.ROUTER = zmq.XREP |
|
|||
32 |
|
||||
33 | if V(zmq.zmq_version()) >= V('4.0.0'): |
|
61 | if V(zmq.zmq_version()) >= V('4.0.0'): | |
34 | warnings.warn("""libzmq 4 detected. |
|
62 | warnings.warn("""libzmq 4 detected. | |
35 | It is unlikely that IPython's zmq code will work properly. |
|
63 | It is unlikely that IPython's zmq code will work properly. | |
@@ -37,3 +65,4 b" def check_for_zmq(minimum_version, module='IPython.zmq'):" | |||||
37 | RuntimeWarning) |
|
65 | RuntimeWarning) | |
38 |
|
66 | |||
39 | check_for_zmq('2.1.4') |
|
67 | check_for_zmq('2.1.4') | |
|
68 | patch_pyzmq() |
@@ -74,21 +74,9 b' def squash_unicode(obj):' | |||||
74 | #----------------------------------------------------------------------------- |
|
74 | #----------------------------------------------------------------------------- | |
75 |
|
75 | |||
76 |
|
76 | |||
77 | # jsonlib behaves a bit differently, so handle that where it affects us |
|
77 | # ISO8601-ify datetime objects | |
78 | if jsonapi.jsonmod.__name__ == 'jsonlib': |
|
78 | json_packer = lambda obj: jsonapi.dumps(obj, default=date_default) | |
79 | # kwarg for serializing unknown types (datetime) is different |
|
79 | json_unpacker = lambda s: extract_dates(jsonapi.loads(s)) | |
80 | dumps_kwargs = dict(on_unknown=date_default) |
|
|||
81 | # By default, jsonlib unpacks floats as Decimal instead of float, |
|
|||
82 | # which can foul things up |
|
|||
83 | loads_kwargs = dict(use_float=True) |
|
|||
84 | else: |
|
|||
85 | # ISO8601-ify datetime objects |
|
|||
86 | dumps_kwargs = dict(default=date_default) |
|
|||
87 | # nothing to specify for loads |
|
|||
88 | loads_kwargs = dict() |
|
|||
89 |
|
||||
90 | json_packer = lambda obj: jsonapi.dumps(obj, **dumps_kwargs) |
|
|||
91 | json_unpacker = lambda s: extract_dates(jsonapi.loads(s, **loads_kwargs)) |
|
|||
92 |
|
80 | |||
93 | pickle_packer = lambda o: pickle.dumps(o,-1) |
|
81 | pickle_packer = lambda o: pickle.dumps(o,-1) | |
94 | pickle_unpacker = pickle.loads |
|
82 | pickle_unpacker = pickle.loads |
General Comments 0
You need to be logged in to leave comments.
Login now