Show More
@@ -36,7 +36,7 from IPython.lib import pretty | |||
|
36 | 36 | from IPython.utils.traitlets import ( |
|
37 | 37 | Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List, |
|
38 | 38 | ) |
|
39 | from IPython.utils.py3compat import unicode_to_str | |
|
39 | from IPython.utils.py3compat import unicode_to_str, with_metaclass | |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | #----------------------------------------------------------------------------- |
@@ -176,7 +176,7 class DisplayFormatter(Configurable): | |||
|
176 | 176 | #----------------------------------------------------------------------------- |
|
177 | 177 | |
|
178 | 178 | |
|
179 | class FormatterABC(object): | |
|
179 | class FormatterABC(with_metaclass(abc.ABCMeta, object)): | |
|
180 | 180 | """ Abstract base class for Formatters. |
|
181 | 181 | |
|
182 | 182 | A formatter is a callable class that is responsible for computing the |
@@ -184,7 +184,6 class FormatterABC(object): | |||
|
184 | 184 | an HTML formatter would have a format type of `text/html` and would return |
|
185 | 185 | the HTML representation of the object when called. |
|
186 | 186 | """ |
|
187 | __metaclass__ = abc.ABCMeta | |
|
188 | 187 | |
|
189 | 188 | # The format type of the data returned, usually a MIME type. |
|
190 | 189 | format_type = 'text/plain' |
@@ -6,6 +6,7 from io import StringIO | |||
|
6 | 6 | from IPython.core.splitinput import LineInfo |
|
7 | 7 | from IPython.utils import tokenize2 |
|
8 | 8 | from IPython.utils.openpy import cookie_comment_re |
|
9 | from IPython.utils.py3compat import with_metaclass | |
|
9 | 10 | from IPython.utils.tokenize2 import generate_tokens, untokenize, TokenError |
|
10 | 11 | |
|
11 | 12 | #----------------------------------------------------------------------------- |
@@ -33,9 +34,8 ESC_SEQUENCES = [ESC_SHELL, ESC_SH_CAP, ESC_HELP ,\ | |||
|
33 | 34 | ESC_QUOTE, ESC_QUOTE2, ESC_PAREN ] |
|
34 | 35 | |
|
35 | 36 | |
|
36 | class InputTransformer(object): | |
|
37 | class InputTransformer(with_metaclass(abc.ABCMeta, object)): | |
|
37 | 38 | """Abstract base class for line-based input transformers.""" |
|
38 | __metaclass__ = abc.ABCMeta | |
|
39 | 39 | |
|
40 | 40 | @abc.abstractmethod |
|
41 | 41 | def push(self, line): |
@@ -68,7 +68,8 from IPython.utils.ipstruct import Struct | |||
|
68 | 68 | from IPython.utils.path import get_home_dir, get_ipython_dir, get_py_filename, unquote_filename |
|
69 | 69 | from IPython.utils.pickleshare import PickleShareDB |
|
70 | 70 | from IPython.utils.process import system, getoutput |
|
71 | from IPython.utils.py3compat import builtin_mod, unicode_type, string_types | |
|
71 | from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types, | |
|
72 | with_metaclass) | |
|
72 | 73 | from IPython.utils.strdispatch import StrDispatch |
|
73 | 74 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
74 | 75 | from IPython.utils.text import (format_screen, LSString, SList, |
@@ -3157,8 +3158,7 class InteractiveShell(SingletonConfigurable): | |||
|
3157 | 3158 | self.restore_sys_module_state() |
|
3158 | 3159 | |
|
3159 | 3160 | |
|
3160 | class InteractiveShellABC(object): | |
|
3161 | class InteractiveShellABC(with_metaclass(abc.ABCMeta, object)): | |
|
3161 | 3162 | """An abstract base class for InteractiveShell.""" |
|
3162 | __metaclass__ = abc.ABCMeta | |
|
3163 | 3163 | |
|
3164 | 3164 | InteractiveShellABC.register(InteractiveShell) |
@@ -11,19 +11,18 | |||
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | # Standard library imports | |
|
15 | 14 | import abc |
|
16 | 15 | |
|
16 | from IPython.utils.py3compat import with_metaclass | |
|
17 | ||
|
17 | 18 | #----------------------------------------------------------------------------- |
|
18 | 19 | # Channels |
|
19 | 20 | #----------------------------------------------------------------------------- |
|
20 | 21 | |
|
21 | 22 | |
|
22 | class ChannelABC(object): | |
|
23 | class ChannelABC(with_metaclass(abc.ABCMeta, object)): | |
|
23 | 24 | """A base class for all channel ABCs.""" |
|
24 | 25 | |
|
25 | __metaclass__ = abc.ABCMeta | |
|
26 | ||
|
27 | 26 | @abc.abstractmethod |
|
28 | 27 | def start(self): |
|
29 | 28 | pass |
@@ -11,14 +11,15 | |||
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | # Standard library imports | |
|
15 | 14 | import abc |
|
16 | 15 | |
|
16 | from IPython.utils.py3compat import with_metaclass | |
|
17 | ||
|
17 | 18 | #----------------------------------------------------------------------------- |
|
18 | 19 | # Main kernel client class |
|
19 | 20 | #----------------------------------------------------------------------------- |
|
20 | 21 | |
|
21 | class KernelClientABC(object): | |
|
22 | class KernelClientABC(with_metaclass(abc.ABCMeta, object)): | |
|
22 | 23 | """KernelManager ABC. |
|
23 | 24 | |
|
24 | 25 | The docstrings for this class can be found in the base implementation: |
@@ -26,8 +27,6 class KernelClientABC(object): | |||
|
26 | 27 | `IPython.kernel.client.KernelClient` |
|
27 | 28 | """ |
|
28 | 29 | |
|
29 | __metaclass__ = abc.ABCMeta | |
|
30 | ||
|
31 | 30 | @abc.abstractproperty |
|
32 | 31 | def kernel(self): |
|
33 | 32 | pass |
@@ -23,14 +23,13 import zmq | |||
|
23 | 23 | |
|
24 | 24 | # Local imports. |
|
25 | 25 | from IPython.utils.traitlets import HasTraits, Instance, Int |
|
26 | from IPython.utils.py3compat import with_metaclass | |
|
26 | 27 | |
|
27 | 28 | #----------------------------------------------------------------------------- |
|
28 | 29 | # Generic socket interface |
|
29 | 30 | #----------------------------------------------------------------------------- |
|
30 | 31 | |
|
31 | class SocketABC(object): | |
|
32 | __metaclass__ = abc.ABCMeta | |
|
33 | ||
|
32 | class SocketABC(with_metaclass(abc.ABCMeta, object)): | |
|
34 | 33 | @abc.abstractmethod |
|
35 | 34 | def recv_multipart(self, flags=0, copy=True, track=False): |
|
36 | 35 | raise NotImplementedError |
@@ -11,19 +11,18 | |||
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | # Standard library imports. | |
|
15 | 14 | import abc |
|
16 | 15 | |
|
16 | from IPython.utils.py3compat import with_metaclass | |
|
17 | ||
|
17 | 18 | #----------------------------------------------------------------------------- |
|
18 | 19 | # Channels |
|
19 | 20 | #----------------------------------------------------------------------------- |
|
20 | 21 | |
|
21 | 22 | |
|
22 | class ChannelABC(object): | |
|
23 | class ChannelABC(with_metaclass(abc.ABCMeta, object)): | |
|
23 | 24 | """A base class for all channel ABCs.""" |
|
24 | 25 | |
|
25 | __metaclass__ = abc.ABCMeta | |
|
26 | ||
|
27 | 26 | @abc.abstractmethod |
|
28 | 27 | def start(self): |
|
29 | 28 | pass |
@@ -130,7 +129,7 class HBChannelABC(ChannelABC): | |||
|
130 | 129 | # Main kernel manager class |
|
131 | 130 | #----------------------------------------------------------------------------- |
|
132 | 131 | |
|
133 | class KernelManagerABC(object): | |
|
132 | class KernelManagerABC(with_metaclass(abc.ABCMeta, object)): | |
|
134 | 133 | """KernelManager ABC. |
|
135 | 134 | |
|
136 | 135 | The docstrings for this class can be found in the base implementation: |
@@ -138,8 +137,6 class KernelManagerABC(object): | |||
|
138 | 137 | `IPython.kernel.kernelmanager.KernelManager` |
|
139 | 138 | """ |
|
140 | 139 | |
|
141 | __metaclass__ = abc.ABCMeta | |
|
142 | ||
|
143 | 140 | @abc.abstractproperty |
|
144 | 141 | def kernel(self): |
|
145 | 142 | pass |
@@ -21,6 +21,7 from IPython.config.configurable import LoggingConfigurable | |||
|
21 | 21 | from IPython.core.inputsplitter import ESC_SEQUENCES |
|
22 | 22 | from IPython.qt.rich_text import HtmlExporter |
|
23 | 23 | from IPython.qt.util import MetaQObjectHasTraits, get_font |
|
24 | from IPython.utils.py3compat import with_metaclass | |
|
24 | 25 | from IPython.utils.text import columnize |
|
25 | 26 | from IPython.utils.traitlets import Bool, Enum, Integer, Unicode |
|
26 | 27 | from .ansi_code_processor import QtAnsiCodeProcessor |
@@ -69,7 +70,7 def is_letter_or_number(char): | |||
|
69 | 70 | # Classes |
|
70 | 71 | #----------------------------------------------------------------------------- |
|
71 | 72 | |
|
72 | class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): | |
|
73 | class ConsoleWidget(with_metaclass(MetaQObjectHasTraits, type('NewBase', (LoggingConfigurable, QtGui.QWidget), {}))): | |
|
73 | 74 | """ An abstract base class for console-type widgets. This class has |
|
74 | 75 | functionality for: |
|
75 | 76 | |
@@ -82,7 +83,6 class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): | |||
|
82 | 83 | ConsoleWidget also provides a number of utility methods that will be |
|
83 | 84 | convenient to implementors of a console-style widget. |
|
84 | 85 | """ |
|
85 | __metaclass__ = MetaQObjectHasTraits | |
|
86 | 86 | |
|
87 | 87 | #------ Configuration ------------------------------------------------------ |
|
88 | 88 |
@@ -168,27 +168,22 class QtHBChannelMixin(ChannelQObject): | |||
|
168 | 168 | self.kernel_died.emit(since_last_heartbeat) |
|
169 | 169 | |
|
170 | 170 | |
|
171 | class QtKernelRestarterMixin(HasTraits, SuperQObject): | |
|
171 | class QtKernelRestarterMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})): | |
|
172 | 172 | |
|
173 | __metaclass__ = MetaQObjectHasTraits | |
|
174 | 173 | _timer = None |
|
175 | 174 | |
|
176 | 175 | |
|
177 | class QtKernelManagerMixin(HasTraits, SuperQObject): | |
|
176 | class QtKernelManagerMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})): | |
|
178 | 177 | """ A KernelClient that provides signals and slots. |
|
179 | 178 | """ |
|
180 | 179 | |
|
181 | __metaclass__ = MetaQObjectHasTraits | |
|
182 | ||
|
183 | 180 | kernel_restarted = QtCore.Signal() |
|
184 | 181 | |
|
185 | 182 | |
|
186 | class QtKernelClientMixin(HasTraits, SuperQObject): | |
|
183 | class QtKernelClientMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})): | |
|
187 | 184 | """ A KernelClient that provides signals and slots. |
|
188 | 185 | """ |
|
189 | 186 | |
|
190 | __metaclass__ = MetaQObjectHasTraits | |
|
191 | ||
|
192 | 187 | # Emitted when the kernel client has started listening. |
|
193 | 188 | started_channels = QtCore.Signal() |
|
194 | 189 |
@@ -208,3 +208,28 else: | |||
|
208 | 208 | else: |
|
209 | 209 | filename = fname |
|
210 | 210 | builtin_mod.execfile(filename, *where) |
|
211 | ||
|
212 | # Parts below taken from six: | |
|
213 | # Copyright (c) 2010-2013 Benjamin Peterson | |
|
214 | # | |
|
215 | # Permission is hereby granted, free of charge, to any person obtaining a copy | |
|
216 | # of this software and associated documentation files (the "Software"), to deal | |
|
217 | # in the Software without restriction, including without limitation the rights | |
|
218 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
|
219 | # copies of the Software, and to permit persons to whom the Software is | |
|
220 | # furnished to do so, subject to the following conditions: | |
|
221 | # | |
|
222 | # The above copyright notice and this permission notice shall be included in all | |
|
223 | # copies or substantial portions of the Software. | |
|
224 | # | |
|
225 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
|
226 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
|
227 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
|
228 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
|
229 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
|
230 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
|
231 | # SOFTWARE. | |
|
232 | ||
|
233 | def with_metaclass(meta, *bases): | |
|
234 | """Create a base class with a metaclass.""" | |
|
235 | return meta("NewBase", bases, {}) |
@@ -394,9 +394,7 class MetaHasTraits(type): | |||
|
394 | 394 | v.this_class = cls |
|
395 | 395 | super(MetaHasTraits, cls).__init__(name, bases, classdict) |
|
396 | 396 | |
|
397 | class HasTraits(object): | |
|
398 | ||
|
399 | __metaclass__ = MetaHasTraits | |
|
397 | class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)): | |
|
400 | 398 | |
|
401 | 399 | def __new__(cls, *args, **kw): |
|
402 | 400 | # This is needed because in Python 2.6 object.__new__ only accepts |
General Comments 0
You need to be logged in to leave comments.
Login now