Commit 365ed6e5 authored by Christian Ledermann's avatar Christian Ledermann

Merge pull request #13 from IanLee1521/pep8

Pep8
parents 9eac7e71 d8d77db0
......@@ -17,7 +17,8 @@ install:
# command to run tests, e.g. python setup.py test
script:
coverage run --source=fastkml setup.py test
- pep8 --exclude test_main.py fastkml
- coverage run --source=fastkml setup.py test
after_success:
coveralls
......
......@@ -5,4 +5,4 @@ Contributors
- Jeremy Blalock
- Denis Krienbühl
- Egil Möller
- Ian Lee
- Ian Lee <IanLee1521@gmail.com>
......@@ -6,6 +6,8 @@ Changelog
----------------
- 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)
----------------
......
# -*- 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
......
# -*- 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
......@@ -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,10 +141,13 @@ 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',
return etree.tostring(
self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8')
else:
return etree.tostring(self.etree_element(),
return etree.tostring(
self.etree_element(),
encoding='utf-8').decode('UTF-8')
......@@ -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',
return etree.tostring(
self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8')
else:
return etree.tostring(self.etree_element(),
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"
......@@ -20,6 +20,7 @@
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,12 +54,16 @@ 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',
return etree.tostring(
self.etree_element(),
encoding='utf-8',
pretty_print=True).decode('UTF-8')
else:
return etree.tostring(self.etree_element(),
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
KML file. It provides the id attribute, which allows unique
......@@ -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')
This diff is collapsed.
......@@ -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,13 +19,15 @@ class PyTest(TestCommand):
version = '0.7'
setup(name='fastkml',
setup(
name='fastkml',
version=version,
description="Fast KML processing in python",
long_description=open(
"README.rst").read() + "\n" +
long_description=(
open("README.rst").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=[
"Topic :: Scientific/Engineering :: GIS",
"Programming Language :: Python",
......@@ -56,4 +61,4 @@ setup(name='fastkml',
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