Switch from python-slugify to self hosted (Taken from Django 2.2.1 django.utils.text.slugify)

This commit is contained in:
Eriks Karls 2019-07-29 13:52:33 +03:00
parent bb8634fe56
commit 3aa305ea74
3 changed files with 20 additions and 5 deletions

View File

@ -9,7 +9,6 @@ from json import JSONDecodeError, loads, JSONEncoder
from typing import Any, Dict, List, Union from typing import Any, Dict, List, Union
from requests import Response, Session from requests import Response, Session
from slugify import slugify
from erepublik import utils from erepublik import utils
@ -239,7 +238,7 @@ class SlowRequests(Session):
file_data = { file_data = {
"path": 'debug/requests', "path": 'debug/requests',
"time": self.last_time.strftime('%Y-%m-%d_%H-%M-%S'), "time": self.last_time.strftime('%Y-%m-%d_%H-%M-%S'),
"name": slugify(url[len(Citizen.url):]), "name": utils.slugify(url[len(Citizen.url):]),
"extra": "_REDIRECT" if redirect else "" "extra": "_REDIRECT" if redirect else ""
} }

View File

@ -6,6 +6,7 @@ import re
import sys import sys
import time import time
import traceback import traceback
import unicodedata
from collections import deque from collections import deque
from decimal import Decimal from decimal import Decimal
from json import JSONEncoder from json import JSONEncoder
@ -15,7 +16,6 @@ from typing import Union
import pytz import pytz
import requests import requests
from requests import Response from requests import Response
from slugify import slugify
__all__ = ["FOOD_ENERGY", "COMMIT_ID", "COUNTRIES", "erep_tz", __all__ = ["FOOD_ENERGY", "COMMIT_ID", "COUNTRIES", "erep_tz",
@ -317,3 +317,19 @@ def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commi
else: else:
trace = dict() trace = dict()
send_email(name, bugtrace, citizen, local_vars=trace) send_email(name, bugtrace, citizen, local_vars=trace)
def slugify(value, allow_unicode=False):
"""
Function copied from Django2.2.1 django.utils.text.slugify
Convert to ASCII if 'allow_unicode' is False. Convert spaces to hyphens.
Remove characters that aren't alphanumerics, underscores, or hyphens.
Convert to lowercase. Also strip leading and trailing whitespace.
"""
value = str(value)
if allow_unicode:
value = unicodedata.normalize('NFKC', value)
else:
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub(r'[^\w\s-]', '', value).strip().lower()
return re.sub(r'[-\s]+', '-', value)

View File

@ -11,7 +11,7 @@ with open('README.rst') as readme_file:
with open('HISTORY.rst') as history_file: with open('HISTORY.rst') as history_file:
history = history_file.read() history = history_file.read()
requirements = ['pytz==2019.1', 'requests==2.22.0', 'python-slugify<3.0.0'] requirements = ['pytz==2019.1', 'requests==2.22.0']
setup_requirements = [ ] setup_requirements = [ ]
@ -41,6 +41,6 @@ setup(
test_suite='tests', test_suite='tests',
tests_require=test_requirements, tests_require=test_requirements,
url='https://github.com/eeriks/erepublik_script', url='https://github.com/eeriks/erepublik_script',
version='0.14.5.1', version='0.14.5',
zip_safe=False, zip_safe=False,
) )