-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
220 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.0.5' | ||
__version__ = '1.0.0-beta' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import re | ||
|
||
re_content = re.compile(r'(post|blog)s?|docs|support/|/(\d{4}|pages?)/\d+/') | ||
|
||
def check_ext(path, exts): | ||
""" | ||
checks if a url has an extension and if it's in the given list | ||
""" | ||
if '.' not in path.split('/')[-1]: | ||
return False, False | ||
return True, path.lower().endswith(tuple(exts)) | ||
|
||
def has_ext(path, params, meta): | ||
""" | ||
returns True if url has no extension e.g. example.com/about-us/team | ||
""" | ||
has_ext, _ = check_ext(path, []) | ||
return has_ext | ||
|
||
def no_ext(path, params, meta): | ||
""" | ||
returns True if url has no extension e.g. example.com/about-us/team | ||
""" | ||
has_ext, _ = check_ext(path, []) | ||
return not has_ext | ||
|
||
def has_params(path, params, meta): | ||
""" | ||
returns True if url has parameters | ||
""" | ||
return len(params) > 0 | ||
|
||
def no_params(path, params, meta): | ||
""" | ||
returns True if url has no parameters | ||
""" | ||
return len(params) == 0 | ||
|
||
def whitelisted(path, params, meta): | ||
""" | ||
returns True if url has no extension or has a whitelisted extension | ||
""" | ||
has_ext, is_ext = check_ext(path, meta['ext_list']) | ||
return is_ext or (not meta['strict'] and not has_ext) | ||
|
||
def blacklisted(path, params, meta): | ||
""" | ||
returns True if url has no extension or doesn't have a blacklisted extension | ||
""" | ||
has_ext, is_ext = check_ext(path, meta['ext_list']) | ||
return not is_ext or (not meta['strict'] and not has_ext) | ||
|
||
def remove_content(path, params, meta): | ||
""" | ||
checks if a path is likely to contain | ||
human written content e.g. a blog | ||
returns False if it is | ||
""" | ||
for part in path.split('/'): | ||
if part.count('-') > 3: | ||
return False | ||
return False if re_content.search(path) else True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
def clean_nargs(args): | ||
""" | ||
cleans nargs to prevent user errors | ||
""" | ||
if not args: | ||
return [] | ||
new_args = [] | ||
if len(args) == 1: | ||
if "," in args[0]: | ||
new_args = [arg.lower() for arg in args[0].strip().split(',')] | ||
elif " " in args[0]: | ||
new_args = [arg.lower() for arg in args[0].split(' ')] | ||
else: | ||
new_args.append(args[0].lower()) | ||
else: | ||
for arg in args: | ||
cleaner = clean_nargs([arg]) | ||
if cleaner: | ||
new_args.extend(cleaner) | ||
else: | ||
new_args.append(arg) | ||
return list(set(filter(None, new_args))) | ||
|
||
def params_to_dict(params): | ||
""" | ||
converts query string to dict | ||
""" | ||
the_dict = {} | ||
if params: | ||
for pair in params.split('&'): | ||
parts = pair.split('=') | ||
try: | ||
the_dict[parts[0]] = parts[1] | ||
except IndexError: | ||
pass | ||
return the_dict | ||
|
||
|
||
def dict_to_params(params): | ||
""" | ||
converts dict of params to query string | ||
""" | ||
stringed = [name + '=' + value for name, value in params.items()] | ||
return '?' + '&'.join(stringed) | ||
|
||
|
||
def compare_params(og_params, new_params): | ||
""" | ||
checks if new_params contain a param | ||
that doesn't exist in og_params | ||
""" | ||
og_set = set([]) | ||
for each in og_params: | ||
for key in each.keys(): | ||
og_set.add(key) | ||
return set(new_params.keys()) - og_set |