|
1 | 1 | from __future__ import print_function
|
2 | 2 |
|
3 |
| -import sys |
4 | 3 | from . import imports
|
5 | 4 | from .fields import RecordFactory
|
6 | 5 | from ctypes import *
|
7 | 6 |
|
8 | 7 |
|
9 |
| -# Black magic lifted from six.py (http://pypi.python.org/pypi/six/) to replace |
10 |
| -# use of __metaclass__ for metaclass definition |
11 |
| -def with_metaclass(meta, *bases): |
12 |
| - class metaclass(meta): |
13 |
| - def __new__(cls, name, this_bases, d): |
14 |
| - return meta(name, bases, d) |
15 |
| - return type.__new__(metaclass, 'temporary_class', (), {}) |
16 |
| - |
17 |
| - |
18 |
| -class InitClass(type): |
19 |
| - def __new__(cls, name, bases, dict): |
20 |
| - if '__init_class__' in dict: |
21 |
| - dict['__init_class__'] = classmethod(dict['__init_class__']) |
22 |
| - return type.__new__(cls, name, bases, dict) |
23 |
| - |
24 |
| - def __init__(cls, name, bases, dict): |
25 |
| - type.__init__(cls, name, bases, dict) |
26 |
| - # Binds self.__super.method to the appropriate superclass method |
27 |
| - setattr(cls, '_%s__super' % name.lstrip('_'), super(cls)) |
28 |
| - # Binds cls.__super_cls().method to the appropriate superclass |
29 |
| - # class method. Unfortunately the .__super form doesn't work |
30 |
| - # with class methods, only instance methods. |
31 |
| - setattr( |
32 |
| - cls, '_%s__super_cls' % name, |
33 |
| - classmethod(lambda child: super(cls, child))) |
34 |
| - # Finally call the class initialisatio nmethod. |
35 |
| - cls.__init_class__() |
36 |
| - |
37 |
| -class DeviceCommon(with_metaclass(InitClass)): |
38 |
| - '''Adds support for an __init_class__ method called when the class or any |
39 |
| - of its subclasses is constructed. Also adds auto-super functionality |
40 |
| - (see iocbuilder.support.autosuper).''' |
41 |
| - |
42 |
| - def __init_class__(cls): pass |
43 |
| - |
| 8 | +class DeviceCommon: |
44 | 9 | # By requiring that DeviceCommon be a common base class for the entire
|
45 | 10 | # Python device hierarchy, we can use this __init__ to test for unused
|
46 | 11 | # keyword arguments.
|
@@ -83,20 +48,16 @@ class DeviceSupportCore(DeviceCommon):
|
83 | 48 | # treatment) are then bound to the appropriate class instance and the
|
84 | 49 | # appropriate method is invoked.
|
85 | 50 |
|
86 |
| - def __init_class__(cls): |
| 51 | + def __init_subclass__(cls): |
87 | 52 | '''Record support initialisation, called once during class
|
88 | 53 | initialisation for each sub-class. This registers record support for
|
89 | 54 | the specified device name.'''
|
| 55 | + |
90 | 56 | if not hasattr(cls, '_record_type_'):
|
91 | 57 | # If no record type has been specified then we're a base class
|
92 | 58 | # with nothing to do.
|
93 | 59 | return
|
94 | 60 |
|
95 |
| - # Create an empty device directory. |
96 |
| - # (Potentially this belongs in a mix-in for resolving the linkage |
97 |
| - # between record and instances, but for now this is hard-wired here.) |
98 |
| - cls.__device_directory = {} |
99 |
| - |
100 | 61 | # Convert the list of fields into a dictionary suitable for record
|
101 | 62 | # lookup.
|
102 | 63 | fields = set([cls._link_] + cls.__preset_fields + cls._fields_)
|
@@ -194,7 +155,7 @@ def __init__(self, name, **kargs):
|
194 | 155 | # a call to get_ioinit_info. This is only a trivial attempt to
|
195 | 156 | # reduce resource consumption.
|
196 | 157 | self.__ioscanpvt = imports.IOSCANPVT()
|
197 |
| - self.__super.__init__(name, **kargs) |
| 158 | + super().__init__(name, **kargs) |
198 | 159 |
|
199 | 160 |
|
200 | 161 | def init_record(self, record):
|
@@ -245,7 +206,7 @@ def __init__(self, name, **kargs):
|
245 | 206 | 'Record %s already registered' % name
|
246 | 207 | self._name = name
|
247 | 208 | self._RecordDirectory[name] = self
|
248 |
| - self.__super.__init__(name, **kargs) |
| 209 | + super().__init__(name, **kargs) |
249 | 210 |
|
250 | 211 |
|
251 | 212 | LookupRecord = RecordLookup.LookupRecord
|
|
0 commit comments