|
2 | 2 | import contextlib
|
3 | 3 | import json
|
4 | 4 | import pprint
|
| 5 | +import sys |
5 | 6 | import threading
|
6 | 7 | try:
|
7 | 8 | import configparser
|
|
11 | 12 | import StringIO as io
|
12 | 13 |
|
13 | 14 | import marshmallow
|
14 |
| -from marshmallow import compat |
15 | 15 | from marshmallow import fields
|
16 | 16 | try:
|
17 | 17 | import yaml
|
|
20 | 20 |
|
21 | 21 | # Checking Marshmallow version
|
22 | 22 | MM2 = marshmallow.__version__.startswith('2')
|
| 23 | +PY2 = int(sys.version_info[0]) == 2 |
23 | 24 |
|
24 | 25 |
|
25 | 26 | @marshmallow.post_load
|
@@ -95,7 +96,19 @@ def _deserialize(self, value, attr, data, **kwargs):
|
95 | 96 | **kwargs)
|
96 | 97 |
|
97 | 98 |
|
98 |
| -class Model(compat.with_metaclass(ModelMeta)): |
| 99 | +def with_metaclass(meta, *bases): |
| 100 | + """Create a base class with a metaclass.""" |
| 101 | + # This requires a bit of explanation: the basic idea is to make a dummy |
| 102 | + # metaclass for one level of class instantiation that replaces itself with |
| 103 | + # the actual metaclass. |
| 104 | + class metaclass(meta): # noqa |
| 105 | + |
| 106 | + def __new__(cls, name, this_bases, d): |
| 107 | + return meta(name, bases, d) |
| 108 | + return type.__new__(metaclass, 'temporary_class', (), {}) |
| 109 | + |
| 110 | + |
| 111 | +class Model(with_metaclass(ModelMeta)): |
99 | 112 | __schema_class__ = marshmallow.Schema
|
100 | 113 | __schema__ = None
|
101 | 114 | __missing_fields__ = None
|
@@ -206,7 +219,7 @@ def dump_yaml(self, default_flow_style=False):
|
206 | 219 | @classmethod
|
207 | 220 | def load_ini(cls, data, context=None, partial=None, **kwargs):
|
208 | 221 | parser = configparser.ConfigParser(**kwargs)
|
209 |
| - if compat.PY2: |
| 222 | + if PY2: |
210 | 223 | fp = io.StringIO(data)
|
211 | 224 | parser.readfp(fp)
|
212 | 225 | else:
|
|
0 commit comments