Skip to content

Commit f273284

Browse files
committed
Support for Django >= 2.2; swap travis for gh actions
1 parent 0d1ba8f commit f273284

File tree

15 files changed

+88
-208
lines changed

15 files changed

+88
-208
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: [3.7, 3.8]
11+
12+
steps:
13+
- uses: actions/checkout@v1
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install tox tox-gh-actions
22+
- name: Test with tox
23+
run: tox

.travis.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# django-xml
22

3-
[![Build Status](https://travis-ci.org/theatlantic/django-xml.svg?branch=master)](https://travis-ci.org/theatlantic/django-xml)
4-
5-
63
**django-xml** is a python module which provides an abstraction to
74
[lxml](http://lxml.de/)'s XPath and XSLT functionality in a manner resembling
85
django database models.
96

7+
## Note
8+
9+
* Version 2.0 drops support for Django < 1.11
10+
* Version 2.0.1 drops support for Python 3.4
11+
* Version 3.0 adds support for Django>=2.2, drops support for Python < 3.7
12+
13+
1014
## Contents
1115

1216
* [Installation](#installation)

README.rst

Lines changed: 0 additions & 108 deletions
This file was deleted.

djxml/xmlmodels/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
from __future__ import absolute_import
2-
from .loading import (get_apps, get_app, get_xml_models, get_xml_model,
1+
from .loading import (get_apps, get_app, get_xml_models, get_xml_model, # noqa
32
register_xml_models,)
4-
from . import signals
5-
from .base import XmlModel
6-
from .decorators import lxml_extension
7-
from .fields import (XmlElementField, XmlPrimaryElementField,
3+
from . import signals # noqa
4+
from .base import XmlModel # noqa
5+
from .decorators import lxml_extension # noqa
6+
from .fields import (XmlElementField, XmlPrimaryElementField, # noqa
87
XPathSingleNodeField, XPathTextField, XPathIntegerField,
98
XPathFloatField, XPathDateTimeField, XPathListField,
109
XPathTextListField, XPathIntegerListField,
1110
XPathFloatListField, XPathDateTimeListField, XsltField,
1211
XPathHtmlField, XPathHtmlListField,
1312
XPathInnerHtmlField, XPathInnerHtmlListField,
1413
XPathBooleanField, XPathBooleanListField, SchematronField,)
15-
from .related import (EmbeddedXPathField, EmbeddedXPathListField,
14+
from .related import (EmbeddedXPathField, EmbeddedXPathListField, # noqa
1615
EmbeddedXsltField, EmbeddedSchematronField,)

djxml/xmlmodels/base.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
from __future__ import absolute_import
21
import re
32
import sys
43
import codecs
54
import functools
65
import copy
7-
import six
86

97
from lxml import etree
108

119
from django.core.exceptions import (ObjectDoesNotExist, FieldError,
1210
MultipleObjectsReturned,)
1311
from django.db.models.base import subclass_exception
1412
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
1614

1715
from .signals import xmlclass_prepared
1816
from .options import Options, DEFAULT_NAMES
1917
from .loading import register_xml_models, get_xml_model
2018

21-
# Alias smart_str based on Python version
22-
smart_str = smart_text if six.PY3 else smart_bytes
23-
2419

2520
class XmlModelBase(type):
2621
"""
@@ -147,8 +142,7 @@ def _prepare(cls):
147142
xmlclass_prepared.send(sender=cls)
148143

149144

150-
@six.add_metaclass(XmlModelBase)
151-
class XmlModel(object):
145+
class XmlModel(metaclass=XmlModelBase):
152146

153147
def __init__(self, root_element_tree):
154148
fields_iter = iter(self._meta.fields)
@@ -184,8 +178,8 @@ def _merge_xpath_kwargs(self, ns=None, ext=None):
184178

185179
xpath_kwargs = {
186180
'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()}}
189183

190184
if ns is not None:
191185
xpath_kwargs['namespaces'].update(ns)
@@ -234,14 +228,12 @@ def create_from_file(cls, xml_file):
234228

235229
def __repr__(self):
236230
try:
237-
u = six.text_type(self)
231+
u = str(self)
238232
except (UnicodeEncodeError, UnicodeDecodeError):
239233
u = '[Bad Unicode data]'
240234
return smart_str(u'<%s: %s>' % (self.__class__.__name__, u))
241235

242236
def __str__(self):
243-
if hasattr(self, '__unicode__'):
244-
return force_text(self).encode('utf-8')
245237
return '%s object' % self.__class__.__name__
246238

247239
def __eq__(self, other):

djxml/xmlmodels/descriptors.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
import six
31
import functools
42

53
from lxml import etree
@@ -85,9 +83,8 @@ def __get__(self, instance, instance_type=None):
8583
namespaces.update(getattr(instance._meta, 'namespaces', {}))
8684
namespaces.update(getattr(self.field, 'extra_namespaces', {}))
8785

88-
extensions = {}
89-
for k, method in six.iteritems(instance._meta.extensions):
90-
extensions[k] = functools.partial(method, instance)
86+
extensions = {k: functools.partial(method, instance)
87+
for k, method in instance._meta.extensions.items()}
9188
extensions.update(self.field.extensions)
9289

9390
xpath_eval = etree.XPathEvaluator(tree, namespaces=namespaces,
@@ -119,9 +116,8 @@ def __get__(self, instance, instance_type=None):
119116
tree = instance._get_etree_val()
120117
xslt_tree = self.field.get_xslt_tree(instance)
121118

122-
extensions = {}
123-
for k, method in six.iteritems(instance._meta.extensions):
124-
extensions[k] = functools.partial(method, instance)
119+
extensions = {k: functools.partial(method, instance)
120+
for k, method in instance._meta.extensions.items()}
125121
extensions.update(self.field.extensions)
126122

127123
transform = etree.XSLT(xslt_tree, extensions=extensions)

djxml/xmlmodels/exceptions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from __future__ import absolute_import
21
from django.core.exceptions import ValidationError
3-
from django.utils import six
42

53
class XmlModelException(Exception):
64
pass
@@ -21,17 +19,17 @@ def __str__(self):
2119
return str(self.apply_exception)
2220

2321
def __unicode__(self):
24-
msg = six.text_type(self.apply_exception)
22+
msg = str(self.apply_exception)
2523
debug_output = self.get_debug_output()
2624
if len(debug_output) > 0:
27-
msg += u"\n\n" + debug_output
25+
msg += "\n\n" + debug_output
2826
return msg
2927

3028
def get_debug_output(self):
3129
debug_lines = []
3230
for entry in self.error_log:
33-
entry_filename = u'%s ' % entry.filename if entry.filename != '<string>' else ''
34-
debug_line = u'%(msg)s [%(file)sline %(line)s, col %(col)s]' % {
31+
entry_filename = '%s ' % entry.filename if entry.filename != '<string>' else ''
32+
debug_line = '%(msg)s [%(file)sline %(line)s, col %(col)s]' % {
3533
'file': entry_filename,
3634
'line': entry.line,
3735
'col': entry.column,

0 commit comments

Comments
 (0)