Add Python 3 compatibility.

This commit is contained in:
Vincent Driessen 2014-09-20 23:51:04 +02:00 committed by Lars Kiesow
parent 72b2896cf8
commit 626d9df6c4
3 changed files with 9 additions and 7 deletions

View file

@ -13,6 +13,7 @@ from datetime import datetime
import dateutil.parser import dateutil.parser
import dateutil.tz import dateutil.tz
from feedgen.util import ensure_format from feedgen.util import ensure_format
from six import string_types
class FeedEntry(object): class FeedEntry(object):
@ -282,7 +283,7 @@ class FeedEntry(object):
:returns: Modification date as datetime.datetime :returns: Modification date as datetime.datetime
''' '''
if not updated is None: if not updated is None:
if isinstance(updated, basestring): if isinstance(updated, string_types):
updated = dateutil.parser.parse(updated) updated = dateutil.parser.parse(updated)
if not isinstance(updated, datetime): if not isinstance(updated, datetime):
raise ValueError('Invalid datetime format') raise ValueError('Invalid datetime format')
@ -549,7 +550,7 @@ class FeedEntry(object):
:returns: Creation date as datetime.datetime :returns: Creation date as datetime.datetime
''' '''
if not published is None: if not published is None:
if isinstance(published, basestring): if isinstance(published, string_types):
published = dateutil.parser.parse(published) published = dateutil.parser.parse(published)
if not isinstance(published, datetime): if not isinstance(published, datetime):
raise ValueError('Invalid datetime format') raise ValueError('Invalid datetime format')

View file

@ -17,6 +17,7 @@ from feedgen.entry import FeedEntry
from feedgen.util import ensure_format from feedgen.util import ensure_format
import feedgen.version import feedgen.version
import sys import sys
from six import string_types
_feedgen_version = feedgen.version.version_str _feedgen_version = feedgen.version.version_str
@ -431,7 +432,7 @@ class FeedGenerator(object):
:returns: Modification date as datetime.datetime :returns: Modification date as datetime.datetime
''' '''
if not updated is None: if not updated is None:
if isinstance(updated, basestring): if isinstance(updated, string_types):
updated = dateutil.parser.parse(updated) updated = dateutil.parser.parse(updated)
if not isinstance(updated, datetime): if not isinstance(updated, datetime):
raise ValueError('Invalid datetime format') raise ValueError('Invalid datetime format')
@ -670,9 +671,9 @@ class FeedGenerator(object):
''' '''
if not generator is None: if not generator is None:
self.__atom_generator = {'value':generator} self.__atom_generator = {'value':generator}
if not version in None: if not version is None:
self.__atom_generator['version'] = version self.__atom_generator['version'] = version
if not uri in None: if not uri is None:
self.__atom_generator['uri'] = uri self.__atom_generator['uri'] = uri
self.__rss_generator = generator self.__rss_generator = generator
return self.__atom_generator return self.__atom_generator
@ -846,7 +847,7 @@ class FeedGenerator(object):
:returns: Publication date as datetime.datetime :returns: Publication date as datetime.datetime
''' '''
if not pubDate is None: if not pubDate is None:
if isinstance(pubDate, basestring): if isinstance(pubDate, string_types):
pubDate = dateutil.parser.parse(pubDate) pubDate = dateutil.parser.parse(pubDate)
if not isinstance(pubDate, datetime): if not isinstance(pubDate, datetime):
raise ValueError('Invalid datetime format') raise ValueError('Invalid datetime format')

View file

@ -14,7 +14,7 @@ setup(
url = 'http://lkiesow.github.io/python-feedgen', url = 'http://lkiesow.github.io/python-feedgen',
keywords = ['feed','ATOM','RSS','podcast'], keywords = ['feed','ATOM','RSS','podcast'],
license = 'FreeBSD and LGPLv3+', license = 'FreeBSD and LGPLv3+',
install_requires = ['lxml', 'dateutils'], install_requires = ['lxml', 'dateutils', 'six'],
classifiers = [ classifiers = [
'Development Status :: 4 - Beta', 'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable', 'Development Status :: 5 - Production/Stable',