From 966fea46ba4954f5511266e630697c4f06fb1221 Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Thu, 21 Dec 2023 21:29:04 +0100 Subject: [PATCH] Fix flake8 complaints This pull request fixes a number of complaints the current version of flake8 has about the code. --- feedgen/__main__.py | 10 ++++----- feedgen/entry.py | 50 +++++++++++++++++++++--------------------- feedgen/ext/base.py | 3 ++- feedgen/ext/podcast.py | 4 ++-- feedgen/feed.py | 24 ++++++++++---------- feedgen/util.py | 6 ++--- tests/test_main.py | 4 ++-- 7 files changed, 51 insertions(+), 50 deletions(-) diff --git a/feedgen/__main__.py b/feedgen/__main__.py index abc0737..9f008b3 100644 --- a/feedgen/__main__.py +++ b/feedgen/__main__.py @@ -36,8 +36,8 @@ def print_enc(s): - '''Print function compatible with both python2 and python3 accepting strings - and byte arrays. + '''Print function compatible with both python2 and python3 accepting + strings and byte arrays. ''' if sys.version_info[0] >= 3: print(s.decode('utf-8') if isinstance(s, bytes) else s) @@ -73,9 +73,9 @@ def main(): fe = fg.add_entry() fe.id('http://lernfunk.de/_MEDIAID_123#1') fe.title('First Element') - fe.content('''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Tamen - aberramus a proposito, et, ne longius, prorsus, inquam, Piso, si - ista mala sunt, placet. Aut etiam, ut vestitum, sic sententiam + fe.content('''Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Tamen aberramus a proposito, et, ne longius, prorsus, inquam, Piso, + si ista mala sunt, placet. Aut etiam, ut vestitum, sic sententiam habeas aliam domesticam, aliam forensem, ut in fronte ostentatio sit, intus veritas occultetur? Cum id fugiunt, re eadem defendunt, quae Peripatetici, verba.''') diff --git a/feedgen/entry.py b/feedgen/entry.py index 66400ba..71d295a 100644 --- a/feedgen/entry.py +++ b/feedgen/entry.py @@ -58,8 +58,8 @@ def _add_text_elm(entry, data, name): class FeedEntry(object): - '''FeedEntry call representing an ATOM feeds entry node or an RSS feeds item - node. + '''FeedEntry call representing an ATOM feeds entry node or an RSS feeds + item node. ''' def __init__(self): @@ -115,8 +115,8 @@ def atom_entry(self, extensions=True): # element. if not self.__atom_content: links = self.__atom_link or [] - if not [l for l in links if l.get('rel') == 'alternate']: - raise ValueError('Entry must contain an alternate link or ' + + if not [link for link in links if link.get('rel') == 'alternate']: + raise ValueError('Entry must contain an alternate link or ' 'a content element.') # Add author elements @@ -136,18 +136,18 @@ def atom_entry(self, extensions=True): _add_text_elm(entry, self.__atom_content, 'content') - for l in self.__atom_link or []: - link = xml_elem('link', entry, href=l['href']) - if l.get('rel'): - link.attrib['rel'] = l['rel'] - if l.get('type'): - link.attrib['type'] = l['type'] - if l.get('hreflang'): - link.attrib['hreflang'] = l['hreflang'] - if l.get('title'): - link.attrib['title'] = l['title'] - if l.get('length'): - link.attrib['length'] = l['length'] + for link in self.__atom_link or []: + link = xml_elem('link', entry, href=link['href']) + if link.get('rel'): + link.attrib['rel'] = link['rel'] + if link.get('type'): + link.attrib['type'] = link['type'] + if link.get('hreflang'): + link.attrib['hreflang'] = link['hreflang'] + if link.get('title'): + link.attrib['title'] = link['title'] + if link.get('length'): + link.attrib['length'] = link['length'] _add_text_elm(entry, self.__atom_summary, 'summary') @@ -449,13 +449,13 @@ def link(self, link=None, replace=False, **kwargs): {'rel': ['alternate', 'enclosure', 'related', 'self', 'via']}, {'rel': 'alternate'}) # RSS only needs one URL. We use the first link for RSS: - for l in self.__atom_link: - if l.get('rel') == 'alternate': - self.__rss_link = l['href'] - elif l.get('rel') == 'enclosure': - self.__rss_enclosure = {'url': l['href']} - self.__rss_enclosure['type'] = l.get('type') - self.__rss_enclosure['length'] = l.get('length') or '0' + for link in self.__atom_link: + if link.get('rel') == 'alternate': + self.__rss_link = link['href'] + elif link.get('rel') == 'enclosure': + self.__rss_enclosure = {'url': link['href']} + self.__rss_enclosure['type'] = link.get('type') + self.__rss_enclosure['length'] = link.get('length') or '0' # return the set with more information (atom) return self.__atom_link @@ -574,8 +574,8 @@ def contributor(self, contributor=None, replace=False, **kwargs): return self.__atom_contributor def published(self, published=None): - '''Set or get the published value which contains the time of the initial - creation or first availability of the entry. + '''Set or get the published value which contains the time of the + initial creation or first availability of the entry. The value can either be a string which will automatically be parsed or a datetime.datetime object. In any case it is necessary that the value diff --git a/feedgen/ext/base.py b/feedgen/ext/base.py index 521139e..b94826d 100644 --- a/feedgen/ext/base.py +++ b/feedgen/ext/base.py @@ -21,7 +21,8 @@ def extend_ns(self): return dict() def extend_rss(self, feed): - '''Extend a RSS feed xml structure containing all previously set fields. + '''Extend a RSS feed xml structure containing all previously set + fields. :param feed: The feed xml root element. :returns: The feed root element. diff --git a/feedgen/ext/podcast.py b/feedgen/ext/podcast.py index 4c7eb0b..e0d7d05 100644 --- a/feedgen/ext/podcast.py +++ b/feedgen/ext/podcast.py @@ -292,8 +292,8 @@ def itunes_owner(self, name=None, email=None): return self.__itunes_owner def itunes_subtitle(self, itunes_subtitle=None): - '''Get or set the itunes:subtitle value for the podcast. The contents of - this tag are shown in the Description column in iTunes. The subtitle + '''Get or set the itunes:subtitle value for the podcast. The contents + of this tag are shown in the Description column in iTunes. The subtitle displays best if it is only a few words long. :param itunes_subtitle: Subtitle of the podcast. diff --git a/feedgen/feed.py b/feedgen/feed.py index 9ebd219..33e0c3f 100644 --- a/feedgen/feed.py +++ b/feedgen/feed.py @@ -130,18 +130,18 @@ def _create_atom(self, extensions=True): uri = xml_elem('uri', author) uri.text = a.get('uri') - for l in self.__atom_link or []: - link = xml_elem('link', feed, href=l['href']) - if l.get('rel'): - link.attrib['rel'] = l['rel'] - if l.get('type'): - link.attrib['type'] = l['type'] - if l.get('hreflang'): - link.attrib['hreflang'] = l['hreflang'] - if l.get('title'): - link.attrib['title'] = l['title'] - if l.get('length'): - link.attrib['length'] = l['length'] + for ln in self.__atom_link or []: + link = xml_elem('link', feed, href=ln['href']) + if ln.get('rel'): + link.attrib['rel'] = ln['rel'] + if ln.get('type'): + link.attrib['type'] = ln['type'] + if ln.get('hreflang'): + link.attrib['hreflang'] = ln['hreflang'] + if ln.get('title'): + link.attrib['title'] = ln['title'] + if ln.get('length'): + link.attrib['length'] = ln['length'] for c in self.__atom_category or []: cat = xml_elem('category', feed, term=c['term']) diff --git a/feedgen/util.py b/feedgen/util.py index 8b4e6e5..e8125e8 100644 --- a/feedgen/util.py +++ b/feedgen/util.py @@ -35,9 +35,9 @@ def xml_elem(name, parent=None, **kwargs): def ensure_format(val, allowed, required, allowed_values=None, defaults=None): - '''Takes a dictionary or a list of dictionaries and check if all keys are in - the set of allowed keys, if all required keys are present and if the values - of a specific key are ok. + '''Takes a dictionary or a list of dictionaries and check if all keys are + in the set of allowed keys, if all required keys are present and if the + values of a specific key are ok. :param val: Dictionaries to check. :param allowed: Set of allowed keys. diff --git a/tests/test_main.py b/tests/test_main.py index efea777..af0b19e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -22,8 +22,8 @@ def test_usage(self): assert e.code is None def test_feed(self): - for ftype in 'rss', 'atom', 'podcast', 'torrent', 'dc.rss', 'dc.atom',\ - 'syndication.rss', 'syndication.atom': + for ftype in 'rss', 'atom', 'podcast', 'torrent', 'dc.rss', \ + 'dc.atom', 'syndication.rss', 'syndication.atom': sys.argv = ['feedgen', ftype] try: __main__.main()