Skip to content

Commit 78c9547

Browse files
committed
Add support for Python 2.7, closes #19
I'll admit some of the code has been made uglier, but 2.7 is still used widely and so I think it's worth it. However, I have no experience with the unicode/byte/str thing, so surely something has gone horribly wrong in a subtle way somewhere :P
1 parent 29f1552 commit 78c9547

File tree

9 files changed

+34
-25
lines changed

9 files changed

+34
-25
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: python
22

33
python:
44
# - "2.6"
5-
# - "2.7"
5+
- "2.7"
66
- "3.3"
77
- "3.4"
88
- "3.5"

doc/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ head around ambiguous, undocumented APIs. PodGen incorporates the industry's
4343
best practices and lets you focus on collecting the necessary metadata and
4444
publishing the podcast.
4545

46+
PodGen is compatible with Python 2.7 and 3.3+.
47+
4648

4749
User Guide
4850
----------

doc/user/installation.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Installation
33
============
44

5+
PodGen can be used on any system (if not: file a bug report!), and supports
6+
Python 2.7 and 3.3, 3.4 and 3.5.
7+
58
Use `pip <https://pypi.python.org/pypi>`_::
69

710
$ pip install podgen

podgen/media.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212
import warnings
1313
from future.moves.urllib.parse import urlparse
14+
from future.utils import raise_from
1415
import datetime
1516

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

255256
@property
256257
def duration(self):

podgen/podcast.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def _get_xslt_pi(self):
643643
return etree.tostring(etree.ProcessingInstruction(
644644
"xml-stylesheet",
645645
'type="text/xsl" href="' + quote_sanitized + '"',
646-
), encoding=str)
646+
), encoding="UTF-8").decode("UTF-8")
647647

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

podgen/tests/test_media.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ def test_autoRecognizeType(self):
112112
# Mapping between url file extension and type given by iTunes
113113
# https://help.apple.com/itc/podcasts_connect/#/itcb54353390
114114
types = {
115-
'.mp3': {"audio/mpeg"},
116-
'.m4a': {"audio/x-m4a"},
117-
'.mov': {"video/quicktime"},
118-
'.mp4': {"video/mp4"},
119-
'.m4v': {"video/x-m4v"},
120-
'.pdf': {"application/pdf"},
121-
'.epub': {"document/x-epub"},
115+
'.mp3': set(["audio/mpeg"]),
116+
'.m4a': set(["audio/x-m4a"]),
117+
'.mov': set(["video/quicktime"]),
118+
'.mp4': set(["video/mp4"]),
119+
'.m4v': set(["video/x-m4v"]),
120+
'.pdf': set(["application/pdf"]),
121+
'.epub': set(["document/x-epub"]),
122122
}
123123

124124
for (file_extension, allowed_types) in iteritems(types):

podgen/tests/test_podcast.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from lxml import etree
1414
import tempfile
1515
import os
16+
from future.utils import raise_from
1617

1718
from podgen import Person, Category, Podcast
1819
import podgen.version
@@ -53,8 +54,8 @@ def setUp(self):
5354
'email': 'Contributor email'}
5455
self.copyright = "The copyright notice"
5556
self.docs = 'http://www.rssboard.org/rss-specification'
56-
self.skip_days = {'Tuesday'}
57-
self.skip_hours = {23}
57+
self.skip_days = set(['Tuesday'])
58+
self.skip_hours = set([23])
5859

5960
self.explicit = False
6061

@@ -454,12 +455,12 @@ def test_mandatoryValues(self):
454455
# Try to create a Podcast once for each mandatory property.
455456
# On each iteration, exactly one of the properties is not set.
456457
# Therefore, an exception should be thrown on each iteration.
457-
mandatory_properties = {
458+
mandatory_properties = set([
458459
"description",
459460
"title",
460461
"link",
461462
"explicit",
462-
}
463+
])
463464

464465
for test_property in mandatory_properties:
465466
fg = Podcast()
@@ -474,8 +475,8 @@ def test_mandatoryValues(self):
474475
try:
475476
self.assertRaises(ValueError, fg._create_rss)
476477
except AssertionError as e:
477-
raise AssertionError("The test failed for %s" % test_property)\
478-
from e
478+
raise_from(AssertionError(
479+
"The test failed for %s" % test_property), e)
479480

480481
def test_withholdFromItunesOffByDefault(self):
481482
assert not self.fg.withhold_from_itunes

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PodGen (forked from python-feedgen)
88

99

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

1313
It is licensed under the terms of both, the FreeBSD license and the LGPLv3+.
1414
Choose the one which is more convenient for you. For more details have a look

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
'Natural Language :: English',
2626
'Operating System :: OS Independent',
2727
'Programming Language :: Python',
28-
'Programming Language :: Python :: 3 :: Only',
28+
'Programming Language :: Python :: 2',
29+
'Programming Language :: Python :: 2.7',
30+
'Programming Language :: Python :: 3',
2931
'Programming Language :: Python :: 3.3',
3032
'Programming Language :: Python :: 3.4',
3133
'Programming Language :: Python :: 3.5',

0 commit comments

Comments
 (0)