Merge pull request #2127 from ingwinlu/fix_py36_warnings

Fix warnings originating from bad regexes
This commit is contained in:
Justin Mayer 2017-03-27 13:04:26 -07:00 committed by GitHub
commit cfcf40f1f8
6 changed files with 11 additions and 11 deletions

View file

@ -712,7 +712,7 @@ Metadata
The default metadata you want to use for all articles and pages. The default metadata you want to use for all articles and pages.
.. data:: FILENAME_METADATA = '(?P<date>\d{4}-\d{2}-\d{2}).*' .. data:: FILENAME_METADATA = r'(?P<date>\d{4}-\d{2}-\d{2}).*'
The regexp that will be used to extract any metadata from the filename. All The regexp that will be used to extract any metadata from the filename. All
named groups that are matched will be set in the metadata object. The named groups that are matched will be set in the metadata object. The
@ -720,7 +720,7 @@ Metadata
For example, to extract both the date and the slug:: For example, to extract both the date and the slug::
FILENAME_METADATA = '(?P<date>\d{4}-\d{2}-\d{2})_(?P<slug>.*)' FILENAME_METADATA = r'(?P<date>\d{4}-\d{2}-\d{2})_(?P<slug>.*)'
See also ``SLUGIFY_SOURCE``. See also ``SLUGIFY_SOURCE``.

View file

@ -111,10 +111,10 @@ class Pelican(object):
structure = self.settings['ARTICLE_PERMALINK_STRUCTURE'] structure = self.settings['ARTICLE_PERMALINK_STRUCTURE']
# Convert %(variable) into {variable}. # Convert %(variable) into {variable}.
structure = re.sub('%\((\w+)\)s', '{\g<1>}', structure) structure = re.sub(r'%\((\w+)\)s', '{\g<1>}', structure)
# Convert %x into {date:%x} for strftime # Convert %x into {date:%x} for strftime
structure = re.sub('(%[A-z])', '{date:\g<1>}', structure) structure = re.sub(r'(%[A-z])', '{date:\g<1>}', structure)
# Strip a / prefix # Strip a / prefix
structure = re.sub('^/', '', structure) structure = re.sub('^/', '', structure)

View file

@ -650,9 +650,9 @@ def parse_path_metadata(source_path, settings=None, process=None):
... settings=settings, ... settings=settings,
... process=reader.process_metadata) ... process=reader.process_metadata)
>>> pprint.pprint(metadata) # doctest: +ELLIPSIS >>> pprint.pprint(metadata) # doctest: +ELLIPSIS
{'category': <pelican.urlwrappers.Category object at ...>, ... {'category': <pelican.urlwrappers.Category object at ...>,
'date': SafeDatetime(2013, 1, 1, 0, 0), ... 'date': SafeDatetime(2013, 1, 1, 0, 0),
'slug': 'my-slug'} ... 'slug': 'my-slug'}
""" """
metadata = {} metadata = {}
dirname, basename = os.path.split(source_path) dirname, basename = os.path.split(source_path)

View file

@ -75,7 +75,7 @@ directives.register_directive('code-block', Pygments)
directives.register_directive('sourcecode', Pygments) directives.register_directive('sourcecode', Pygments)
_abbr_re = re.compile('\((.*)\)$', re.DOTALL) _abbr_re = re.compile(r'\((.*)\)$', re.DOTALL)
class abbreviation(nodes.Inline, nodes.TextElement): class abbreviation(nodes.Inline, nodes.TextElement):

View file

@ -121,7 +121,7 @@ DEFAULT_CONFIG = {
'DEFAULT_PAGINATION': False, 'DEFAULT_PAGINATION': False,
'DEFAULT_ORPHANS': 0, 'DEFAULT_ORPHANS': 0,
'DEFAULT_METADATA': {}, 'DEFAULT_METADATA': {},
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2}).*', 'FILENAME_METADATA': r'(?P<date>\d{4}-\d{2}-\d{2}).*',
'PATH_METADATA': '', 'PATH_METADATA': '',
'EXTRA_PATH_METADATA': {}, 'EXTRA_PATH_METADATA': {},
'DEFAULT_STATUS': 'published', 'DEFAULT_STATUS': 'published',

View file

@ -305,8 +305,8 @@ def slugify(value, substitutions=()):
replace = replace and not skip replace = replace and not skip
if replace: if replace:
value = re.sub('[^\w\s-]', '', value).strip() value = re.sub(r'[^\w\s-]', '', value).strip()
value = re.sub('[-\s]+', '-', value) value = re.sub(r'[-\s]+', '-', value)
else: else:
value = value.strip() value = value.strip()