forked from lkiesow/python-feedgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/snipem/python-feedgen int…
…o merge-test
- Loading branch information
Showing
3 changed files
with
55 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,22 +11,30 @@ | |
from feedgen.feed import FeedGenerator | ||
import sys | ||
|
||
def print_enc(string): | ||
version = sys.version_info[0] | ||
|
||
if version == 2: | ||
print(string) | ||
elif version == 3: | ||
sys.stdout.buffer.write(string) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 2 or not ( | ||
sys.argv[1].endswith('rss') \ | ||
or sys.argv[1].endswith('atom') \ | ||
or sys.argv[1].endswith('podcast') ): | ||
print 'Usage: %s ( <file>.atom | atom | <file>.rss | rss | podcast )' % \ | ||
'pythom -m feedgen' | ||
print '' | ||
print ' atom -- Generate ATOM test output and print it to stdout.' | ||
print ' rss -- Generate RSS test output and print it to stdout.' | ||
print ' <file>.atom -- Generate ATOM test feed and write it to file.atom.' | ||
print ' <file>.rss -- Generate RSS test teed and write it to file.rss.' | ||
print ' podcast -- Generator Podcast test output and print it to stdout.' | ||
print '' | ||
print_enc ('Usage: %s ( <file>.atom | atom | <file>.rss | rss | podcast )' % \ | ||
'pythom -m feedgen') | ||
print_enc ('') | ||
print_enc (' atom -- Generate ATOM test output and print it to stdout.') | ||
print_enc (' rss -- Generate RSS test output and print it to stdout.') | ||
print_enc (' <file>.atom -- Generate ATOM test feed and write it to file.atom.') | ||
print_enc (' <file>.rss -- Generate RSS test teed and write it to file.rss.') | ||
print_enc (' podcast -- Generator Podcast test output and print it to stdout.') | ||
print_enc ('') | ||
exit() | ||
|
||
arg = sys.argv[1] | ||
|
@@ -59,9 +67,9 @@ | |
fe.author( name='Lars Kiesow', email='[email protected]' ) | ||
|
||
if arg == 'atom': | ||
print fg.atom_str(pretty=True) | ||
print_enc (fg.atom_str(pretty=True)) | ||
elif arg == 'rss': | ||
print fg.rss_str(pretty=True) | ||
print_enc (fg.rss_str(pretty=True)) | ||
elif arg == 'podcast': | ||
# Load the podcast extension. It will automatically be loaded for all | ||
# entries in the feed, too. Thus also for our “fe”. | ||
|
@@ -76,18 +84,18 @@ | |
'consectetur adipiscing elit. ' + \ | ||
'Verba tu fingas et ea dicas, quae non sentias?') | ||
fe.podcast.itunes_author('Lars Kiesow') | ||
print fg.rss_str(pretty=True) | ||
print_enc (fg.rss_str(pretty=True)) | ||
|
||
elif arg == 'dc.atom': | ||
fg.load_extension('dc') | ||
fg.dc.dc_contributor('Lars Kiesow') | ||
fe.dc.dc_contributor('Lars Kiesow') | ||
print fg.atom_str(pretty=True) | ||
print_enc (fg.atom_str(pretty=True)) | ||
|
||
elif arg == 'dc.rss': | ||
fg.load_extension('dc') | ||
fg.dc.dc_contributor('Lars Kiesow') | ||
print fg.rss_str(pretty=True) | ||
print_enc (fg.rss_str(pretty=True)) | ||
|
||
elif arg.endswith('atom'): | ||
fg.atom_file(arg) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
:copyright: 2013, Lars Kiesow <[email protected]> | ||
:license: FreeBSD and LGPL, see license.* for more details. | ||
''' | ||
|
||
import sys | ||
|
||
|
||
def ensure_format(val, allowed, required, allowed_values=None, defaults=None): | ||
|
@@ -36,13 +36,27 @@ def ensure_format(val, allowed, required, allowed_values=None, defaults=None): | |
if not isinstance(elem, dict): | ||
raise ValueError('Invalid data (value is no dictionary)') | ||
# Set default values | ||
for k,v in defaults.iteritems(): | ||
|
||
version = sys.version_info[0] | ||
|
||
if version == 2: | ||
items = defaults.iteritems() | ||
else: | ||
items = defaults.items() | ||
|
||
for k,v in items: | ||
elem[k] = elem.get(k, v) | ||
if not set(elem.keys()) <= allowed: | ||
raise ValueError('Data contains invalid keys') | ||
if not set(elem.keys()) >= required: | ||
raise ValueError('Data contains not all required keys') | ||
for k,v in allowed_values.iteritems(): | ||
|
||
if version == 2: | ||
values = allowed_values.iteritems() | ||
else: | ||
values = allowed_values.items() | ||
|
||
for k,v in values: | ||
if elem.get(k) and not elem[k] in v: | ||
raise ValueError('Invalid value for %s' % k ) | ||
return val |