Skip to content

Commit

Permalink
Merge pull request #81 from piatrashkakanstantinass/style
Browse files Browse the repository at this point in the history
Black and isort stuff
  • Loading branch information
bee-san authored Jun 18, 2021
2 parents 81ae185 + 2ac916c commit c6527a1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import nox
from nox.sessions import Session


package = "hypermodern_python"
nox.options.sessions = "lint", "tests"
locations = "src", "tests", "noxfile.py", "docs/conf.py"
Expand Down
3 changes: 2 additions & 1 deletion pywhat/distribution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional

from pywhat.helper import AvailableTags, CaseInsensitiveSet, InvalidTag, load_regexes
from pywhat.helper import (AvailableTags, CaseInsensitiveSet, InvalidTag,
load_regexes)


class Distribution:
Expand Down
6 changes: 3 additions & 3 deletions scripts/get_file_sigs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import wikitextparser as wtp
import requests
import json
import re
import json

import requests
import wikitextparser as wtp


def cleanhtml(raw_html):
Expand Down
9 changes: 5 additions & 4 deletions scripts/get_tlds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re

import requests

tlds = requests.get("https://data.iana.org/TLD/tlds-alpha-by-domain.txt")
Expand All @@ -11,11 +12,11 @@
database = re.sub(
# what you want to replace
r'("Name": "Uniform Resource Locator \(URL\)",\s*"Regex": ")[^"]+(")',

# what you want to replace it with - need to be double slashes
r"\1(?i)^(?:(?:https?|ftp):\/\/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?::[0-9]{1,5})?)([a-z0-9-_\/]?\\\\.?)*$|^(?:(?:https?|ftp):\/\/)?(?:\\\\S+:\\\\S+@)?(?:[a-z0-9-_]?\\\\.?)+?(?:[a-z0-9-_][a-z0-9-_]{0,62})\\\\.(?:" + final_string + r")(?::\\\\d{2,5})?(?:[\/?#]\\\\S*)?$\2",

database
r"\1(?i)^(?:(?:https?|ftp):\/\/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?::[0-9]{1,5})?)([a-z0-9-_\/]?\\\\.?)*$|^(?:(?:https?|ftp):\/\/)?(?:\\\\S+:\\\\S+@)?(?:[a-z0-9-_]?\\\\.?)+?(?:[a-z0-9-_][a-z0-9-_]{0,62})\\\\.(?:"
+ final_string
+ r")(?::\\\\d{2,5})?(?:[\/?#]\\\\S*)?$\2",
database,
)

with open("pywhat/Data/regex.json", "w") as file:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_distribution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from pywhat import pywhat_tags, Distribution

from pywhat import Distribution, pywhat_tags
from pywhat.helper import CaseInsensitiveSet, InvalidTag, load_regexes


Expand Down
8 changes: 6 additions & 2 deletions tests/test_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def test_identifier_filtration2():
filter1 = {"ExcludeTags": ["Identifiers"]}
filter2 = {"Tags": ["Identifiers"], "MinRarity": 0.6}
r = identifier.Identifier(dist=Distribution(filter1))
regexes = r.identify("fixtures/file", only_text=False, dist=Distribution(filter2))["Regexes"]["file"]
regexes = r.identify("fixtures/file", only_text=False, dist=Distribution(filter2))[
"Regexes"
]["file"]
for regex in regexes:
assert "Identifiers" in regex["Regex Pattern"]["Tags"]
assert regex["Regex Pattern"]["Rarity"] >= 0.6
Expand Down Expand Up @@ -136,4 +138,6 @@ def test_recursion():
out = r.identify("fixtures", only_text=False)

assert re.findall(r"\'(?:\/|\\\\)file\'", str(list(out["Regexes"].keys())))
assert re.findall(r"\'(?:\/|\\\\)test(?:\/|\\\\)file\'", str(list(out["Regexes"].keys())))
assert re.findall(
r"\'(?:\/|\\\\)test(?:\/|\\\\)file\'", str(list(out["Regexes"].keys()))
)
5 changes: 4 additions & 1 deletion tests/test_regex_identifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from pywhat import regex_identifier


Expand Down Expand Up @@ -105,7 +106,9 @@ def test_ip4():
assert "[2001:db8::1]:8080" in res[0]["Matched"]


@pytest.mark.skip(reason="Fails because not a valid TLD. If presented in punycode, it works.")
@pytest.mark.skip(
reason="Fails because not a valid TLD. If presented in punycode, it works."
)
def test_international_url():
r = regex_identifier.RegexIdentifier()
res = r.check(["http://папироска.рф"])
Expand Down

0 comments on commit c6527a1

Please sign in to comment.