|
1 | | -from __future__ import absolute_import |
2 | 1 | import re |
3 | 2 | import sys |
4 | 3 | import codecs |
5 | 4 | import functools |
6 | 5 | import copy |
7 | | -import six |
8 | 6 |
|
9 | 7 | from lxml import etree |
10 | 8 |
|
11 | 9 | from django.core.exceptions import (ObjectDoesNotExist, FieldError, |
12 | 10 | MultipleObjectsReturned,) |
13 | 11 | from django.db.models.base import subclass_exception |
14 | 12 | from django.utils.encoding import force_text |
15 | | -from django.utils.encoding import smart_bytes, smart_text |
| 13 | +from django.utils.encoding import smart_bytes, smart_str |
16 | 14 |
|
17 | 15 | from .signals import xmlclass_prepared |
18 | 16 | from .options import Options, DEFAULT_NAMES |
19 | 17 | from .loading import register_xml_models, get_xml_model |
20 | 18 |
|
21 | | -# Alias smart_str based on Python version |
22 | | -smart_str = smart_text if six.PY3 else smart_bytes |
23 | | - |
24 | 19 |
|
25 | 20 | class XmlModelBase(type): |
26 | 21 | """ |
@@ -147,8 +142,7 @@ def _prepare(cls): |
147 | 142 | xmlclass_prepared.send(sender=cls) |
148 | 143 |
|
149 | 144 |
|
150 | | -@six.add_metaclass(XmlModelBase) |
151 | | -class XmlModel(object): |
| 145 | +class XmlModel(metaclass=XmlModelBase): |
152 | 146 |
|
153 | 147 | def __init__(self, root_element_tree): |
154 | 148 | fields_iter = iter(self._meta.fields) |
@@ -184,8 +178,8 @@ def _merge_xpath_kwargs(self, ns=None, ext=None): |
184 | 178 |
|
185 | 179 | xpath_kwargs = { |
186 | 180 | 'namespaces': getattr(opts, 'namespaces', {}), |
187 | | - 'extensions': dict([(k, functools.partial(method, self)) |
188 | | - for k, method in six.iteritems(opts.extensions)]),} |
| 181 | + 'extensions': {k: functools.partial(method, self) |
| 182 | + for k, method in opts.extensions.items()}} |
189 | 183 |
|
190 | 184 | if ns is not None: |
191 | 185 | xpath_kwargs['namespaces'].update(ns) |
@@ -234,14 +228,12 @@ def create_from_file(cls, xml_file): |
234 | 228 |
|
235 | 229 | def __repr__(self): |
236 | 230 | try: |
237 | | - u = six.text_type(self) |
| 231 | + u = str(self) |
238 | 232 | except (UnicodeEncodeError, UnicodeDecodeError): |
239 | 233 | u = '[Bad Unicode data]' |
240 | 234 | return smart_str(u'<%s: %s>' % (self.__class__.__name__, u)) |
241 | 235 |
|
242 | 236 | def __str__(self): |
243 | | - if hasattr(self, '__unicode__'): |
244 | | - return force_text(self).encode('utf-8') |
245 | 237 | return '%s object' % self.__class__.__name__ |
246 | 238 |
|
247 | 239 | def __eq__(self, other): |
|
0 commit comments