Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def rfc3339_date(date):
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
if not six.PY3: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
if is_aware(date):
offset = date.tzinfo.utcoffset(date)
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d:%02d' % (hour, minute)
else:
return time_str + 'Z'
def rfc2822_date(date):
# We can't use strftime() because it produces locale-dependent results, so
# we have to map english month and day names manually
months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',)
days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
# We do this ourselves to be timezone aware, email.Utils is not tz aware.
dow = days[date.weekday()]
month = months[date.month - 1]
time_str = date.strftime('%s, %%d %s %%Y %%H:%%M:%%S ' % (dow, month))
if not six.PY3: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
if is_aware(date):
offset = date.tzinfo.utcoffset(date)
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d%02d' % (hour, minute)
else:
return time_str + '-0000'
def rfc2822_date(date):
# We can't use strftime() because it produces locale-dependent results, so
# we have to map english month and day names manually
months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',)
days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
# We do this ourselves to be timezone aware, email.Utils is not tz aware.
dow = days[date.weekday()]
month = months[date.month - 1]
time_str = date.strftime('%s, %%d %s %%Y %%H:%%M:%%S ' % (dow, month))
if not six.PY3: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
if is_aware(date):
offset = date.tzinfo.utcoffset(date)
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d%02d' % (hour, minute)
else:
return time_str + '-0000'
def rfc3339_date(date):
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
if not six.PY3: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
if is_aware(date):
offset = date.tzinfo.utcoffset(date)
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d:%02d' % (hour, minute)
else:
return time_str + 'Z'
def rfc2822_date(date):
# We can't use strftime() because it produces locale-dependent results, so
# we have to map english month and day names manually
months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',)
days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
# We do this ourselves to be timezone aware, email.Utils is not tz aware.
dow = days[date.weekday()]
month = months[date.month - 1]
time_str = date.strftime('%s, %%d %s %%Y %%H:%%M:%%S ' % (dow, month))
if not six.PY3: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
if is_aware(date):
offset = date.tzinfo.utcoffset(date)
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d%02d' % (hour, minute)
else:
return time_str + '-0000'
def rfc3339_date(date):
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
if not six.PY3: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
if is_aware(date):
offset = date.tzinfo.utcoffset(date)
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d:%02d' % (hour, minute)
else:
return time_str + 'Z'
def test_write_item_in_cuf_feed(self):
outfile = StringIO()
handler = feedgenerator.SimplerXMLGenerator(outfile, 'utf-8')
handler.startDocument()
contents = ''
item = {u'description': u'test', u'pubdate': None,
u'author_link': None, u'author_name': None,
u'link': 'http://127.0.0.1/test/some_uuid',
u'ttl': None, u'enclosure': None, u'categories': [u'test'],
u'item_copyright': None, u'title': u'test',
u'author_email': None, u'comments': None,
'contents': contents,
u'unique_id': None}
cuf_paged_feed = CufPagedFeed(title='test',
link='http://127.0.0.1/test/some_uuid',
feed_url='http://127.0.0.1/test/some_uuid',
description='test',
def generate_feed(gallery, medias, feed_type=None, feed_url='', nb_items=0):
root_album = gallery.albums['.']
cls = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed
feed = cls(
title=Markup.escape(root_album.title),
link='/',
feed_url=feed_url,
description=Markup.escape(root_album.description).striptags()
)
theme = gallery.settings['theme']
nb_medias = len(medias)
nb_items = min(nb_items, nb_medias) if nb_items > 0 else nb_medias
base_url = feed_url.rsplit('/', maxsplit=1)[0]
for item in medias[:nb_items]:
if theme == 'galleria':
link = '%s/%s/#%s' % (base_url, item.path, item.url)
else:
if '/' in repository_or_username:
username, repository = repository_or_username.split('/', 1)
repositories = [repository]
else:
username = repository_or_username
repositories = [rep.name for rep in gh.repos.list(username)]
for repository in repositories:
full_repname = username + '/' + repository
log.info('Processing %s' % full_repname)
# first, we need to get the date of the last commit
commits = gh.commits.list(full_repname, 'master')
last_commit_date = commits[0].committed_date
feed = feedgenerator.Atom1Feed(
title=u'%s forks' % full_repname,
link=u'http://github.com/%s' % full_repname,
description=u'Commits from forks of %s repository at GitHub.' % full_repname,
language=u'en',
)
for fork in gh.repos.network(full_repname):
fork_repname = '%(owner)s/%(name)s' % fork
log.info('Fetching commits from %s' % fork_repname)
fork_commits = gh.commits.list(fork_repname, 'master')
for commit in reversed(fork_commits):
if commit.committed_date > last_commit_date:
short_commit_message = commit.message.split('\n', 1)[0]
log.debug('%s %s %s', fork_repname, commit.committed_date, short_commit_message)
def atom(tag=None):
"""General purpose atom feed."""
title = current_app.config['TITLE']
if tag is not None:
tags = tag.split('/')
for _tag in tags:
if _tag not in current_app.blohg.content.tags:
abort(404)
title += ' » %s' % ' + '.join(tags)
posts = current_app.blohg.content.get_by_tag(tags)
else:
posts = current_app.blohg.content.get_all(True)
feed = feedgenerator.Atom1Feed(title=title,
link=url_for('views.home', _external=True),
description=current_app.config['TAGLINE'],
feed_guid=url_for('views.atom', tag=tag),
feed_url=url_for('views.atom', tag=tag,
_external=True),
author_name=current_app.config['AUTHOR'])
posts_per_atom_feed = \
current_app.config.get('POSTS_PER_ATOM_FEED',
current_app.config.get('POSTS_PER_PAGE'))
for post in posts[:int(posts_per_atom_feed)]:
feed.add_item(title=post.title, content=post.full_raw_html,
description=post.abstract_raw_html,
unique_id=url_for('views.content', slug=post.slug),
link=url_for('views.content', slug=post.slug,
_external=True),
author_name=post.author_name,