Commit a35dd031 authored by Ian Lee's avatar Ian Lee

Applied PEP8 and Pyflakes style guidelines to fastkml source code using the

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