Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Drop bleach from requirements

Patryk Zawadzkia0fa5498052d
diff --git a/poetry.lock b/poetry.lock
index ce07977b8d..95b634938e 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -164,18 +164,6 @@ typed-ast = ">=1.4.0"
[package.extras]
d = ["aiohttp (>=3.3.2)", "aiohttp-cors"]
-[[package]]
-category = "main"
-description = "An easy safelist-based HTML-sanitizing tool."
-name = "bleach"
-optional = false
-python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "2.1.4"
-
-[package.dependencies]
-html5lib = ">=0.99999999pre,<1.0b1 || >1.0b1,<1.0b2 || >1.0b2,<1.0b3 || >1.0b3,<1.0b4 || >1.0b4,<1.0b5 || >1.0b5,<1.0b6 || >1.0b6,<1.0b7 || >1.0b7,<1.0b8 || >1.0b8"
-six = "*"
-
[[package]]
category = "main"
description = "The AWS SDK for Python"
@@ -2250,7 +2238,7 @@ idna = ">=2.0"
multidict = ">=4.0"
[metadata]
-content-hash = "884b42bafa5b9a53e62d75ec70c0d7f6fd234578891d94c40dac54f3b9b81581"
+content-hash = "fa1b17ea41f9d339469ca6576d69ddf6f9838f8da831338ee0c64b9f57602bb2"
python-versions = "~3.8"
[metadata.files]
@@ -2314,10 +2302,6 @@ black = [
{file = "black-19.10b0-py36-none-any.whl", hash = "sha256:1b30e59be925fafc1ee4565e5e08abef6b03fe455102883820fe5ee2e4734e0b"},
{file = "black-19.10b0.tar.gz", hash = "sha256:c2edb73a08e9e0e6f65a0e6af18b059b8b1cdd5bef997d7a0b181df93dc81539"},
]
-bleach = [
- {file = "bleach-2.1.4-py2.py3-none-any.whl", hash = "sha256:24754b9a7d530bf30ce7cbc805bc6cce785660b4a10ff3a43633728438c105ab"},
- {file = "bleach-2.1.4.tar.gz", hash = "sha256:0ee95f6167129859c5dce9b1ca291ebdb5d8cd7e382ca0e237dfd0dad63f63d8"},
-]
boto3 = [
{file = "boto3-1.12.3-py2.py3-none-any.whl", hash = "sha256:4df9e5bca38488d55f6ead4bd02702c83bf56e11c4dfde7a759c2398f2cadff6"},
{file = "boto3-1.12.3.tar.gz", hash = "sha256:c222c1d9301cefb1af7f7a946c48d7c66f404865f9f1951c8540499b5ce71d43"},
diff --git a/pyproject.toml b/pyproject.toml
index 8f29d515f6..5df26601db 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -14,7 +14,6 @@ documentation = "https://docs.getsaleor.com/en/latest/"
[tool.poetry.dependencies]
python = "~3.8"
babel = "~2.7"
-bleach = "~2"
boto3 = "^1.9"
braintree = "~3.49.0"
celery = { version = "^4.3.0", extras = ["redis"] }
diff --git a/requirements.txt b/requirements.txt
index fb763c4d01..8961b25ca9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,7 +5,6 @@ autopep8==1.5
babel==2.7.0
beautifulsoup4==4.7.1
billiard==3.6.3.0
-bleach==2.1.4
boto3==1.12.3
botocore==1.15.3
braintree==3.49.0
diff --git a/requirements_dev.txt b/requirements_dev.txt
index b46ba45bab..0c55498cf2 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -13,7 +13,6 @@ beautifulsoup4==4.7.1
beautifultable==0.7.0
billiard==3.6.3.0
black==19.10b0
-bleach==2.1.4
boto3==1.12.3
botocore==1.15.3
braintree==3.49.0
diff --git a/saleor/product/migrations/0053_product_seo_description.py b/saleor/product/migrations/0053_product_seo_description.py
index 464db840d4..363820731c 100644
--- a/saleor/product/migrations/0053_product_seo_description.py
+++ b/saleor/product/migrations/0053_product_seo_description.py
@@ -1,85 +1,6 @@
# Generated by Django 2.0.2 on 2018-03-11 18:54
-import html
-
-import bleach
from django.core.validators import MaxLengthValidator
from django.db import migrations, models
-from django.template.defaultfilters import truncatechars
-from html5lib.serializer import HTMLSerializer
-
-
-def get_cleaner(**serializer_kwargs: bool):
- """Build a bleach cleaner from the passed parameters.
-
- :param serializer_kwargs:
- options:
- - alphabetical_attributes
- - escape_lt_in_attrs
- - escape_rcdata
- - inject_meta_charset
- - minimize_boolean_attributes
- - omit_optional_tags
- - quote_attr_values
- - quote_char
- - resolve_entities
- - sanitize
- - space_before_trailing_solidus
- - strip_whitespace
- - use_best_quote_char
- - use_trailing_solidus
- :type serializer_kwargs: Dict[str, bool]
-
- :rtype: bleach.Cleaner
- """
- cleaner = bleach.Cleaner([], strip=True)
- for k, v in serializer_kwargs.items():
- if k not in HTMLSerializer.options:
- raise ValueError(
- "Parameter %s is not a valid option for HTMLSerializer" % k
- )
- setattr(cleaner.serializer, k, v)
- return cleaner
-
-
-def strip_html(text: str, **serializer_kwargs: bool):
- """Remove (strip) HTML tags from text.
-
- Can also take additional parameters
- to be passed to the serializer (see `get_cleaner`).
-
- :param text:
- :type text: str
- :param serializer_kwargs:
- :type serializer_kwargs: Dict[str, bool]
- :rtype: str
- """
- cleaner = get_cleaner(**serializer_kwargs)
- text = cleaner.clean(text)
- return text
-
-
-def strip_html_and_truncate(html_text: str, max_length: int):
- """Strip HTML tags and whitespaces from the text, then trim the description."""
- text = strip_html(html_text, strip_whitespace=True)
- text = truncatechars(text, max_length)
- return text
-
-
-def to_seo_friendly(text):
- # saleor descriptions are stored as escaped HTML,
- # we need to decode them before processing them
- text = html.unescape(text)
-
- # cleanup the description and make it seo friendly
- return strip_html_and_truncate(text, 300)
-
-
-def assign_seo_descriptions(apps, schema_editor):
- Product = apps.get_model("product", "Product")
- for product in Product.objects.all():
- if product.seo_description is None:
- product.seo_description = to_seo_friendly(product.description)
- product.save()
class Migration(migrations.Migration):
@@ -98,5 +19,4 @@ class Migration(migrations.Migration):
),
preserve_default=False,
),
- migrations.RunPython(assign_seo_descriptions),
]