Fixed #26, Fixed Localized Time Formatting Issues
Signed-off-by: Lars Kiesow <lkiesow@uos.de>
This commit is contained in:
parent
303c047697
commit
9819fd98b3
3 changed files with 17 additions and 9 deletions
|
@ -12,7 +12,7 @@ from lxml import etree
|
||||||
from datetime import datetime
|
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, formatRFC2822
|
||||||
from feedgen.compat import string_types
|
from feedgen.compat import string_types
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,8 +220,7 @@ class FeedEntry(object):
|
||||||
enclosure.attrib['type'] = self.__rss_enclosure['type']
|
enclosure.attrib['type'] = self.__rss_enclosure['type']
|
||||||
if self.__rss_pubDate:
|
if self.__rss_pubDate:
|
||||||
pubDate = etree.SubElement(entry, 'pubDate')
|
pubDate = etree.SubElement(entry, 'pubDate')
|
||||||
pubDate.text = self.__rss_pubDate.strftime(
|
pubDate.text = formatRFC2822(self.__rss_pubDate)
|
||||||
'%a, %d %b %Y %H:%M:%S %z')
|
|
||||||
|
|
||||||
if extensions:
|
if extensions:
|
||||||
for ext in self.__extensions.values() or []:
|
for ext in self.__extensions.values() or []:
|
||||||
|
|
|
@ -14,7 +14,7 @@ from datetime import datetime
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
import dateutil.tz
|
import dateutil.tz
|
||||||
from feedgen.entry import FeedEntry
|
from feedgen.entry import FeedEntry
|
||||||
from feedgen.util import ensure_format
|
from feedgen.util import ensure_format, formatRFC2822
|
||||||
import feedgen.version
|
import feedgen.version
|
||||||
import sys
|
import sys
|
||||||
from feedgen.compat import string_types
|
from feedgen.compat import string_types
|
||||||
|
@ -313,15 +313,14 @@ class FeedGenerator(object):
|
||||||
language.text = self.__rss_language
|
language.text = self.__rss_language
|
||||||
if self.__rss_lastBuildDate:
|
if self.__rss_lastBuildDate:
|
||||||
lastBuildDate = etree.SubElement(channel, 'lastBuildDate')
|
lastBuildDate = etree.SubElement(channel, 'lastBuildDate')
|
||||||
lastBuildDate.text = self.__rss_lastBuildDate.strftime(
|
|
||||||
'%a, %d %b %Y %H:%M:%S %z')
|
lastBuildDate.text = formatRFC2822(self.__rss_lastBuildDate)
|
||||||
if self.__rss_managingEditor:
|
if self.__rss_managingEditor:
|
||||||
managingEditor = etree.SubElement(channel, 'managingEditor')
|
managingEditor = etree.SubElement(channel, 'managingEditor')
|
||||||
managingEditor.text = self.__rss_managingEditor
|
managingEditor.text = self.__rss_managingEditor
|
||||||
if self.__rss_pubDate:
|
if self.__rss_pubDate:
|
||||||
pubDate = etree.SubElement(channel, 'pubDate')
|
pubDate = etree.SubElement(channel, 'pubDate')
|
||||||
pubDate.text = self.__rss_pubDate.strftime(
|
pubDate.text = formatRFC2822(self.__rss_pubDate)
|
||||||
'%a, %d %b %Y %H:%M:%S %z')
|
|
||||||
if self.__rss_rating:
|
if self.__rss_rating:
|
||||||
rating = etree.SubElement(channel, 'rating')
|
rating = etree.SubElement(channel, 'rating')
|
||||||
rating.text = self.__rss_rating
|
rating.text = self.__rss_rating
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
:copyright: 2013, Lars Kiesow <lkiesow@uos.de>
|
:copyright: 2013, Lars Kiesow <lkiesow@uos.de>
|
||||||
:license: FreeBSD and LGPL, see license.* for more details.
|
:license: FreeBSD and LGPL, see license.* for more details.
|
||||||
'''
|
'''
|
||||||
import sys
|
import sys, locale
|
||||||
|
|
||||||
|
|
||||||
def ensure_format(val, allowed, required, allowed_values=None, defaults=None):
|
def ensure_format(val, allowed, required, allowed_values=None, defaults=None):
|
||||||
|
@ -60,3 +60,13 @@ def ensure_format(val, allowed, required, allowed_values=None, defaults=None):
|
||||||
if elem.get(k) and not elem[k] in v:
|
if elem.get(k) and not elem[k] in v:
|
||||||
raise ValueError('Invalid value for %s' % k )
|
raise ValueError('Invalid value for %s' % k )
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
def formatRFC2822(d):
|
||||||
|
'''Make sure the locale setting do not interfere with the time format.
|
||||||
|
'''
|
||||||
|
l = locale.setlocale(locale.LC_ALL)
|
||||||
|
locale.setlocale(locale.LC_ALL, 'C')
|
||||||
|
d = d.strftime('%a, %d %b %Y %H:%M:%S %z')
|
||||||
|
locale.setlocale(locale.LC_ALL, l)
|
||||||
|
return d
|
||||||
|
|
Loading…
Reference in a new issue