Commit 998d452b authored by Christian Ledermann's avatar Christian Ledermann

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

parents b439f788 365ed6e5
...@@ -9,16 +9,16 @@ python: ...@@ -9,16 +9,16 @@ python:
env: env:
- LXML=true - LXML=true
- LXML=false - LXML=false
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
# install: PLEASE CHANGE ME # command to install dependencies, e.g. pip install -r requirements.txt
install: install:
- pip install coveralls --use-mirrors - pip install -r requirements/test.txt
- if $LXML == true; then pip install --use-mirrors lxml; fi - if $LXML == true; then pip install lxml; fi
# 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
......
...@@ -28,6 +28,18 @@ fastkml is continually tested with *Travis CI* ...@@ -28,6 +28,18 @@ fastkml is continually tested with *Travis CI*
:target: https://www.ohloh.net/p/fastkml :target: https://www.ohloh.net/p/fastkml
Requirements
============
You can install the requirements for fastkml by using pip:
pip install -r requirements/common.txt
To install packages required for running tests:
pip install -r requirements/test.txt
Limitations Limitations
=========== ===========
......
...@@ -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
......
# -*- 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
...@@ -79,13 +79,14 @@ class Link(object): ...@@ -79,13 +79,14 @@ class Link(object):
title = None title = None
# human readable information about the link # human readable information about the link
lenght = 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, lenght=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
...@@ -94,12 +95,11 @@ class Link(object): ...@@ -94,12 +95,11 @@ class Link(object):
self.type = type self.type = type
self.hreflang = hreflang self.hreflang = hreflang
self.title = title self.title = title
self.lenght = lenght self.length = length
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
...@@ -117,9 +117,8 @@ class Link(object): ...@@ -117,9 +117,8 @@ class Link(object):
self.hreflang = element.get('hreflang') self.hreflang = element.get('hreflang')
if element.get('title'): if element.get('title'):
self.title = element.get('title') self.title = element.get('title')
if element.get('lenght'): if element.get('length'):
self.lenght = element.get('lenght') 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())
...@@ -135,17 +134,20 @@ class Link(object): ...@@ -135,17 +134,20 @@ class Link(object):
element.set('hreflang', self.hreflang) element.set('hreflang', self.hreflang)
if self.title: if self.title:
element.set('title', self.title) element.set('title', self.title)
if self.lenght: if self.length:
element.set('lenght', self.lenght) element.set('length', self.length)
return element return element
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(
self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8') pretty_print=True).decode('UTF-8')
else: else:
return etree.tostring(self.etree_element(), return etree.tostring(
self.etree_element(),
encoding='utf-8').decode('UTF-8') encoding='utf-8').decode('UTF-8')
...@@ -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(
self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8') pretty_print=True).decode('UTF-8')
else: else:
return etree.tostring(self.etree_element(), return etree.tostring(
self.etree_element(),
encoding='utf-8').decode('UTF-8') 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"
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
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,12 +54,16 @@ class _XMLObject(object): ...@@ -49,12 +54,16 @@ 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(
self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8') pretty_print=True).decode('UTF-8')
else: else:
return etree.tostring(self.etree_element(), return etree.tostring(
self.etree_element(),
encoding='utf-8').decode('UTF-8') 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
KML file. It provides the id attribute, which allows unique KML file. It provides the id attribute, which allows unique
...@@ -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')
This diff is collapsed.
...@@ -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.
pygeoif
python-dateutil
-r common.txt
pytest
pep8
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,13 +19,15 @@ class PyTest(TestCommand): ...@@ -16,13 +19,15 @@ class PyTest(TestCommand):
version = '0.7' version = '0.7'
setup(name='fastkml', setup(
name='fastkml',
version=version, version=version,
description="Fast KML processing in python", description="Fast KML processing in python",
long_description=open( long_description=(
"README.rst").read() + "\n" + open("README.rst").read() + "\n" +
open(os.path.join("docs", "HISTORY.txt")).read() + "\n" + open(os.path.join("docs", "HISTORY.txt")).read() + "\n" +
open(os.path.join("docs", "TODO.txt")).read(), open(os.path.join("docs", "TODO.txt")).read()
),
classifiers=[ classifiers=[
"Topic :: Scientific/Engineering :: GIS", "Topic :: Scientific/Engineering :: GIS",
"Programming Language :: Python", "Programming Language :: Python",
...@@ -56,4 +61,4 @@ setup(name='fastkml', ...@@ -56,4 +61,4 @@ setup(name='fastkml',
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