Commit 15ac35f8 authored by Jonathan's avatar Jonathan

Merge branch 'master' of https://github.com/cleder/fastkml

Conflicts:
	fastkml/kml.py
parents e7e778f0 365ed6e5
...@@ -17,7 +17,8 @@ install: ...@@ -17,7 +17,8 @@ install:
# command to run tests, e.g. python setup.py test # command to run tests, e.g. python setup.py test
script: script:
coverage run --source=fastkml setup.py test - pep8 --exclude test_main.py fastkml
- coverage run --source=fastkml setup.py test
after_success: after_success:
coveralls coveralls
......
...@@ -5,4 +5,4 @@ Contributors ...@@ -5,4 +5,4 @@ Contributors
- Jeremy Blalock - Jeremy Blalock
- Denis Krienbühl - Denis Krienbühl
- Egil Möller - Egil Möller
- Ian Lee - Ian Lee <IanLee1521@gmail.com>
...@@ -6,6 +6,8 @@ Changelog ...@@ -6,6 +6,8 @@ Changelog
---------------- ----------------
- test case additions and lxml warning [Ian Lee] - test case additions and lxml warning [Ian Lee]
- pep8-ify source code (except test_main.py) [Ian Lee]
- pyflakes-ify source code (except __init__.py) [Ian Lee]
0.6 (2014/05/29) 0.6 (2014/05/29)
---------------- ----------------
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2012 Christian Ledermann # Copyright (C) 2012 Christian Ledermann
#
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either # License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version. # version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, # This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details. # Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public # You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from .kml import KML, Document, Folder, Placemark from .kml import KML, Document, Folder, Placemark
from .kml import TimeSpan, TimeStamp from .kml import TimeSpan, TimeStamp
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2012 Christian Ledermann # Copyright (C) 2012 Christian Ledermann
#
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either # License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version. # version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, # This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details. # Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public # You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
""" """
KML 2.2 supports new elements for including data about the author and KML 2.2 supports new elements for including data about the author and
related website in your KML file. This information is displayed in geo related website in your KML file. This information is displayed in geo
...@@ -82,10 +82,11 @@ class Link(object): ...@@ -82,10 +82,11 @@ class Link(object):
length = None length = None
# the length of the resource, in bytes # the length of the resource, in bytes
def __init__(
def __init__(self, ns=None, href=None, rel=None, type=None, self, ns=None, href=None, rel=None, type=None,
hreflang=None, title=None, length=None): hreflang=None, title=None, length=None
if ns == None: ):
if ns is None:
self.ns = NS self.ns = NS
else: else:
self.ns = ns self.ns = ns
...@@ -99,7 +100,6 @@ class Link(object): ...@@ -99,7 +100,6 @@ class Link(object):
def from_string(self, xml_string): def from_string(self, xml_string):
self.from_element(etree.XML(xml_string)) self.from_element(etree.XML(xml_string))
def from_element(self, element): def from_element(self, element):
if self.ns + self.__name__.lower() != element.tag: if self.ns + self.__name__.lower() != element.tag:
raise TypeError raise TypeError
...@@ -120,7 +120,6 @@ class Link(object): ...@@ -120,7 +120,6 @@ class Link(object):
if element.get('length'): if element.get('length'):
self.length = element.get('length') self.length = element.get('length')
def etree_element(self): def etree_element(self):
element = etree.Element(self.ns + self.__name__.lower()) element = etree.Element(self.ns + self.__name__.lower())
if self.href: if self.href:
...@@ -142,11 +141,14 @@ class Link(object): ...@@ -142,11 +141,14 @@ class Link(object):
def to_string(self, prettyprint=True): def to_string(self, prettyprint=True):
""" Return the ATOM Object as serialized xml """ """ Return the ATOM Object as serialized xml """
if LXML and prettyprint: if LXML and prettyprint:
return etree.tostring(self.etree_element(), encoding='utf-8', return etree.tostring(
pretty_print=True).decode('UTF-8') self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8')
else: else:
return etree.tostring(self.etree_element(), return etree.tostring(
encoding='utf-8').decode('UTF-8') self.etree_element(),
encoding='utf-8').decode('UTF-8')
class _Person(object): class _Person(object):
...@@ -159,16 +161,16 @@ class _Person(object): ...@@ -159,16 +161,16 @@ class _Person(object):
ns = None ns = None
name = None name = None
#conveys a human-readable name for the person. # conveys a human-readable name for the person.
uri = None uri = None
#contains a home page for the person. # contains a home page for the person.
email = None email = None
#contains an email address for the person. # contains an email address for the person.
def __init__(self, ns=None, name=None, uri=None, email=None): def __init__(self, ns=None, name=None, uri=None, email=None):
if ns == None: if ns is None:
self.ns = NS self.ns = NS
else: else:
self.ns = ns self.ns = ns
...@@ -176,27 +178,24 @@ class _Person(object): ...@@ -176,27 +178,24 @@ class _Person(object):
self.uri = uri self.uri = uri
self.email = email self.email = email
def etree_element(self): def etree_element(self):
element = etree.Element(self.ns + self.__name__.lower()) element = etree.Element(self.ns + self.__name__.lower())
if self.name: if self.name:
name = etree.SubElement(element, "%sname" %self.ns) name = etree.SubElement(element, "%sname" % self.ns)
name.text = self.name name.text = self.name
#else: # else:
# logger.critical('No Name for person defined') # logger.critical('No Name for person defined')
# raise TypeError # raise TypeError
if self.uri: if self.uri:
#XXX validate uri # XXX validate uri
uri = etree.SubElement(element, "%suri" %self.ns) uri = etree.SubElement(element, "%suri" % self.ns)
uri.text = self.uri uri.text = self.uri
if self.email: if self.email:
if check_email(self.email): if check_email(self.email):
email = etree.SubElement(element, "%semail" %self.ns) email = etree.SubElement(element, "%semail" % self.ns)
email.text = self.email email.text = self.email
return element return element
def from_string(self, xml_string): def from_string(self, xml_string):
self.from_element(etree.XML(xml_string)) self.from_element(etree.XML(xml_string))
...@@ -204,13 +203,13 @@ class _Person(object): ...@@ -204,13 +203,13 @@ class _Person(object):
if self.ns + self.__name__.lower() != element.tag: if self.ns + self.__name__.lower() != element.tag:
raise TypeError raise TypeError
else: else:
name = element.find('%sname' %self.ns) name = element.find('%sname' % self.ns)
if name is not None: if name is not None:
self.name = name.text self.name = name.text
uri = element.find('%suri' %self.ns) uri = element.find('%suri' % self.ns)
if uri is not None: if uri is not None:
self.uri = uri.text self.uri = uri.text
email = element.find('%semail' %self.ns) email = element.find('%semail' % self.ns)
if email is not None: if email is not None:
if check_email(email.text): if check_email(email.text):
self.email = email.text self.email = email.text
...@@ -218,21 +217,23 @@ class _Person(object): ...@@ -218,21 +217,23 @@ class _Person(object):
def to_string(self, prettyprint=True): def to_string(self, prettyprint=True):
""" Return the ATOM Object as serialized xml """ """ Return the ATOM Object as serialized xml """
if LXML and prettyprint: if LXML and prettyprint:
return etree.tostring(self.etree_element(), encoding='utf-8', return etree.tostring(
pretty_print=True).decode('UTF-8') self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8')
else: else:
return etree.tostring(self.etree_element(), return etree.tostring(
encoding='utf-8').decode('UTF-8') self.etree_element(),
encoding='utf-8').decode('UTF-8')
class Author(_Person): class Author(_Person):
""" Names one author of the feed/entry. A feed/entry may have """ Names one author of the feed/entry. A feed/entry may have
multiple authors.""" multiple authors."""
__name__ = "Author" __name__ = "Author"
class Contributor(_Person): class Contributor(_Person):
""" Names one contributor to the feed/entry. A feed/entry may have """ Names one contributor to the feed/entry. A feed/entry may have
multiple contributor elements.""" multiple contributor elements."""
__name__ = "Contributor" __name__ = "Contributor"
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2012 Christian Ledermann # Copyright (C) 2012 Christian Ledermann
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either # License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version. # version 2.1 of the License, or (at your option) any later version.
# #
# This library is distributed in the hope that it will be useful, # This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details. # Lesser General Public License for more details.
# #
# You should have received a copy of the GNU Lesser General Public # You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
""" abstract base classes""" """ abstract base classes"""
import fastkml.config as config import fastkml.config as config
from fastkml.config import etree from fastkml.config import etree
class _XMLObject(object): class _XMLObject(object):
""" XML Baseclass""" """ XML Baseclass"""
...@@ -27,7 +28,7 @@ class _XMLObject(object): ...@@ -27,7 +28,7 @@ class _XMLObject(object):
ns = None ns = None
def __init__(self, ns=None): def __init__(self, ns=None):
if ns == None: if ns is None:
self.ns = config.NS self.ns = config.NS
else: else:
self.ns = ns self.ns = ns
...@@ -36,12 +37,16 @@ class _XMLObject(object): ...@@ -36,12 +37,16 @@ class _XMLObject(object):
if self.__name__: if self.__name__:
element = etree.Element(self.ns + self.__name__) element = etree.Element(self.ns + self.__name__)
else: else:
raise NotImplementedError("Call of abstract base class, subclasses implement this!") raise NotImplementedError(
"Call of abstract base class, subclasses implement this!"
)
return element return element
def from_element(self, element): def from_element(self, element):
if self.ns + self.__name__ != element.tag: if self.ns + self.__name__ != element.tag:
raise TypeError("Call of abstract base class, subclasses implement this!") raise TypeError(
"Call of abstract base class, subclasses implement this!"
)
def from_string(self, xml_string): def from_string(self, xml_string):
self.from_element(etree.XML(xml_string)) self.from_element(etree.XML(xml_string))
...@@ -49,11 +54,15 @@ class _XMLObject(object): ...@@ -49,11 +54,15 @@ class _XMLObject(object):
def to_string(self, prettyprint=True): def to_string(self, prettyprint=True):
""" Return the KML Object as serialized xml """ """ Return the KML Object as serialized xml """
if config.LXML and prettyprint: if config.LXML and prettyprint:
return etree.tostring(self.etree_element(), encoding='utf-8', return etree.tostring(
pretty_print=True).decode('UTF-8') self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8')
else: else:
return etree.tostring(self.etree_element(), return etree.tostring(
encoding='utf-8').decode('UTF-8') self.etree_element(),
encoding='utf-8').decode('UTF-8')
class _BaseObject(_XMLObject): class _BaseObject(_XMLObject):
""" This is an abstract base class and cannot be used directly in a """ This is an abstract base class and cannot be used directly in a
...@@ -68,7 +77,7 @@ class _BaseObject(_XMLObject): ...@@ -68,7 +77,7 @@ class _BaseObject(_XMLObject):
def __init__(self, ns=None, id=None): def __init__(self, ns=None, id=None):
super(_BaseObject, self).__init__(ns) super(_BaseObject, self).__init__(ns)
self.id = id self.id = id
if ns == None: if ns is None:
self.ns = config.NS self.ns = config.NS
else: else:
self.ns = ns self.ns = ns
...@@ -81,12 +90,9 @@ class _BaseObject(_XMLObject): ...@@ -81,12 +90,9 @@ class _BaseObject(_XMLObject):
element.set('targetId', self.targetId) element.set('targetId', self.targetId)
return element return element
def from_element(self, element): def from_element(self, element):
super(_BaseObject, self).from_element(element) super(_BaseObject, self).from_element(element)
if element.get('id'): if element.get('id'):
self.id = element.get('id') self.id = element.get('id')
if element.get('targetId'): if element.get('targetId'):
self.targetId = element.get('targetId') self.targetId = element.get('targetId')
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2012 Christian Ledermann # Copyright (C) 2012 Christian Ledermann
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either # License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version. # version 2.1 of the License, or (at your option) any later version.
# #
# This library is distributed in the hope that it will be useful, # This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details. # Lesser General Public License for more details.
# #
# You should have received a copy of the GNU Lesser General Public # You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""frequently used constants and abstract base classes""" """frequently used constants and abstract base classes"""
import logging import logging
......
This diff is collapsed.
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2012 Christian Ledermann # Copyright (C) 2012 Christian Ledermann
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either # License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version. # version 2.1 of the License, or (at your option) any later version.
# #
# This library is distributed in the hope that it will be useful, # This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details. # Lesser General Public License for more details.
# #
# You should have received a copy of the GNU Lesser General Public # You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
""" """
With the launch of Google Earth 5.0, Google has provided extensions to KML With the launch of Google Earth 5.0, Google has provided extensions to KML
...@@ -76,9 +76,6 @@ located at http://developers.google.com/kml/schema/kml22gx.xsd. ...@@ -76,9 +76,6 @@ located at http://developers.google.com/kml/schema/kml22gx.xsd.
import logging import logging
logger = logging.getLogger('fastkml.gx') logger = logging.getLogger('fastkml.gx')
from .config import etree # from .config import etree
from .config import GXNS as NS # from .config import GXNS as NS
from .config import LXML # from .config import LXML
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
-r common.txt -r common.txt
pytest pytest
pep8
coveralls coveralls
from setuptools import setup, find_packages from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand from setuptools.command.test import test as TestCommand
import sys, os import sys
import os
class PyTest(TestCommand): class PyTest(TestCommand):
def finalize_options(self): def finalize_options(self):
TestCommand.finalize_options(self) TestCommand.finalize_options(self)
self.test_args = [] self.test_args = []
self.test_suite = True self.test_suite = True
def run_tests(self): def run_tests(self):
#import here, cause outside the eggs aren't loaded # import here, cause outside the eggs aren't loaded
import pytest import pytest
errno = pytest.main(self.test_args) errno = pytest.main(self.test_args)
sys.exit(errno) sys.exit(errno)
...@@ -16,14 +19,16 @@ class PyTest(TestCommand): ...@@ -16,14 +19,16 @@ class PyTest(TestCommand):
version = '0.7' version = '0.7'
setup(name='fastkml', setup(
version=version, name='fastkml',
description="Fast KML processing in python", version=version,
long_description=open( description="Fast KML processing in python",
"README.rst").read() + "\n" + long_description=(
open(os.path.join("docs", "HISTORY.txt")).read() + "\n" + open("README.rst").read() + "\n" +
open(os.path.join("docs", "TODO.txt")).read(), open(os.path.join("docs", "HISTORY.txt")).read() + "\n" +
classifiers=[ open(os.path.join("docs", "TODO.txt")).read()
),
classifiers=[
"Topic :: Scientific/Engineering :: GIS", "Topic :: Scientific/Engineering :: GIS",
"Programming Language :: Python", "Programming Language :: Python",
'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2',
...@@ -37,23 +42,23 @@ setup(name='fastkml', ...@@ -37,23 +42,23 @@ setup(name='fastkml',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)', 'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
'Development Status :: 4 - Beta', 'Development Status :: 4 - Beta',
'Operating System :: OS Independent', 'Operating System :: OS Independent',
], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers ], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
keywords='GIS KML Google Maps OpenLayers', keywords='GIS KML Google Maps OpenLayers',
author='Christian Ledermann', author='Christian Ledermann',
author_email='christian.ledermann@gmail.com', author_email='christian.ledermann@gmail.com',
url='https://github.com/cleder/fastkml', url='https://github.com/cleder/fastkml',
license='LGPL', license='LGPL',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
tests_require=['pytest'], tests_require=['pytest'],
cmdclass = {'test': PyTest}, cmdclass = {'test': PyTest},
install_requires=[ install_requires=[
# -*- Extra requirements: -*- # -*- Extra requirements: -*-
'pygeoif', 'pygeoif',
'python-dateutil', 'python-dateutil',
], ],
entry_points=""" entry_points="""
# -*- Entry points: -*- # -*- Entry points: -*-
""", """,
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment