From 72b2896cf80b786a2db089f469adf9f538226b61 Mon Sep 17 00:00:00 2001 From: wltb Date: Sun, 6 Jul 2014 19:38:34 +0200 Subject: [PATCH] Add encoding argument for output creation functions, change default encoding to unicode --- feedgen/__main__.py | 2 +- feedgen/feed.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/feedgen/__main__.py b/feedgen/__main__.py index 158c66f..967d9fb 100644 --- a/feedgen/__main__.py +++ b/feedgen/__main__.py @@ -62,7 +62,7 @@ if __name__ == '__main__': domesticam, aliam forensem, ut in fronte ostentatio sit, intus veritas occultetur? Cum id fugiunt, re eadem defendunt, quae Peripatetici, verba.''') - fe.summary('Lorem ipsum dolor sit amet, consectetur adipiscing elit...') + fe.summary(u'Lorem ipsum dolor sit amet, consectetur adipiscing elit…') fe.link( href='http://example.com', rel='alternate' ) fe.author( name='Lars Kiesow', email='lkiesow@uos.de' ) diff --git a/feedgen/feed.py b/feedgen/feed.py index 194ec5c..9e3fc4c 100644 --- a/feedgen/feed.py +++ b/feedgen/feed.py @@ -199,7 +199,7 @@ class FeedGenerator(object): return feed, doc - def atom_str(self, pretty=False, extensions=True): + def atom_str(self, pretty=False, extensions=True, encoding="unicode"): '''Generates an ATOM feed and returns the feed XML as string. :param pretty: If the feed should be split into multiple lines and @@ -209,10 +209,10 @@ class FeedGenerator(object): :returns: String representation of the ATOM feed. ''' feed, doc = self._create_atom(extensions=extensions) - return etree.tostring(feed, pretty_print=pretty) + return etree.tostring(feed, pretty_print=pretty, encoding=encoding) - def atom_file(self, filename, extensions=True, pretty=False): + def atom_file(self, filename, extensions=True, pretty=False, encoding="UTF-8"): '''Generates an ATOM feed and write the resulting XML to a file. :param filename: Name of file to write, or a file-like object, or a URL. @@ -220,7 +220,7 @@ class FeedGenerator(object): generation (default: enabled). ''' feed, doc = self._create_atom(extensions=extensions) - doc.write(filename, pretty_print=pretty) + doc.write(filename, pretty_print=pretty, encoding=encoding) def _create_rss(self, extensions=True): @@ -360,7 +360,7 @@ class FeedGenerator(object): return feed, doc - def rss_str(self, pretty=False, extensions=True): + def rss_str(self, pretty=False, extensions=True, encoding="unicode"): '''Generates an RSS feed and returns the feed XML as string. :param pretty: If the feed should be split into multiple lines and @@ -370,10 +370,10 @@ class FeedGenerator(object): :returns: String representation of the RSS feed. ''' feed, doc = self._create_rss(extensions=extensions) - return etree.tostring(feed, pretty_print=pretty) + return etree.tostring(feed, pretty_print=pretty, encoding=encoding) - def rss_file(self, filename, extensions=True, pretty=False): + def rss_file(self, filename, extensions=True, pretty=False, encoding="UTF-8"): '''Generates an RSS feed and write the resulting XML to a file. :param filename: Name of file to write, or a file-like object, or a URL. @@ -381,7 +381,7 @@ class FeedGenerator(object): generation (default: enabled). ''' feed, doc = self._create_rss(extensions=extensions) - doc.write(filename, pretty_print=pretty) + doc.write(filename, pretty_print=pretty, encoding=encoding) def title(self, title=None):