Skip to content

Commit

Permalink
Merge pull request #44 from tobinus/port-to-python-2-#19
Browse files Browse the repository at this point in the history
Add support for Python 2.7, closes #19
  • Loading branch information
tobinus authored Jul 13, 2016
2 parents 29f1552 + 78c9547 commit 342ad70
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: python

python:
# - "2.6"
# - "2.7"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
Expand Down
2 changes: 2 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ head around ambiguous, undocumented APIs. PodGen incorporates the industry's
best practices and lets you focus on collecting the necessary metadata and
publishing the podcast.

PodGen is compatible with Python 2.7 and 3.3+.


User Guide
----------
Expand Down
3 changes: 3 additions & 0 deletions doc/user/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Installation
============

PodGen can be used on any system (if not: file a bug report!), and supports
Python 2.7 and 3.3, 3.4 and 3.5.

Use `pip <https://pypi.python.org/pypi>`_::

$ pip install podgen
Expand Down
11 changes: 6 additions & 5 deletions podgen/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
import warnings
from future.moves.urllib.parse import urlparse
from future.utils import raise_from
import datetime

from podgen.not_supported_by_itunes_warning import NotSupportedByItunesWarning
Expand Down Expand Up @@ -246,11 +247,11 @@ def get_type(self, url):
try:
return self.file_types[file_extension]
except KeyError as e:
raise ValueError("The file extension %s was not recognized, which "
"means it's not supported by iTunes. If this is "
"intended, please provide the type yourself so "
"clients can see what type of file it is."
% file_extension) from e
raise_from(ValueError(
"The file extension %s was not recognized, which means it's "
"not supported by iTunes. If this is intended, please provide "
"the type yourself so clients can see what type of file it is."
% file_extension), e)

@property
def duration(self):
Expand Down
8 changes: 4 additions & 4 deletions podgen/podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def _get_xslt_pi(self):
return etree.tostring(etree.ProcessingInstruction(
"xml-stylesheet",
'type="text/xsl" href="' + quote_sanitized + '"',
), encoding=str)
), encoding="UTF-8").decode("UTF-8")

def __str__(self):
"""Print the podcast in RSS format, using the default options.
Expand All @@ -660,12 +660,12 @@ def rss_str(self, minimize=False, encoding='UTF-8',
lines and adding properly indentation, saving bytes at the cost of
readability (default: False).
:type minimize: bool
:param encoding: Encoding used in the XML file (default: UTF-8).
:param encoding: Encoding used in the XML declaration (default: UTF-8).
:type encoding: str
:param xml_declaration: Whether an XML declaration should be added to
the output (default: True).
:type xml_declaration: bool
:returns: The generated RSS feed as a :obj:`str`.
:returns: The generated RSS feed as a :obj:`str` (unicode in 2.7)
"""
feed = self._create_rss()
rss = etree.tostring(feed, pretty_print=not minimize, encoding=encoding,
Expand Down Expand Up @@ -1133,7 +1133,7 @@ def skip_days(self, days):
if not d.lower() in ['monday', 'tuesday', 'wednesday', 'thursday',
'friday', 'saturday', 'sunday']:
raise ValueError('Invalid day %s' % d)
self.__skip_days = {day.capitalize() for day in days}
self.__skip_days = set(day.capitalize() for day in days)
else:
self.__skip_days = None

Expand Down
14 changes: 7 additions & 7 deletions podgen/tests/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ def test_autoRecognizeType(self):
# Mapping between url file extension and type given by iTunes
# https://help.apple.com/itc/podcasts_connect/#/itcb54353390
types = {
'.mp3': {"audio/mpeg"},
'.m4a': {"audio/x-m4a"},
'.mov': {"video/quicktime"},
'.mp4': {"video/mp4"},
'.m4v': {"video/x-m4v"},
'.pdf': {"application/pdf"},
'.epub': {"document/x-epub"},
'.mp3': set(["audio/mpeg"]),
'.m4a': set(["audio/x-m4a"]),
'.mov': set(["video/quicktime"]),
'.mp4': set(["video/mp4"]),
'.m4v': set(["video/x-m4v"]),
'.pdf': set(["application/pdf"]),
'.epub': set(["document/x-epub"]),
}

for (file_extension, allowed_types) in iteritems(types):
Expand Down
13 changes: 7 additions & 6 deletions podgen/tests/test_podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from lxml import etree
import tempfile
import os
from future.utils import raise_from

from podgen import Person, Category, Podcast
import podgen.version
Expand Down Expand Up @@ -53,8 +54,8 @@ def setUp(self):
'email': 'Contributor email'}
self.copyright = "The copyright notice"
self.docs = 'http://www.rssboard.org/rss-specification'
self.skip_days = {'Tuesday'}
self.skip_hours = {23}
self.skip_days = set(['Tuesday'])
self.skip_hours = set([23])

self.explicit = False

Expand Down Expand Up @@ -454,12 +455,12 @@ def test_mandatoryValues(self):
# Try to create a Podcast once for each mandatory property.
# On each iteration, exactly one of the properties is not set.
# Therefore, an exception should be thrown on each iteration.
mandatory_properties = {
mandatory_properties = set([
"description",
"title",
"link",
"explicit",
}
])

for test_property in mandatory_properties:
fg = Podcast()
Expand All @@ -474,8 +475,8 @@ def test_mandatoryValues(self):
try:
self.assertRaises(ValueError, fg._create_rss)
except AssertionError as e:
raise AssertionError("The test failed for %s" % test_property)\
from e
raise_from(AssertionError(
"The test failed for %s" % test_property), e)

def test_withholdFromItunesOffByDefault(self):
assert not self.fg.withhold_from_itunes
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PodGen (forked from python-feedgen)


This module can be used to generate podcast feeds in RSS format, and is
compatible with Python 3.3+.
compatible with Python 2.7 and 3.3+.

It is licensed under the terms of both, the FreeBSD license and the LGPLv3+.
Choose the one which is more convenient for you. For more details have a look
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
Expand Down

0 comments on commit 342ad70

Please sign in to comment.