path
stringlengths
9
117
type
stringclasses
2 values
project
stringclasses
10 values
commit_hash
stringlengths
40
40
commit_message
stringlengths
1
137
ground_truth
stringlengths
0
2.74k
main_code
stringlengths
102
3.37k
context
stringlengths
0
14.7k
pywhat.identifier/Identifier.__init__
Modified
bee-san~pyWhat
76040a75dda997fbba195b022362fdddaccfeb0b
Merge branch 'main' into remove-nth
<6>:<del> self._name_that_hash = Nth()
# module: pywhat.identifier class Identifier: def __init__( self, *, dist: Optional[Distribution] = None, key: Callable = Keys.NONE, reverse=False, boundaryless: Optional[Filter] = None ): <0> if dist is None: <1> self.distribution = Distribution() <2> else: <3> self.distribution = dist <4> self._regex_id = RegexIdentifier() <5> self._file_sig = FileSignatures() <6> self._name_that_hash = Nth() <7> self._key = key <8> self._reverse = reverse <9> if boundaryless is None: <10> self.boundaryless = Filter({"Tags": []}) <11> else: <12> self.boundaryless = boundaryless <13>
===========unchanged ref 0=========== at: pywhat.filter Filter(filters_dict: Optional[Mapping]=None) Distribution(filter: Optional[Filter]=None) at: pywhat.helper Keys() at: pywhat.magic_numbers FileSignatures() at: pywhat.regex_identifier RegexIdentifier() at: typing Callable = _CallableType(collections.abc.Callable, 2)
pywhat.printer/Printing.pretty_print
Modified
bee-san~pyWhat
76040a75dda997fbba195b022362fdddaccfeb0b
Merge branch 'main' into remove-nth
# module: pywhat.printer class Printing: def pretty_print(self, text: dict, text_input): <0> to_out = "" <1> <2> if text["File Signatures"] and text["Regexes"]: <3> for key, value in text["File Signatures"].items(): <4> if value: <5> to_out += "\n" <6> to_out += f"[bold #D7Afff]File Identified[/bold #D7Afff]: [bold]{key}[/bold] with Magic Numbers {value['ISO 8859-1']}." <7> to_out += f"\n[bold #D7Afff]File Description:[/bold #D7Afff] {value['Description']}." <8> to_out += "\n" <9> <10> if text["Regexes"]: <11> to_out += "\n[bold #D7Afff]Possible Identification[/bold #D7Afff]" <12> table = Table( <13> show_header=True, header_style="bold #D7Afff", show_lines=True <14> ) <15> table.add_column("Matched Text", overflow="fold") <16> table.add_column("Identified as", overflow="fold") <17> table.add_column("Description", overflow="fold") <18> <19> if os.path.isdir(text_input): <20> # if input is a folder, add a filename column <21> table.add_column("File", overflow="fold") <22> <23> for key, value in text["Regexes"].items(): <24> for i in value: <25> matched = i["Matched"] <26> name = i["Regex Pattern"]["Name"] <27> description = None <28> filename = key <29> <30> if "URL" in i["Regex Pattern"] and i["Regex Pattern"]["URL"]: <31> description = ( <32> "Click here to analyse in the browser\n" <33> + i["Regex Pattern"]["URL"] <34> + matched.replace(" ", "") <35> ) <36> <37> if i["Regex Pattern"]["Description"]: <38> </s>
===========below chunk 0=========== # module: pywhat.printer class Printing: def pretty_print(self, text: dict, text_input): # offset: 1 description = ( description + "\n" + i["Regex Pattern"]["Description"] ) else: description = i["Regex Pattern"]["Description"] if not description: description = "None" if os.path.isdir(text_input): table.add_row( matched, name, description, filename, ) else: table.add_row( matched, name, description, ) self.console.print(to_out, table) if to_out == "": self.console.print("Nothing found!") """ # This is commented out because there's too many possible hash idenfications # This is fixed by https://github.com/HashPals/Name-That-Hash/issues/89 if text["Hashes"]: to_out = "\n[bold #D7Afff]Hashes Identified[/bold #D7Afff]" table = Table( show_header=True, header_style="bold #D7Afff", show_lines=True ) table.add_column("Matched Text") table.add_column("Possible Hash Type") table.add_column("Description") for hash_text in text["Hashes"].keys(): for types in text["Hashes"][hash_text]: table.add_row( hash_text, types["name"], types["description"], ) console.print(to_out, table) """ ===========unchanged ref 0=========== at: json dumps(obj: Any, *, skipkeys: bool=..., ensure_ascii: bool=..., check_circular: bool=..., allow_nan: bool=..., cls: Optional[Type[JSONEncoder]]=..., indent: Union[None, int, str]=..., separators: Optional[Tuple[str, str]]=..., default: Optional[Callable[[Any], Any]]=..., sort_keys: bool=..., **kwds: Any) -> str at: os.path isdir(s: AnyPath) -> bool at: pywhat.printer.Printing.__init__ self.console = Console(highlight=False) ===========changed ref 0=========== # module: pywhat.identifier class Identifier: def __init__( self, *, dist: Optional[Distribution] = None, key: Callable = Keys.NONE, reverse=False, boundaryless: Optional[Filter] = None ): if dist is None: self.distribution = Distribution() else: self.distribution = dist self._regex_id = RegexIdentifier() self._file_sig = FileSignatures() - self._name_that_hash = Nth() self._key = key self._reverse = reverse if boundaryless is None: self.boundaryless = Filter({"Tags": []}) else: self.boundaryless = boundaryless
pywhat.identifier/Identifier.identify
Modified
bee-san~pyWhat
2712f60bda0cde149fed9ec52c4c8ef02e6d65c8
Merge branch 'main' into search-filenames
<28>:<add> <add> if include_filenames: <add> contents.append(os.path.basename(string)) <del> contents.append(os.path.basename(string)) <29>:<add>
# module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, + boundaryless: Optional[Filter] = None, - boundaryless: Optional[Filter] = None + include_filenames=False, ) -> dict: <0> if dist is None: <1> dist = self.distribution <2> if key is None: <3> key = self._key <4> if reverse is None: <5> reverse = self._reverse <6> if boundaryless is None: <7> boundaryless = self.boundaryless <8> identify_obj = {"File Signatures": {}, "Regexes": {}} <9> search = [] <10> <11> if not only_text and os.path.isdir(text): <12> # if input is a directory, recursively search for all of the files <13> for myfile in glob.iglob(text + "/**", recursive=True): <14> if os.path.isfile(myfile): <15> search.append(os.path.abspath(myfile)) <16> else: <17> search = [text] <18> <19> for string in search: <20> if not only_text and os.path.isfile(string): <21> if os.path.isdir(text): <22> short_name = string.replace(os.path.abspath(text), "") <23> else: <24> short_name = os.path.basename(string) <25> <26> magic_numbers = self._file_sig.open_binary_scan_magic_nums(string) <27> contents = self._file_sig.open_file_loc(string) <28> contents.append(os.path.basename(string)) <29> regex = self._regex_id.check(contents, dist) </s>
===========below chunk 0=========== <s>what.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, + boundaryless: Optional[Filter] = None, - boundaryless: Optional[Filter] = None + include_filenames=False, ) -> dict: # offset: 1 if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string) if magic_numbers: identify_obj["File Signatures"][short_name] = magic_numbers else: short_name = "text" regex = self._regex_id.check( search, dist=dist, boundaryless=boundaryless ) if regex: identify_obj["Regexes"][short_name] = regex for key_, value in identify_obj.items(): # if there are zero regex or file signature matches, set it to None if len(identify_obj[key_]) == 0: identify_obj[key_] = None if key != Keys.NONE: identify_obj["Regexes"][short_name] = sorted( identify_obj["Regexes"][short_name], key=key, reverse=reverse ) return identify_obj ===========unchanged ref 0=========== at: glob iglob(pathname: AnyStr, *, recursive: bool=...) -> Iterator[AnyStr] at: os.path isfile(path: AnyPath) -> bool isdir(s: AnyPath) -> bool basename(p: _PathLike[AnyStr]) -> AnyStr basename(p: AnyStr) -> AnyStr abspath(path: _PathLike[AnyStr]) -> AnyStr abspath(path: AnyStr) -> AnyStr abspath = _abspath_fallback at: pywhat.filter Filter(filters_dict: Optional[Mapping]=None) Distribution(filter: Optional[Filter]=None) at: pywhat.helper Keys() at: pywhat.identifier.Identifier.__init__ self.distribution = Distribution() self.distribution = dist self._regex_id = RegexIdentifier() self._file_sig = FileSignatures() self._key = key self._reverse = reverse self.boundaryless = boundaryless self.boundaryless = Filter({"Tags": []}) at: pywhat.magic_numbers.FileSignatures open_file_loc(file_loc) open_binary_scan_magic_nums(file_loc) check_magic_nums(text) at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: typing Callable = _CallableType(collections.abc.Callable, 2)
pywhat.what/main
Modified
bee-san~pyWhat
2712f60bda0cde149fed9ec52c4c8ef02e6d65c8
Merge branch 'main' into search-filenames
<s> for boundaryless mode." ) @click.option( "-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode." ) @click.option("--json", is_flag=True, help="Return results in json format.") + @click.option( + "-if", + "--include-filenames", + is_flag=True, + help="Search filenames for possible matches." + ) def main(**kwargs): <0> """ <1> pyWhat - Identify what something is. <2> <3> Made by Bee https://twitter.com/bee_sec_san <4> <5> https://github.com/bee-san <6> <7> Filtration: <8> <9> --rarity min:max <10> <11> Rarity is how unlikely something is to be a false-positive. The higher the number, the more unlikely. <12> <13> Only print entries with rarity in range [min,max]. min and max can be omitted. <14> <15> Note: PyWhat by default has a rarity of 0.1. To see all matches, with many potential false positives use `0:`. <16> <17> --include list <18> <19> Only include entries containing at least one tag in a list. List is a comma separated list. <20> <21> --exclude list <22> <23> Exclude specified tags. List is a comma separated list. <24> <25> Sorting: <26> <27> --key key_name <28> <29> Sort by the given key. <30> <31> --reverse <32> <33> Sort in reverse order. <34> <35> Available keys: <36> <37> name - Sort by the name of regex pattern <38> <39> rarity - Sort by rarity <40> <41> matched - Sort by a matched string <42> <43> none - No sorting is done (the default) <44> <45> Exporting: <46> </s>
===========below chunk 0=========== <s> ) @click.option( "-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode." ) @click.option("--json", is_flag=True, help="Return results in json format.") + @click.option( + "-if", + "--include-filenames", + is_flag=True, + help="Search filenames for possible matches." + ) def main(**kwargs): # offset: 1 Return results in json format. Boundaryless mode: CLI tool matches strings like 'abcdTHM{hello}plze' by default because the boundaryless mode is enabled for regexes with a rarity of 0.1 and higher. Since boundaryless mode may produce a lot of false-positive matches, it is possible to disable it, either fully or partially. '--disable-boundaryless' flag can be used to fully disable this mode. In addition, '-br', '-bi', and '-be' options can be used to tweak which regexes should be in boundaryless mode. Refer to the Filtration section for more information. Examples: * what 'HTB{this is a flag}' * what '0x52908400098527886E0F7030069857D2E4169EE7' * what -- '52.6169586, -1.9779857' * what --rarity 0.6: '[email protected]' * what --rarity 0: --include "credentials, username, password" --exclude "aws, credentials" 'James:SecretPassword' * what -br 0.6: -be URL '[email protected]' Your text must either be in quotation marks, or use the POSIX standard of "--" to mean "anything after -- is textual input". pyWhat can also search files or</s> ===========below chunk 1=========== <s> ) @click.option( "-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode." ) @click.option("--json", is_flag=True, help="Return results in json format.") + @click.option( + "-if", + "--include-filenames", + is_flag=True, + help="Search filenames for possible matches." + ) def main(**kwargs): # offset: 2 <s> POSIX standard of "--" to mean "anything after -- is textual input". pyWhat can also search files or even a whole directory with recursion: * what 'secret.txt' * what 'this/is/a/path' """ dist = Distribution( create_filter(kwargs["rarity"], kwargs["include"], kwargs["exclude"]) ) if kwargs["disable_boundaryless"]: boundaryless = Filter({"Tags": []}) # use empty filter else: boundaryless = create_filter( kwargs["boundaryless_rarity"], kwargs["boundaryless_include"], kwargs["boundaryless_exclude"], ) what_obj = What_Object(dist) if kwargs["key"] is None: key = Keys.NONE else: try: key = str_to_key(kwargs["key"]) except ValueError: print("Invalid key") sys.exit(1) identified_output = what_obj.what_is_this( kwargs["text_input"], kwargs["only_text"], key, kwargs["reverse"], boundaryless ) p = printer.Printing() if kwargs["json"]: p.print_json(identified_ ===========below chunk 2=========== <s> ) @click.option( "-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode." ) @click.option("--json", is_flag=True, help="Return results in json format.") + @click.option( + "-if", + "--include-filenames", + is_flag=True, + help="Search filenames for possible matches." + ) def main(**kwargs): # offset: 3 <s>) else: p.pretty_print(identified_output, kwargs["text_input"]) ===========unchanged ref 0=========== at: click.decorators command(name: Optional[str]=..., cls: Optional[Type[Command]]=..., context_settings: Optional[Dict[Any, Any]]=..., help: Optional[str]=..., epilog: Optional[str]=..., short_help: Optional[str]=..., options_metavar: str=..., add_help_option: bool=..., hidden: bool=..., deprecated: bool=...) -> Callable[[Callable[..., Any]], Command] argument(*param_decls: Text, cls: Type[Argument]=..., required: Optional[bool]=..., type: Optional[_ConvertibleType]=..., default: Optional[Any]=..., callback: Optional[_Callback]=..., nargs: Optional[int]=..., metavar: Optional[str]=..., expose_value: bool=..., is_eager: bool=..., envvar: Optional[Union[str, List[str]]]=..., autocompletion: Optional[Callable[[Any, List[str], str], List[Union[str, Tuple[str, str]]]]]=...) -> _IdentityFunction ===========unchanged ref 1=========== option(*param_decls: str, cls: Type[Option]=..., show_default: Union[bool, Text]=..., prompt: Union[bool, Text]=..., confirmation_prompt: bool=..., hide_input: bool=..., is_flag: Optional[bool]=..., flag_value: Optional[Any]=..., multiple: bool=..., count: bool=..., allow_from_autoenv: bool=..., type: _T=..., help: Optional[str]=..., show_choices: bool=..., default: Optional[Any]=..., required: bool=..., callback: Optional[Callable[[Context, Union[Option, Parameter], Union[bool, int, str]], _T]]=..., nargs: Optional[int]=..., metavar: Optional[str]=..., expose_value: bool=..., is_eager: bool=..., envvar: Optional[Union[str, List[str]]]=..., **kwargs: Any) -> _IdentityFunction option(*param_decls: str, cls: Type[Option]=..., show_default: Union[bool, Text]=..., prompt: Union[bool, Text]=..., confirmation_prompt: bool=..., hide_input: bool=..., is_flag: Optional[bool]=..., flag_value: Optional[Any]=..., multiple: bool=..., count: bool=..., allow_from_autoenv: bool=..., type: Type[int]=..., help: Optional[str]=..., show_choices: bool=..., default: Optional[Any]=..., required: bool=..., callback: Callable[[Context, Union[Option, Parameter], int], Any]=..., nargs: Optional[int]=..., metavar: Optional[str]=..., expose_value: bool=..., is_eager: bool=..., envvar: Optional[Union[str, List[str]]]=..., **kwargs: Any) -> _IdentityFunction option(*param_decls: Text, cls: Type[Option]=..., show_default: Union[bool, Text]=..., prompt: Union[bool, Text]=..., confirmation_prompt: bool=...,</s>
pywhat.what/What_Object.what_is_this
Modified
bee-san~pyWhat
2712f60bda0cde149fed9ec52c4c8ef02e6d65c8
Merge branch 'main' into search-filenames
<9>:<add> include_filenames=include_filenames
# module: pywhat.what class What_Object: def what_is_this( + self, + text: str, + only_text: bool, + key, + reverse: bool, + boundaryless: Filter, + include_filenames: bool, - self, text: str, only_text: bool, key, reverse: bool, boundaryless: Filter ) -> dict: <0> """ <1> Returns a Python dictionary of everything that has been identified <2> """ <3> return self.id.identify( <4> text, <5> only_text=only_text, <6> key=key, <7> reverse=reverse, <8> boundaryless=boundaryless, <9> ) <10>
===========unchanged ref 0=========== at: pywhat.identifier Identifier(*, dist: Optional[Distribution]=None, key: Callable=Keys.NONE, reverse=False, boundaryless: Optional[Filter]=None) at: pywhat.printer.Printing pretty_print(text: dict, text_input) print_json(text: dict) at: pywhat.what.main identified_output = what_obj.what_is_this( kwargs["text_input"], kwargs["only_text"], key, kwargs["reverse"], boundaryless, kwargs["include_filenames"], ) p = printer.Printing() ===========changed ref 0=========== <s> for boundaryless mode." ) @click.option( "-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode." ) @click.option("--json", is_flag=True, help="Return results in json format.") + @click.option( + "-if", + "--include-filenames", + is_flag=True, + help="Search filenames for possible matches." + ) def main(**kwargs): """ pyWhat - Identify what something is. Made by Bee https://twitter.com/bee_sec_san https://github.com/bee-san Filtration: --rarity min:max Rarity is how unlikely something is to be a false-positive. The higher the number, the more unlikely. Only print entries with rarity in range [min,max]. min and max can be omitted. Note: PyWhat by default has a rarity of 0.1. To see all matches, with many potential false positives use `0:`. --include list Only include entries containing at least one tag in a list. List is a comma separated list. --exclude list Exclude specified tags. List is a comma separated list. Sorting: --key key_name Sort by the given key. --reverse Sort in reverse order. Available keys: name - Sort by the name of regex pattern rarity - Sort by rarity matched - Sort by a matched string none - No sorting is done (the default) Exporting: --json Return results in json format. Boundaryless mode: CLI tool matches strings like 'abcdTHM{hello}plze' by default because</s> ===========changed ref 1=========== <s> ) @click.option( "-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode." ) @click.option("--json", is_flag=True, help="Return results in json format.") + @click.option( + "-if", + "--include-filenames", + is_flag=True, + help="Search filenames for possible matches." + ) def main(**kwargs): # offset: 1 <s> Boundaryless mode: CLI tool matches strings like 'abcdTHM{hello}plze' by default because the boundaryless mode is enabled for regexes with a rarity of 0.1 and higher. Since boundaryless mode may produce a lot of false-positive matches, it is possible to disable it, either fully or partially. '--disable-boundaryless' flag can be used to fully disable this mode. In addition, '-br', '-bi', and '-be' options can be used to tweak which regexes should be in boundaryless mode. Refer to the Filtration section for more information. Examples: * what 'HTB{this is a flag}' * what '0x52908400098527886E0F7030069857D2E4169EE7' * what -- '52.6169586, -1.9779857' * what --rarity 0.6: '[email protected]' * what --rarity 0: --include "credentials, username, password" --exclude "aws, credentials" 'James:SecretPassword' * what -br 0.6: -be URL '[email protected]' Your text must either be in quotation marks, or use the POSIX standard of "--" to mean "any</s> ===========changed ref 2=========== <s> ) @click.option( "-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode." ) @click.option("--json", is_flag=True, help="Return results in json format.") + @click.option( + "-if", + "--include-filenames", + is_flag=True, + help="Search filenames for possible matches." + ) def main(**kwargs): # offset: 2 <s> -- is textual input". pyWhat can also search files or even a whole directory with recursion: * what 'secret.txt' * what 'this/is/a/path' """ dist = Distribution( create_filter(kwargs["rarity"], kwargs["include"], kwargs["exclude"]) ) if kwargs["disable_boundaryless"]: boundaryless = Filter({"Tags": []}) # use empty filter else: boundaryless = create_filter( kwargs["boundaryless_rarity"], kwargs["boundaryless_include"], kwargs["boundaryless_exclude"], ) what_obj = What_Object(dist) if kwargs["key"] is None: key = Keys.NONE else: try: key = str_to_key(kwargs["key"]) except ValueError: print("Invalid key") sys.exit(1) identified_output = what_obj.what_is_this( + kwargs["text_input"], + kwargs["only_text"], + key, + kwargs["reverse"], + boundaryless, + kwargs["include_filenames"], - kwargs["text_input"], kwargs["only_text"], key,</s> ===========changed ref 3=========== <s> ) @click.option( "-db", "--disable-boundaryless", is_flag=True, help="Disable boundaryless mode." ) @click.option("--json", is_flag=True, help="Return results in json format.") + @click.option( + "-if", + "--include-filenames", + is_flag=True, + help="Search filenames for possible matches." + ) def main(**kwargs): # offset: 3 <s>reverse"], boundaryless ) p = printer.Printing() if kwargs["json"]: p.print_json(identified_output) else: p.pretty_print(identified_output, kwargs["text_input"])
pywhat.helper/load_regexes
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> path = "Data/regex.json" <1>:<del> fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) <2>:<del> with open(fullpath, "rb") as myfile: <3>:<del> regexes = json.load(myfile) <4>:<add> regexes = read_json("regex.json") <11>:<add> children = regex.get("Children") <add> if children is not None: <add> try: <add> children["Items"] = read_json(children["path"]) <add> except KeyError: <add> pass <add> children["lengths"] = set() <add> for element in children["Items"]: <add> children["lengths"].add(len(element))
# module: pywhat.helper + @lru_cache() def load_regexes() -> list: <0> path = "Data/regex.json" <1> fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) <2> with open(fullpath, "rb") as myfile: <3> regexes = json.load(myfile) <4> for regex in regexes: <5> regex["Boundaryless Regex"] = re.sub( <6> r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] <7> ) <8> regex["Boundaryless Regex"] = re.sub( <9> r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] <10> ) <11> return regexes <12>
===========unchanged ref 0=========== at: functools lru_cache(maxsize: Optional[int]=..., typed: bool=...) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]] lru_cache(maxsize: Callable[..., _T], typed: bool=...) -> _lru_cache_wrapper[_T] at: io.BufferedWriter read(self, size: Optional[int]=..., /) -> bytes at: json loads(s: Union[str, bytes], *, cls: Optional[Type[JSONDecoder]]=..., object_hook: Optional[Callable[[Dict[Any, Any]], Any]]=..., parse_float: Optional[Callable[[str], Any]]=..., parse_int: Optional[Callable[[str], Any]]=..., parse_constant: Optional[Callable[[str], Any]]=..., object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]]=..., **kwds: Any) -> Any at: os.path join(a: StrPath, *paths: StrPath) -> str join(a: BytesPath, *paths: BytesPath) -> bytes dirname(p: _PathLike[AnyStr]) -> AnyStr dirname(p: AnyStr) -> AnyStr abspath(path: _PathLike[AnyStr]) -> AnyStr abspath(path: AnyStr) -> AnyStr abspath = _abspath_fallback at: typing.IO __slots__ = () read(n: int=...) -> AnyStr ===========changed ref 0=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json +
pywhat.regex_identifier/RegexIdentifier.check
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<13>:<del> reg = copy.copy(reg) # necessary, when checking phone <14>:<del> # numbers from file that may contain <15>:<del> # non-international numbers <16>:<add> reg = copy.copy(reg) <18>:<del> if "Phone Number" in reg["Name"]: <19>:<del> number = re.sub(r"[-() ]", "", matched) <20>:<del> codes_path = "Data/phone_codes.json" <21>:<del> codes_fullpath = os.path.join( <22>:<del> os.path.dirname(os.path.abspath(__file__)), codes_path <23>:<add> children = reg.get("Children") <add> if children is not None: <add> processed_match = re.sub( <add> children.get("deletion_pattern", ""), "", matched <24>:<add> matched_children = [] <add> if children["method"] == "hashmap": <add> for length in children["lengths"]: <add> try: <add> matched_children.append( <add> children["Items"][processed_match[:length]] <add> ) <add> except KeyError: <add> continue <add> else: <add> for element in children["Items"]: <add> if ( <add> children["method"] == "regex" <add> and re.search( <add> element, processed_match, re.MULTILINE <add> ) <add> ) or ( <add> children["method"] == "startswith" <add> and processed_match
# module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): <0> if dist is None: <1> dist = self.distribution <2> if boundaryless is None: <3> boundaryless = Filter({"Tags": []}) <4> matches = [] <5> <6> for string in text: <7> for reg in dist.get_regexes(): <8> regex = ( <9> reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] <10> ) <11> <12> for matched_regex in re.finditer(regex, string, re.MULTILINE): <13> reg = copy.copy(reg) # necessary, when checking phone <14> # numbers from file that may contain <15> # non-international numbers <16> matched = self.clean_text(matched_regex.group(0)) <17> <18> if "Phone Number" in reg["Name"]: <19> number = re.sub(r"[-() ]", "", matched) <20> codes_path = "Data/phone_codes.json" <21> codes_fullpath = os.path.join( <22> os.path.dirname(os.path.abspath(__file__)), codes_path <23> ) <24> with open(codes_fullpath, "rb") as myfile: <25> codes = json.load(myfile) <26> <27> locations = [] <28> for code in codes: <29> if number.startswith(code["dial_code"]): <30> locations.append(code["name"]) <31> if len(locations) > 0: <32> reg["Description"] = ( <33> "Location(s)" + ": " + ", ".join(locations) <34> ) <35> <36> matches.append( <37> { <38> "Matched": matched, <39> "Regex Pattern": reg, <40> } <41> ) <42> <43> return matches <44>
===========unchanged ref 0=========== at: copy copy(x: _T) -> _T at: json load(fp: SupportsRead[Union[str, bytes]], *, cls: Optional[Type[JSONDecoder]]=..., object_hook: Optional[Callable[[Dict[Any, Any]], Any]]=..., parse_float: Optional[Callable[[str], Any]]=..., parse_int: Optional[Callable[[str], Any]]=..., parse_constant: Optional[Callable[[str], Any]]=..., object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]]=..., **kwds: Any) -> Any at: os.path join(a: StrPath, *paths: StrPath) -> str join(a: BytesPath, *paths: BytesPath) -> bytes dirname(p: _PathLike[AnyStr]) -> AnyStr dirname(p: AnyStr) -> AnyStr abspath(path: _PathLike[AnyStr]) -> AnyStr abspath(path: AnyStr) -> AnyStr abspath = _abspath_fallback at: pywhat.filter Filter(filters_dict: Optional[Mapping]=None) Distribution(filter: Optional[Filter]=None) at: pywhat.filter.Distribution get_regexes() at: pywhat.regex_identifier.RegexIdentifier clean_text(text) at: pywhat.regex_identifier.RegexIdentifier.__init__ self.distribution = Distribution() at: re MULTILINE = RegexFlag.MULTILINE ===========unchanged ref 1=========== sub(pattern: AnyStr, repl: AnyStr, string: AnyStr, count: int=..., flags: _FlagsType=...) -> AnyStr sub(pattern: Pattern[AnyStr], repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int=..., flags: _FlagsType=...) -> AnyStr sub(pattern: AnyStr, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int=..., flags: _FlagsType=...) -> AnyStr sub(pattern: Pattern[AnyStr], repl: AnyStr, string: AnyStr, count: int=..., flags: _FlagsType=...) -> AnyStr finditer(pattern: AnyStr, string: AnyStr, flags: _FlagsType=...) -> Iterator[Match[AnyStr]] finditer(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType=...) -> Iterator[Match[AnyStr]] at: typing.Match pos: int endpos: int lastindex: Optional[int] lastgroup: Optional[AnyStr] string: AnyStr re: Pattern[AnyStr] group(group1: Union[str, int], group2: Union[str, int], /, *groups: Union[str, int]) -> Tuple[AnyStr, ...] group(group: Union[str, int]=..., /) -> AnyStr ===========changed ref 0=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 1=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 2=========== # module: pywhat.helper + @lru_cache() def load_regexes() -> list: - path = "Data/regex.json" - fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) - with open(fullpath, "rb") as myfile: - regexes = json.load(myfile) + regexes = read_json("regex.json") for regex in regexes: regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] ) regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] ) + children = regex.get("Children") + if children is not None: + try: + children["Items"] = read_json(children["path"]) + except KeyError: + pass + children["lengths"] = set() + for element in children["Items"]: + children["lengths"].add(len(element)) return regexes
pywhat.magic_numbers/FileSignatures.__init__
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<3>:<add> self.file_sigs = json.loads(myfile.read()) <del> self.file_sigs = json.load(myfile)
# module: pywhat.magic_numbers class FileSignatures: def __init__(self): <0> path = "Data/file_signatures.json" <1> fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) <2> with open(fullpath, "rb") as myfile: <3> self.file_sigs = json.load(myfile) <4>
===========changed ref 0=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 1=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 2=========== # module: pywhat.helper + @lru_cache() def load_regexes() -> list: - path = "Data/regex.json" - fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) - with open(fullpath, "rb") as myfile: - regexes = json.load(myfile) + regexes = read_json("regex.json") for regex in regexes: regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] ) regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] ) + children = regex.get("Children") + if children is not None: + try: + children["Items"] = read_json(children["path"]) + except KeyError: + pass + children["lengths"] = set() + for element in children["Items"]: + children["lengths"].add(len(element)) return regexes ===========changed ref 3=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 4=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches
pywhat.identifier/Identifier.identify
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<8>:<add>
# module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: <0> if dist is None: <1> dist = self.distribution <2> if key is None: <3> key = self._key <4> if reverse is None: <5> reverse = self._reverse <6> if boundaryless is None: <7> boundaryless = self.boundaryless <8> identify_obj = {"File Signatures": {}, "Regexes": {}} <9> search = [] <10> <11> if not only_text and os.path.isdir(text): <12> # if input is a directory, recursively search for all of the files <13> for myfile in glob.iglob(text + "/**", recursive=True): <14> if os.path.isfile(myfile): <15> search.append(os.path.abspath(myfile)) <16> else: <17> search = [text] <18> <19> for string in search: <20> if not only_text and os.path.isfile(string): <21> if os.path.isdir(text): <22> short_name = string.replace(os.path.abspath(text), "") <23> else: <24> short_name = os.path.basename(string) <25> <26> magic_numbers = self._file_sig.open_binary_scan_magic_nums(string) <27> contents = self._file_sig.open_file_loc(string) <28> <29> if include_filenames: <30> contents.append(os.path.basename(string)) <31> <32> regex = self._regex_id.check(contents, dist) </s>
===========below chunk 0=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: # offset: 1 if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string) if magic_numbers: identify_obj["File Signatures"][short_name] = magic_numbers else: short_name = "text" regex = self._regex_id.check( search, dist=dist, boundaryless=boundaryless ) if regex: identify_obj["Regexes"][short_name] = regex for key_, value in identify_obj.items(): # if there are zero regex or file signature matches, set it to None if len(identify_obj[key_]) == 0: identify_obj[key_] = None if key != Keys.NONE: identify_obj["Regexes"][short_name] = sorted( identify_obj["Regexes"][short_name], key=key, reverse=reverse ) return identify_obj ===========unchanged ref 0=========== at: glob iglob(pathname: AnyStr, *, recursive: bool=...) -> Iterator[AnyStr] at: os.path isfile(path: AnyPath) -> bool isdir(s: AnyPath) -> bool basename(p: _PathLike[AnyStr]) -> AnyStr basename(p: AnyStr) -> AnyStr abspath(path: _PathLike[AnyStr]) -> AnyStr abspath(path: AnyStr) -> AnyStr abspath = _abspath_fallback at: pywhat.filter Filter(filters_dict: Optional[Mapping]=None) Distribution(filter: Optional[Filter]=None) at: pywhat.helper Keys() at: pywhat.identifier.Identifier.__init__ self.distribution = Distribution() self.distribution = dist self._regex_id = RegexIdentifier() self._file_sig = FileSignatures() self._key = key self._reverse = reverse self.boundaryless = boundaryless self.boundaryless = Filter({"Tags": []}) at: pywhat.magic_numbers.FileSignatures open_file_loc(file_loc) open_binary_scan_magic_nums(file_loc) check_magic_nums(text) at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: typing Callable = _CallableType(collections.abc.Callable, 2) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 3=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 4=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 5=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile)
pywhat.what/print_tags
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<3>:<add> console.print("[bold #D7AFFF]" + "\n".join(tags) + "[/bold #D7AFFF]") <del> console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]")
# module: pywhat.what def print_tags(ctx, opts, value): <0> if value: <1> tags = sorted(AvailableTags().get_tags()) <2> console = Console() <3> console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]") <4> sys.exit() <5>
===========unchanged ref 0=========== at: pywhat.helper AvailableTags() at: pywhat.helper.AvailableTags get_tags() at: sys exit(status: object=..., /) -> NoReturn ===========changed ref 0=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 1=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 2=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 3=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 4=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile) ===========changed ref 5=========== # module: pywhat.helper + @lru_cache() def load_regexes() -> list: - path = "Data/regex.json" - fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) - with open(fullpath, "rb") as myfile: - regexes = json.load(myfile) + regexes = read_json("regex.json") for regex in regexes: regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] ) regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] ) + children = regex.get("Children") + if children is not None: + try: + children["Items"] = read_json(children["path"]) + except KeyError: + pass + children["lengths"] = set() + for element in children["Items"]: + children["lengths"].add(len(element)) return regexes ===========changed ref 6=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: if dist is None: dist = self.distribution if key is None: key = self._key if reverse is None: reverse = self._reverse if boundaryless is None: boundaryless = self.boundaryless + identify_obj = {"File Signatures": {}, "Regexes": {}} search = [] if not only_text and os.path.isdir(text): # if input is a directory, recursively search for all of the files for myfile in glob.iglob(text + "/**", recursive=True): if os.path.isfile(myfile): search.append(os.path.abspath(myfile)) else: search = [text] for string in search: if not only_text and os.path.isfile(string): if os.path.isdir(text): short_name = string.replace(os.path.abspath(text), "") else: short_name = os.path.basename(string) magic_numbers = self._file_sig.open_binary_scan_magic_nums(string) contents = self._file_sig.open_file_loc(string) if include_filenames: contents.append(os.path.basename(string)) regex = self._regex_id.check(contents, dist) if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string)</s> ===========changed ref 7=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: # offset: 1 <s> if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string) if magic_numbers: identify_obj["File Signatures"][short_name] = magic_numbers else: short_name = "text" regex = self._regex_id.check( search, dist=dist, boundaryless=boundaryless ) if regex: identify_obj["Regexes"][short_name] = regex for key_, value in identify_obj.items(): # if there are zero regex or file signature matches, set it to None if len(identify_obj[key_]) == 0: identify_obj[key_] = None if key != Keys.NONE: identify_obj["Regexes"][short_name] = sorted( identify_obj["Regexes"][short_name], key=key, reverse=reverse ) return identify_obj
tests.test_regex_identifier/test_if_all_tests_exist
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> database = load_regexes() <1>:<del>
# module: tests.test_regex_identifier def test_if_all_tests_exist(): <0> database = load_regexes() <1> <2> with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: <3> tests = file.read() <4> <5> for regex in database: <6> assert ( <7> regex["Name"] in tests <8> ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." <9>
===========unchanged ref 0=========== at: io.FileIO read(self, size: int=..., /) -> bytes at: pywhat.regex_identifier RegexIdentifier() at: tests.test_regex_identifier database = load_regexes() at: typing.IO __slots__ = () read(n: int=...) -> AnyStr ===========changed ref 0=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 1=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 2=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 3=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 4=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 5=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile) ===========changed ref 6=========== # module: pywhat.what def print_tags(ctx, opts, value): if value: tags = sorted(AvailableTags().get_tags()) console = Console() + console.print("[bold #D7AFFF]" + "\n".join(tags) + "[/bold #D7AFFF]") - console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]") sys.exit() ===========changed ref 7=========== # module: pywhat.helper + @lru_cache() def load_regexes() -> list: - path = "Data/regex.json" - fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) - with open(fullpath, "rb") as myfile: - regexes = json.load(myfile) + regexes = read_json("regex.json") for regex in regexes: regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] ) regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] ) + children = regex.get("Children") + if children is not None: + try: + children["Items"] = read_json(children["path"]) + except KeyError: + pass + children["lengths"] = set() + for element in children["Items"]: + children["lengths"].add(len(element)) return regexes ===========changed ref 8=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: if dist is None: dist = self.distribution if key is None: key = self._key if reverse is None: reverse = self._reverse if boundaryless is None: boundaryless = self.boundaryless + identify_obj = {"File Signatures": {}, "Regexes": {}} search = [] if not only_text and os.path.isdir(text): # if input is a directory, recursively search for all of the files for myfile in glob.iglob(text + "/**", recursive=True): if os.path.isfile(myfile): search.append(os.path.abspath(myfile)) else: search = [text] for string in search: if not only_text and os.path.isfile(string): if os.path.isdir(text): short_name = string.replace(os.path.abspath(text), "") else: short_name = os.path.basename(string) magic_numbers = self._file_sig.open_binary_scan_magic_nums(string) contents = self._file_sig.open_file_loc(string) if include_filenames: contents.append(os.path.basename(string)) regex = self._regex_id.check(contents, dist) if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string)</s> ===========changed ref 9=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: # offset: 1 <s> if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string) if magic_numbers: identify_obj["File Signatures"][short_name] = magic_numbers else: short_name = "text" regex = self._regex_id.check( search, dist=dist, boundaryless=boundaryless ) if regex: identify_obj["Regexes"][short_name] = regex for key_, value in identify_obj.items(): # if there are zero regex or file signature matches, set it to None if len(identify_obj[key_]) == 0: identify_obj[key_] = None if key != Keys.NONE: identify_obj["Regexes"][short_name] = sorted( identify_obj["Regexes"][short_name], key=key, reverse=reverse ) return identify_obj
tests.test_regex_identifier/test_regex_format
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> database = load_regexes() <1>:<del>
# module: tests.test_regex_identifier def test_regex_format(): <0> database = load_regexes() <1> <2> for regex in database: <3> assert re.findall( <4> r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] <5> ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." <6> <7> assert ( <8> re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] <9> ), "Remove in-between boundaries. For example, '^|$' should only be '|'." <10>
===========unchanged ref 0=========== at: re findall(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType=...) -> List[Any] findall(pattern: AnyStr, string: AnyStr, flags: _FlagsType=...) -> List[Any] at: tests.test_regex_identifier database = load_regexes() ===========changed ref 0=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 1=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 2=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 3=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 4=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 5=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 6=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile) ===========changed ref 7=========== # module: pywhat.what def print_tags(ctx, opts, value): if value: tags = sorted(AvailableTags().get_tags()) console = Console() + console.print("[bold #D7AFFF]" + "\n".join(tags) + "[/bold #D7AFFF]") - console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]") sys.exit() ===========changed ref 8=========== # module: pywhat.helper + @lru_cache() def load_regexes() -> list: - path = "Data/regex.json" - fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) - with open(fullpath, "rb") as myfile: - regexes = json.load(myfile) + regexes = read_json("regex.json") for regex in regexes: regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] ) regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] ) + children = regex.get("Children") + if children is not None: + try: + children["Items"] = read_json(children["path"]) + except KeyError: + pass + children["lengths"] = set() + for element in children["Items"]: + children["lengths"].add(len(element)) return regexes ===========changed ref 9=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: if dist is None: dist = self.distribution if key is None: key = self._key if reverse is None: reverse = self._reverse if boundaryless is None: boundaryless = self.boundaryless + identify_obj = {"File Signatures": {}, "Regexes": {}} search = [] if not only_text and os.path.isdir(text): # if input is a directory, recursively search for all of the files for myfile in glob.iglob(text + "/**", recursive=True): if os.path.isfile(myfile): search.append(os.path.abspath(myfile)) else: search = [text] for string in search: if not only_text and os.path.isfile(string): if os.path.isdir(text): short_name = string.replace(os.path.abspath(text), "") else: short_name = os.path.basename(string) magic_numbers = self._file_sig.open_binary_scan_magic_nums(string) contents = self._file_sig.open_file_loc(string) if include_filenames: contents.append(os.path.basename(string)) regex = self._regex_id.check(contents, dist) if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string)</s> ===========changed ref 10=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: # offset: 1 <s> if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string) if magic_numbers: identify_obj["File Signatures"][short_name] = magic_numbers else: short_name = "text" regex = self._regex_id.check( search, dist=dist, boundaryless=boundaryless ) if regex: identify_obj["Regexes"][short_name] = regex for key_, value in identify_obj.items(): # if there are zero regex or file signature matches, set it to None if len(identify_obj[key_]) == 0: identify_obj[key_] = None if key != Keys.NONE: identify_obj["Regexes"][short_name] = sorted( identify_obj["Regexes"][short_name], key=key, reverse=reverse ) return identify_obj
tests.test_regex_identifier/test_sorted_by_rarity
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> database = load_regexes()
# module: tests.test_regex_identifier def test_sorted_by_rarity(): <0> database = load_regexes() <1> rarity_num = [regex["Rarity"] for regex in database] <2> <3> assert rarity_num == sorted( <4> rarity_num, reverse=True <5> ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." <6>
===========unchanged ref 0=========== at: tests.test_regex_identifier database = load_regexes() ===========changed ref 0=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 1=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 2=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 3=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 4=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 5=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 6=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 7=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile) ===========changed ref 8=========== # module: pywhat.what def print_tags(ctx, opts, value): if value: tags = sorted(AvailableTags().get_tags()) console = Console() + console.print("[bold #D7AFFF]" + "\n".join(tags) + "[/bold #D7AFFF]") - console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]") sys.exit() ===========changed ref 9=========== # module: pywhat.helper + @lru_cache() def load_regexes() -> list: - path = "Data/regex.json" - fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) - with open(fullpath, "rb") as myfile: - regexes = json.load(myfile) + regexes = read_json("regex.json") for regex in regexes: regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] ) regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] ) + children = regex.get("Children") + if children is not None: + try: + children["Items"] = read_json(children["path"]) + except KeyError: + pass + children["lengths"] = set() + for element in children["Items"]: + children["lengths"].add(len(element)) return regexes ===========changed ref 10=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: if dist is None: dist = self.distribution if key is None: key = self._key if reverse is None: reverse = self._reverse if boundaryless is None: boundaryless = self.boundaryless + identify_obj = {"File Signatures": {}, "Regexes": {}} search = [] if not only_text and os.path.isdir(text): # if input is a directory, recursively search for all of the files for myfile in glob.iglob(text + "/**", recursive=True): if os.path.isfile(myfile): search.append(os.path.abspath(myfile)) else: search = [text] for string in search: if not only_text and os.path.isfile(string): if os.path.isdir(text): short_name = string.replace(os.path.abspath(text), "") else: short_name = os.path.basename(string) magic_numbers = self._file_sig.open_binary_scan_magic_nums(string) contents = self._file_sig.open_file_loc(string) if include_filenames: contents.append(os.path.basename(string)) regex = self._regex_id.check(contents, dist) if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string)</s>
tests.test_regex_identifier/test_regex_successfully_parses
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_regex_successfully_parses(): <0> r = regex_identifier.RegexIdentifier() <1> assert "Name" in r.distribution.get_regexes()[0] <2>
===========changed ref 0=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 1=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 2=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 3=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 4=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 5=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 6=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 7=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 8=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile) ===========changed ref 9=========== # module: pywhat.what def print_tags(ctx, opts, value): if value: tags = sorted(AvailableTags().get_tags()) console = Console() + console.print("[bold #D7AFFF]" + "\n".join(tags) + "[/bold #D7AFFF]") - console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]") sys.exit() ===========changed ref 10=========== # module: pywhat.helper + @lru_cache() def load_regexes() -> list: - path = "Data/regex.json" - fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) - with open(fullpath, "rb") as myfile: - regexes = json.load(myfile) + regexes = read_json("regex.json") for regex in regexes: regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] ) regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] ) + children = regex.get("Children") + if children is not None: + try: + children["Items"] = read_json(children["path"]) + except KeyError: + pass + children["lengths"] = set() + for element in children["Items"]: + children["lengths"].add(len(element)) return regexes ===========changed ref 11=========== # module: pywhat.identifier class Identifier: def identify( self, text: str, *, only_text=True, dist: Distribution = None, key: Optional[Callable] = None, reverse: Optional[bool] = None, boundaryless: Optional[Filter] = None, include_filenames=False, ) -> dict: if dist is None: dist = self.distribution if key is None: key = self._key if reverse is None: reverse = self._reverse if boundaryless is None: boundaryless = self.boundaryless + identify_obj = {"File Signatures": {}, "Regexes": {}} search = [] if not only_text and os.path.isdir(text): # if input is a directory, recursively search for all of the files for myfile in glob.iglob(text + "/**", recursive=True): if os.path.isfile(myfile): search.append(os.path.abspath(myfile)) else: search = [text] for string in search: if not only_text and os.path.isfile(string): if os.path.isdir(text): short_name = string.replace(os.path.abspath(text), "") else: short_name = os.path.basename(string) magic_numbers = self._file_sig.open_binary_scan_magic_nums(string) contents = self._file_sig.open_file_loc(string) if include_filenames: contents.append(os.path.basename(string)) regex = self._regex_id.check(contents, dist) if not magic_numbers: magic_numbers = self._file_sig.check_magic_nums(string)</s>
tests.test_regex_identifier/test_dogecoin
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_dogecoin(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) <2> _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 4=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 5=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 6=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 7=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 8=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 9=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 10=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 11=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile) ===========changed ref 12=========== # module: pywhat.what def print_tags(ctx, opts, value): if value: tags = sorted(AvailableTags().get_tags()) console = Console() + console.print("[bold #D7AFFF]" + "\n".join(tags) + "[/bold #D7AFFF]") - console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]") sys.exit()
tests.test_regex_identifier/test_url
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_url(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["tryhackme.com"]) <2> _assert_match_first_item("Uniform Resource Locator (URL)", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 5=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 6=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 7=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 8=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 9=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 10=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 11=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 12=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile)
tests.test_regex_identifier/test_url_2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_url_2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["http://username:[email protected]/"]) <2> _assert_match_first_item("Uniform Resource Locator (URL)", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 6=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 7=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 8=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 9=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 10=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 11=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 12=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 13=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile)
tests.test_regex_identifier/test_invalid_tld
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_invalid_tld(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["tryhackme.comm"]) <2> assert "Uniform Resource Locator (URL)" not in res <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 7=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 8=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 9=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 10=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 11=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 12=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 13=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) +
tests.test_regex_identifier/test_https
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_https(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["hTTPs://tryhackme.com"]) <2> _assert_match_first_item("Uniform Resource Locator (URL)", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_lat_long res = r.check(["52.6169586, -1.9779857"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 1=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 2=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 6=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 7=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 8=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 9=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 10=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 11=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 12=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 13=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile) ===========changed ref 14=========== # module: pywhat.what def print_tags(ctx, opts, value): if value: tags = sorted(AvailableTags().get_tags()) console = Console() + console.print("[bold #D7AFFF]" + "\n".join(tags) + "[/bold #D7AFFF]") - console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]") sys.exit() ===========changed ref 15=========== # module: pywhat.helper + @lru_cache() def load_regexes() -> list: - path = "Data/regex.json" - fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) - with open(fullpath, "rb") as myfile: - regexes = json.load(myfile) + regexes = read_json("regex.json") for regex in regexes: regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\^(?![^\[\]]*(?<!\\)\])", "", regex["Regex"] ) regex["Boundaryless Regex"] = re.sub( r"(?<!\\)\$(?![^\[\]]*(?<!\\)\])", "", regex["Boundaryless Regex"] ) + children = regex.get("Children") + if children is not None: + try: + children["Items"] = read_json(children["path"]) + except KeyError: + pass + children["lengths"] = set() + for element in children["Items"]: + children["lengths"].add(len(element)) return regexes
tests.test_regex_identifier/test_lat_long
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_lat_long(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["52.6169586, -1.9779857"]) <2> _assert_match_first_item("Latitude & Longitude Coordinates", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 3=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 9=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 10=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 11=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 12=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 13=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 14=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() +
tests.test_regex_identifier/test_lat_long2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_lat_long2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["53.76297,-1.9388732"]) <2> _assert_match_first_item("Latitude & Longitude Coordinates", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 10=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 11=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 12=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 13=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 14=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"]
tests.test_regex_identifier/test_lat_long3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_lat_long3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["77\u00B0 30' 29.9988\" N"]) <2> _assert_match_first_item("Latitude & Longitude Coordinates", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 4=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 11=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 12=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 13=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 14=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json
tests.test_regex_identifier/test_lat_long4
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_lat_long4(): <0> r = regex_identifier.RegexIdentifier() <1> # degree symbol has to be a unicode character, otherwise Windows will not understand it <2> res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) <3> _assert_match_first_item("Latitude & Longitude Coordinates", res) <4>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 5=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 12=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 13=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'."
tests.test_regex_identifier/test_lat_long5
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_lat_long5(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) <2> _assert_match_first_item("Latitude & Longitude Coordinates", res) <3>
===========unchanged ref 0=========== at: pywhat.filter Filter(filters_dict: Optional[Mapping]=None) at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_ip res = r.check( ["http://10.1.1.1/just/a/test"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_lat_long4(): - r = regex_identifier.RegexIdentifier() # degree symbol has to be a unicode character, otherwise Windows will not understand it res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 11=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 12=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 13=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 14=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 15=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 16=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 17=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) + ===========changed ref 18=========== # module: pywhat.magic_numbers class FileSignatures: def __init__(self): path = "Data/file_signatures.json" fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) with open(fullpath, "rb") as myfile: + self.file_sigs = json.loads(myfile.read()) - self.file_sigs = json.load(myfile) ===========changed ref 19=========== # module: pywhat.what def print_tags(ctx, opts, value): if value: tags = sorted(AvailableTags().get_tags()) console = Console() + console.print("[bold #D7AFFF]" + "\n".join(tags) + "[/bold #D7AFFF]") - console.print("[bold #D7Afff]" + "\n".join(tags) + "[/bold #D7Afff]") sys.exit()
tests.test_regex_identifier/test_lat_long6
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_lat_long6(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["40.741895,-73.989308"]) <2> _assert_match_first_item("Latitude & Longitude Coordinates", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 6=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_lat_long4(): - r = regex_identifier.RegexIdentifier() # degree symbol has to be a unicode character, otherwise Windows will not understand it res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 14=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name."
tests.test_regex_identifier/test_ip
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ip(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check( <2> ["http://10.1.1.1/just/a/test"], boundaryless=Filter({"Tags": ["Identifiers"]}) <3> ) <4> _assert_match_first_item("Uniform Resource Locator (URL)", res) <5> assert "Internet Protocol (IP) Address Version 4" in res[1]["Regex Pattern"]["Name"] <6>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 7=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_lat_long4(): - r = regex_identifier.RegexIdentifier() # degree symbol has to be a unicode character, otherwise Windows will not understand it res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom."
tests.test_regex_identifier/test_ip_not_url
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ip_not_url(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["http://10.1.1.1"]) <2> assert "Uniform Resource Locator (URL)" not in res[0] <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 7=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ip(): - r = regex_identifier.RegexIdentifier() res = r.check( ["http://10.1.1.1/just/a/test"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) _assert_match_first_item("Uniform Resource Locator (URL)", res) assert "Internet Protocol (IP) Address Version 4" in res[1]["Regex Pattern"]["Name"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_lat_long4(): - r = regex_identifier.RegexIdentifier() # degree symbol has to be a unicode character, otherwise Windows will not understand it res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res)
tests.test_regex_identifier/test_ip2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ip2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["192.0.2.235:80"]) <2> assert "192.0.2.235:80" in res[0]["Matched"] <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 8=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ip(): - r = regex_identifier.RegexIdentifier() res = r.check( ["http://10.1.1.1/just/a/test"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) _assert_match_first_item("Uniform Resource Locator (URL)", res) assert "Internet Protocol (IP) Address Version 4" in res[1]["Regex Pattern"]["Name"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_lat_long4(): - r = regex_identifier.RegexIdentifier() # degree symbol has to be a unicode character, otherwise Windows will not understand it res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res)
tests.test_regex_identifier/test_ip3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ip3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) <2> _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier.test_mac res = r.check(["00:00:00:00:00:00"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 1=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 2=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 7=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ip(): - r = regex_identifier.RegexIdentifier() res = r.check( ["http://10.1.1.1/just/a/test"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) _assert_match_first_item("Uniform Resource Locator (URL)", res) assert "Internet Protocol (IP) Address Version 4" in res[1]["Regex Pattern"]["Name"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_lat_long4(): - r = regex_identifier.RegexIdentifier() # degree symbol has to be a unicode character, otherwise Windows will not understand it res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 16=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 17=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 18=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 19=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 20=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 21=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() + ===========changed ref 22=========== # module: pywhat.helper + def read_json(path: str): + fullpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data/" + path) + with open(fullpath, "rb") as myfile: + return json.loads(myfile.read()) +
tests.test_regex_identifier/test_ip4
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ip4(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["[2001:db8::1]:8080"]) <2> assert "[2001:db8::1]:8080" in res[0]["Matched"] <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier.test_mac2 res = r.check(["00-00-00-00-00-00"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 1=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 8=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ip(): - r = regex_identifier.RegexIdentifier() res = r.check( ["http://10.1.1.1/just/a/test"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) _assert_match_first_item("Uniform Resource Locator (URL)", res) assert "Internet Protocol (IP) Address Version 4" in res[1]["Regex Pattern"]["Name"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_lat_long4(): - r = regex_identifier.RegexIdentifier() # degree symbol has to be a unicode character, otherwise Windows will not understand it res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_regex_successfully_parses(): - r = regex_identifier.RegexIdentifier() assert "Name" in r.distribution.get_regexes()[0] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_url_2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://username:[email protected]/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_dogecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["DANHz6EQVoWyZ9rER56DwTXHWUxfkv9k2o"]) _assert_match_first_item("Dogecoin (DOGE) Wallet Address", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_sorted_by_rarity(): - database = load_regexes() rarity_num = [regex["Rarity"] for regex in database] assert rarity_num == sorted( rarity_num, reverse=True ), "Regexes should be sorted by rarity in 'regex.json'. Regexes with rarity '1' are at the top of the file and '0' is at the bottom." ===========changed ref 17=========== # module: tests.test_regex_identifier def test_if_all_tests_exist(): - database = load_regexes() - with open("tests/test_regex_identifier.py", "r", encoding="utf-8") as file: tests = file.read() for regex in database: assert ( regex["Name"] in tests ), "No test for this regex found in 'test_regex_identifier.py'. Note that a test needs to assert the whole name." ===========changed ref 18=========== # module: tests.test_regex_identifier def test_regex_format(): - database = load_regexes() - for regex in database: assert re.findall( r"^(?:\(\?i\))?\^\(.*\)\$$", regex["Regex"] ), r"Please use ^(regex)$ regex format. If there is '\n' character, you have to escape it. If there is '(?i)', it is allowed and should be before the '^'." assert ( re.findall(r"\^\||\|\^|\$\|\^|\$\||\|\$", regex["Regex"]) == [] ), "Remove in-between boundaries. For example, '^|$' should only be '|'." ===========changed ref 19=========== # module: pywhat.helper """Helper utilities""" + try: + import orjson as json + except ImportError: + import json + ===========changed ref 20=========== # module: pywhat.magic_numbers + + try: + import orjson as json + except ImportError: + import json ===========changed ref 21=========== # module: pywhat + __version__ = "3.3.0" + pywhat_tags = AvailableTags().get_tags() __all__ = ["Identifier", "Distribution", "pywhat_tags", "Keys", "Filter"] ===========changed ref 22=========== # module: pywhat.what + + + def print_version(ctx, opts, value): + if value: + console = Console() + console.print(f"PyWhat version [bold #49C3CE]{__version__}[/bold #49C3CE]") + sys.exit() +
tests.test_regex_identifier/test_mac
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier() <7>:<add> and "Xerox Corp" in res[0]["Regex Pattern"]["Description"]
# module: tests.test_regex_identifier def test_mac(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["00:00:00:00:00:00"]) <2> assert ( <3> res <4> and "00:00:00:00:00:00" in res[0]["Matched"] <5> and res[0]["Regex Pattern"]["Name"] <6> == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" <7> ) <8>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 11=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ip(): - r = regex_identifier.RegexIdentifier() res = r.check( ["http://10.1.1.1/just/a/test"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) _assert_match_first_item("Uniform Resource Locator (URL)", res) assert "Internet Protocol (IP) Address Version 4" in res[1]["Regex Pattern"]["Name"] ===========changed ref 14=========== # module: tests.test_regex_identifier def test_lat_long4(): - r = regex_identifier.RegexIdentifier() # degree symbol has to be a unicode character, otherwise Windows will not understand it res = r.check(["N 32\u00B0 53.733 W 096\u00B0 48.358"]) _assert_match_first_item("Latitude & Longitude Coordinates", res)
tests.test_regex_identifier/test_mac2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier() <7>:<add> and "Xerox Corp" in res[0]["Regex Pattern"]["Description"]
# module: tests.test_regex_identifier def test_mac2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["00-00-00-00-00-00"]) <2> assert ( <3> res <4> and "00-00-00-00-00-00" in res[0]["Matched"] <5> and res[0]["Regex Pattern"]["Name"] <6> == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" <7> ) <8>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_mac(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:00:00:00:00"]) assert ( res and "00:00:00:00:00:00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 12=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_https(): - r = regex_identifier.RegexIdentifier() res = r.check(["hTTPs://tryhackme.com"]) _assert_match_first_item("Uniform Resource Locator (URL)", res)
tests.test_regex_identifier/test_mac3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier() <7>:<add> and "Xerox Corp" in res[0]["Regex Pattern"]["Description"]
# module: tests.test_regex_identifier def test_mac3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["0000.0000.0000"]) <2> assert ( <3> res <4> and "0000.0000.0000" in res[0]["Matched"] <5> and res[0]["Regex Pattern"]["Name"] <6> == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" <7> ) <8>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_mac2(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00-00-00"]) assert ( res and "00-00-00-00-00-00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_mac(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:00:00:00:00"]) assert ( res and "00:00:00:00:00:00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_invalid_tld(): - r = regex_identifier.RegexIdentifier() res = r.check(["tryhackme.comm"]) assert "Uniform Resource Locator (URL)" not in res ===========changed ref 13=========== # module: tests.test_regex_identifier def test_lat_long(): - r = regex_identifier.RegexIdentifier() res = r.check(["52.6169586, -1.9779857"]) _assert_match_first_item("Latitude & Longitude Coordinates", res)
tests.test_regex_identifier/test_mac4
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_mac4(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["00-00-00-00.00-00"]) <2> assert ( <3> not res <4> or res[0]["Regex Pattern"]["Name"] <5> != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" <6> ) <7>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_mac2(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00-00-00"]) assert ( res and "00-00-00-00-00-00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_mac(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:00:00:00:00"]) assert ( res and "00:00:00:00:00:00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] )
tests.test_regex_identifier/test_mac5
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_mac5(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["00:00-00-00-00-00"]) <2> assert ( <3> not res <4> or res[0]["Regex Pattern"]["Name"] <5> != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" <6> ) <7>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_mac2(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00-00-00"]) assert ( res and "00-00-00-00-00-00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_lat_long2(): - r = regex_identifier.RegexIdentifier() res = r.check(["53.76297,-1.9388732"]) _assert_match_first_item("Latitude & Longitude Coordinates", res)
tests.test_regex_identifier/test_mac6
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_mac6(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["00:00:0G:00:00:00"]) <2> assert ( <3> not res <4> or res[0]["Regex Pattern"]["Name"] <5> != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" <6> ) <7>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_mac2(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00-00-00"]) assert ( res and "00-00-00-00-00-00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_lat_long3(): - r = regex_identifier.RegexIdentifier() res = r.check(["77\u00B0 30' 29.9988\" N"]) _assert_match_first_item("Latitude & Longitude Coordinates", res)
tests.test_regex_identifier/test_international_url
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier @pytest.mark.skip( reason="Fails because not a valid TLD. If presented in punycode, it works." ) def test_international_url(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["http://папироска.рф"]) <2> _assert_match_first_item("Uniform Resource Locator (URL)", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_mac2(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00-00-00"]) assert ( res and "00-00-00-00-00-00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_lat_long5(): - r = regex_identifier.RegexIdentifier() res = r.check(["41\u00B024'12.2\" N 2\u00B010'26.5\" E"]) _assert_match_first_item("Latitude & Longitude Coordinates", res)
tests.test_regex_identifier/test_same_international_url_in_punycode
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_same_international_url_in_punycode(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) <2> _assert_match_first_item("Uniform Resource Locator (URL)", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_mac2(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00-00-00"]) assert ( res and "00-00-00-00-00-00" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] )
tests.test_regex_identifier/test_ctf_flag
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ctf_flag(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["thm{hello}"]) <2> _assert_match_first_item("TryHackMe Flag Format", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 3=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] ) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_lat_long6(): - r = regex_identifier.RegexIdentifier() res = r.check(["40.741895,-73.989308"]) _assert_match_first_item("Latitude & Longitude Coordinates", res)
tests.test_regex_identifier/test_ctf_flag_uppercase
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ctf_flag_uppercase(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["FLAG{hello}"]) <2> _assert_match_first_item("Capture The Flag (CTF) Flag", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] )
tests.test_regex_identifier/test_htb_flag
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_htb_flag(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["htb{just_a_test}"]) <2> _assert_match_first_item("HackTheBox Flag Format", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] )
tests.test_regex_identifier/test_ethereum
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ethereum(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) <2> _assert_match_first_item("Ethereum (ETH) Wallet Address", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 6=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res)
tests.test_regex_identifier/test_bitcoin_p2pkh
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_bitcoin_p2pkh(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) <2> _assert_match_first_item("Bitcoin (₿) Wallet Address", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0]
tests.test_regex_identifier/test_bitcoin_p2sh
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_bitcoin_p2sh(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) <2> _assert_match_first_item("Bitcoin (₿) Wallet Address", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"]
tests.test_regex_identifier/test_bitcoin_bech32
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_bitcoin_bech32(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) <2> _assert_match_first_item("Bitcoin (₿) Wallet Address", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"]
tests.test_regex_identifier/test_monero
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_monero(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check( <2> [ <3> "47DF8D9NwtmefhFUghynYRMqrexiZTsm48T1hhi2jZcbfcwoPbkhMrrED6zqJRfeYpXFfdaqAT3jnBEwoMwCx6BYDJ1W3ub" <4> ] <5> ) <6> _assert_match_first_item("Monero (XMR) Wallet Address", res) <7>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_visa_spaces res = r.check(["4607 0000 0000 0009"]) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" )
tests.test_regex_identifier/test_litecoin
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_litecoin(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) <2> _assert_match_first_item("Litecoin (LTC) Wallet Address", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_monero(): - r = regex_identifier.RegexIdentifier() res = r.check( [ "47DF8D9NwtmefhFUghynYRMqrexiZTsm48T1hhi2jZcbfcwoPbkhMrrED6zqJRfeYpXFfdaqAT3jnBEwoMwCx6BYDJ1W3ub" ] ) _assert_match_first_item("Monero (XMR) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" )
tests.test_regex_identifier/test_bitcoincash
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_bitcoincash(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) <2> _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_monero(): - r = regex_identifier.RegexIdentifier() res = r.check( [ "47DF8D9NwtmefhFUghynYRMqrexiZTsm48T1hhi2jZcbfcwoPbkhMrrED6zqJRfeYpXFfdaqAT3jnBEwoMwCx6BYDJ1W3ub" ] ) _assert_match_first_item("Monero (XMR) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res)
tests.test_regex_identifier/test_ripple
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ripple(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) <2> _assert_match_first_item("Ripple (XRP) Wallet Address", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_american_express_spaces res = r.check(["3714 4963 5398 431"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_monero(): - r = regex_identifier.RegexIdentifier() res = r.check( [ "47DF8D9NwtmefhFUghynYRMqrexiZTsm48T1hhi2jZcbfcwoPbkhMrrED6zqJRfeYpXFfdaqAT3jnBEwoMwCx6BYDJ1W3ub" ] ) _assert_match_first_item("Monero (XMR) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_mac4(): - r = regex_identifier.RegexIdentifier() res = r.check(["00-00-00-00.00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_ip4(): - r = regex_identifier.RegexIdentifier() res = r.check(["[2001:db8::1]:8080"]) assert "[2001:db8::1]:8080" in res[0]["Matched"] ===========changed ref 16=========== # module: tests.test_regex_identifier def test_ip2(): - r = regex_identifier.RegexIdentifier() res = r.check(["192.0.2.235:80"]) assert "192.0.2.235:80" in res[0]["Matched"] ===========changed ref 17=========== # module: tests.test_regex_identifier def test_ip_not_url(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://10.1.1.1"]) assert "Uniform Resource Locator (URL)" not in res[0] ===========changed ref 18=========== # module: tests.test_regex_identifier def test_ip3(): - r = regex_identifier.RegexIdentifier() res = r.check(["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]) _assert_match_first_item("Internet Protocol (IP) Address Version 6", res) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_mac3(): - r = regex_identifier.RegexIdentifier() res = r.check(["0000.0000.0000"]) assert ( res and "0000.0000.0000" in res[0]["Matched"] and res[0]["Regex Pattern"]["Name"] == "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" + and "Xerox Corp" in res[0]["Regex Pattern"]["Description"] )
tests.test_regex_identifier/test_visa
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_visa(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["4111111111111111"]) <2> _assert_match_first_item("Visa Card Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res)
tests.test_regex_identifier/test_visa_spaces
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_visa_spaces(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["4607 0000 0000 0009"]) <2> _assert_match_first_item("Visa Card Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res)
tests.test_regex_identifier/test_master_Card
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier() <1>:<add> res = r.check(["5409010000000004"]) <del> res = r.check(["5500000000000004"]) <3>:<add> assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"]
# module: tests.test_regex_identifier def test_master_Card(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["5500000000000004"]) <2> _assert_match_first_item("MasterCard Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res)
tests.test_regex_identifier/test_master_card_spaces
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier() <1>:<del> res = r.check(["5555 5555 5555 4444"]) <2>:<add> res = r.check(["5409 0100 0000 0004"]) <3>:<add> assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"]
# module: tests.test_regex_identifier def test_master_card_spaces(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["5555 5555 5555 4444"]) <2> _assert_match_first_item("MasterCard Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res)
tests.test_regex_identifier/test_american_express
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_american_express(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["340000000000009"]) <2> _assert_match_first_item("American Express Card Number", res) <3>
===========unchanged ref 0=========== at: _pytest.mark.structures MARK_GEN = MarkGenerator(_ispytest=True) at: _pytest.mark.structures.MarkGenerator skip: _SkipMarkDecorator skipif: _SkipifMarkDecorator xfail: _XfailMarkDecorator parametrize: _ParametrizeMarkDecorator usefixtures: _UsefixturesMarkDecorator filterwarnings: _FilterwarningsMarkDecorator at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_maestro_card_spaces res = r.check(["6759 6498 2643 8453"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_monero(): - r = regex_identifier.RegexIdentifier() res = r.check( [ "47DF8D9NwtmefhFUghynYRMqrexiZTsm48T1hhi2jZcbfcwoPbkhMrrED6zqJRfeYpXFfdaqAT3jnBEwoMwCx6BYDJ1W3ub" ] ) _assert_match_first_item("Monero (XMR) Wallet Address", res) ===========changed ref 16=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" )
tests.test_regex_identifier/test_american_express_spaces
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_american_express_spaces(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["3714 4963 5398 431"]) <2> _assert_match_first_item("American Express Card Number", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_username res = r.check(["james:S3cr37_P@$$W0rd"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 4=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ethereum(): - r = regex_identifier.RegexIdentifier() res = r.check(["0x52908400098527886E0F7030069857D2E4169EE7"]) _assert_match_first_item("Ethereum (ETH) Wallet Address", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_same_international_url_in_punycode(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://xn--80aaxitdbjk.xn--p1ai/"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_monero(): - r = regex_identifier.RegexIdentifier() res = r.check( [ "47DF8D9NwtmefhFUghynYRMqrexiZTsm48T1hhi2jZcbfcwoPbkhMrrED6zqJRfeYpXFfdaqAT3jnBEwoMwCx6BYDJ1W3ub" ] ) _assert_match_first_item("Monero (XMR) Wallet Address", res) ===========changed ref 17=========== # module: tests.test_regex_identifier @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://папироска.рф"]) _assert_match_first_item("Uniform Resource Locator (URL)", res) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_mac6(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00:0G:00:00:00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" ) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_mac5(): - r = regex_identifier.RegexIdentifier() res = r.check(["00:00-00-00-00-00"]) assert ( not res or res[0]["Regex Pattern"]["Name"] != "EUI-48 Identifier (Ethernet, WiFi, Bluetooth, etc)" )
tests.test_regex_identifier/test_american_diners_club
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_american_diners_club(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["30000000000004"]) <2> assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res)
tests.test_regex_identifier/test_american_diners_club_spaces
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_american_diners_club_spaces(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["3056 9309 0259 04"]) <2> _assert_match_first_item("Diners Club Card Number", res) <3>
===========unchanged ref 0=========== at: pywhat.filter Filter(filters_dict: Optional[Mapping]=None) at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 3=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res)
tests.test_regex_identifier/test_discover_card
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_discover_card(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["6011000000000004"]) <2> _assert_match_first_item("Discover Card Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 4=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res)
tests.test_regex_identifier/test_discover_card_spaces
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_discover_card_spaces(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["6011 1111 1111 1117"]) <2> _assert_match_first_item("Discover Card Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res)
tests.test_regex_identifier/test_maestro_card
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_maestro_card(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["5038146401278870"]) <2> _assert_match_first_item("Maestro Card Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res)
tests.test_regex_identifier/test_maestro_card_spaces
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_maestro_card_spaces(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["6759 6498 2643 8453"]) <2> _assert_match_first_item("Maestro Card Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res)
tests.test_regex_identifier/test_username
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["james:S3cr37_P@$$W0rd"]) <2> _assert_match_first_item("Key:Value Pair", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res)
tests.test_regex_identifier/test_email
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_email(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["[email protected]"]) <2> _assert_match_first_item("Email Address", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 14=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"]
tests.test_regex_identifier/test_email2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_email2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["[email protected]"]) <2> _assert_match_first_item("Email Address", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_youtube2 res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 1=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res) ===========changed ref 20=========== # module: tests.test_regex_identifier def test_bitcoin_p2sh(): - r = regex_identifier.RegexIdentifier() res = r.check(["3EmUH8Uh9EXE7axgyAeBsCc2vdUdKkDqWK"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 21=========== # module: tests.test_regex_identifier def test_bitcoin_p2pkh(): - r = regex_identifier.RegexIdentifier() res = r.check(["1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 22=========== # module: tests.test_regex_identifier def test_ctf_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["thm{hello}"]) _assert_match_first_item("TryHackMe Flag Format", res)
tests.test_regex_identifier/test_email3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_email3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check( <2> ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) <3> ) <4> assert "Email Address" in res[2]["Regex Pattern"]["Name"] <5>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 4=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"]
tests.test_regex_identifier/test_email4
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_email4(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["email@[email protected]"]) <2> assert "Email Address" not in res <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 5=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res)
tests.test_regex_identifier/test_phone_number
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_phone_number(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["202-555-0178"]) <2> _assert_match_first_item("Phone Number", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_ssn res = r.check(["001-01-0001"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 1=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 4=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 16=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 17=========== # module: tests.test_regex_identifier def test_ripple(): - r = regex_identifier.RegexIdentifier() res = r.check(["rBPAQmwMrt7FDDPNyjwFgwSqbWZPf6SLkk"]) _assert_match_first_item("Ripple (XRP) Wallet Address", res) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_litecoin(): - r = regex_identifier.RegexIdentifier() res = r.check(["LRX8rSPVjifTxoLeoJtLf2JYdJFTQFcE7m"]) _assert_match_first_item("Litecoin (LTC) Wallet Address", res) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_bitcoincash(): - r = regex_identifier.RegexIdentifier() res = r.check(["bitcoincash:qzlg6uvceehgzgtz6phmvy8gtdqyt6vf359at4n3lq"]) _assert_match_first_item("Bitcoin Cash (BCH) Wallet Address", res) ===========changed ref 20=========== # module: tests.test_regex_identifier def test_htb_flag(): - r = regex_identifier.RegexIdentifier() res = r.check(["htb{just_a_test}"]) _assert_match_first_item("HackTheBox Flag Format", res) ===========changed ref 21=========== # module: tests.test_regex_identifier def test_bitcoin_bech32(): - r = regex_identifier.RegexIdentifier() res = r.check(["bc1qj89046x7zv6pm4n00qgqp505nvljnfp6xfznyw"]) _assert_match_first_item("Bitcoin (₿) Wallet Address", res) ===========changed ref 22=========== # module: tests.test_regex_identifier def test_ctf_flag_uppercase(): - r = regex_identifier.RegexIdentifier() res = r.check(["FLAG{hello}"]) _assert_match_first_item("Capture The Flag (CTF) Flag", res)
tests.test_regex_identifier/test_phone_number2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_phone_number2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["+1-202-555-0156"]) <2> _assert_match_first_item("Phone Number", res) <3> assert "United States" in res[0]["Regex Pattern"]["Description"] <4>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 4=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 7=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 14=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res)
tests.test_regex_identifier/test_phone_number3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_phone_number3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["+662025550156"]) <2> _assert_match_first_item("Phone Number", res) <3> assert "Thailand" in res[0]["Regex Pattern"]["Description"] <4>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 4=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 8=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 15=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res)
tests.test_regex_identifier/test_phone_number4
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_phone_number4(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["+356 202 555 0156"]) <2> _assert_match_first_item("Phone Number", res) <3> assert "Malta" in res[0]["Regex Pattern"]["Description"] <4>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() at: tests.test_regex_identifier.test_ssn5 res = r.check(["900-01-2222"]) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 4=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 9=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"]
tests.test_regex_identifier/test_youtube
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_youtube(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) <2> _assert_match_first_item("YouTube Video", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 4=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 5=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 10=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res)
tests.test_regex_identifier/test_youtube2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_youtube2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) <2> _assert_match_first_item("YouTube Video", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 5=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 11=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res)
tests.test_regex_identifier/test_youtube_id
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_youtube_id(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["dQw4w9WgXcQ"]) <2> _assert_match_first_item("YouTube Video ID", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 6=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 12=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res)
tests.test_regex_identifier/test_youtube_id2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_youtube_id2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["078-05-1120"]) <2> assert "YouTube Video ID" not in res <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier.test_ssn10 res = r.check(["122-32-0000"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 5=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 6=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 7=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 11=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 18=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 20=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 21=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 22=========== # module: tests.test_regex_identifier def test_master_Card(): - r = regex_identifier.RegexIdentifier() + res = r.check(["5409010000000004"]) - res = r.check(["5500000000000004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"] ===========changed ref 23=========== # module: tests.test_regex_identifier def test_master_card_spaces(): - r = regex_identifier.RegexIdentifier() - res = r.check(["5555 5555 5555 4444"]) + res = r.check(["5409 0100 0000 0004"]) _assert_match_first_item("MasterCard Number", res) + assert "UNION NATIONAL BANK" in res[0]["Regex Pattern"]["Description"]
tests.test_regex_identifier/test_youtube_channel_id
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_youtube_channel_id(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) <2> _assert_match_first_item("YouTube Channel ID", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 3=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 8=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 14=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res)
tests.test_regex_identifier/test_ssn
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["001-01-0001"]) <2> _assert_match_first_item("American Social Security Number", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_jwt res = r.check( [ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" ] ) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 1=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 7=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 8=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 9=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 13=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 20=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 21=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 22=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 23=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res)
tests.test_regex_identifier/test_ssn2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["001:01:0001"]) <2> _assert_match_first_item("American Social Security Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 4=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 10=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"]
tests.test_regex_identifier/test_ssn3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["001.01.0001"]) <2> _assert_match_first_item("American Social Security Number", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_s3_internal res = r.check(["s3://bucket/path/key"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 3=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 9=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 10=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 11=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 12=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 15=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 20=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 21=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"] ===========changed ref 22=========== # module: tests.test_regex_identifier def test_american_express_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3714 4963 5398 431"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 23=========== # module: tests.test_regex_identifier def test_american_express(): - r = regex_identifier.RegexIdentifier() res = r.check(["340000000000009"]) _assert_match_first_item("American Express Card Number", res) ===========changed ref 24=========== # module: tests.test_regex_identifier def test_visa_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["4607 0000 0000 0009"]) _assert_match_first_item("Visa Card Number", res) ===========changed ref 25=========== # module: tests.test_regex_identifier def test_visa(): - r = regex_identifier.RegexIdentifier() res = r.check(["4111111111111111"]) _assert_match_first_item("Visa Card Number", res)
tests.test_regex_identifier/test_ssn4
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn4(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["001 01 0001"]) <2> _assert_match_first_item("American Social Security Number", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 6=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 12=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 13=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 14=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 15=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res)
tests.test_regex_identifier/test_ssn5
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn5(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["900-01-2222"]) <2> assert "American Social Security Number" not in str(res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 7=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 13=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 14=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 15=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"]
tests.test_regex_identifier/test_ssn6
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn6(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["999-21-2222"]) <2> assert "American Social Security Number" not in str(res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 8=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 14=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 15=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"]
tests.test_regex_identifier/test_ssn7
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn7(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["666-21-2222"]) <2> assert "American Social Security Number" not in str(res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_arn3 res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 7=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 13=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 14=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 15=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 16=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 19=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 20=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 21=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 22=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 23=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 24=========== # module: tests.test_regex_identifier def test_american_diners_club_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["3056 9309 0259 04"]) _assert_match_first_item("Diners Club Card Number", res) ===========changed ref 25=========== # module: tests.test_regex_identifier def test_american_diners_club(): - r = regex_identifier.RegexIdentifier() res = r.check(["30000000000004"]) assert "Diners Club Card Number" in res[1]["Regex Pattern"]["Name"]
tests.test_regex_identifier/test_ssn8
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn8(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["000-21-5544"]) <2> assert "American Social Security Number" not in str(res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 10=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 16=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"]
tests.test_regex_identifier/test_ssn9
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn9(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["122-00-5544"]) <2> assert "American Social Security Number" not in str(res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier.test_unix_timestamp keys = [m["Regex Pattern"]["Name"] for m in res] ===========changed ref 0=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 9=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 15=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 16=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 17=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 18=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 20=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 21=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 22=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 23=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 24=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 25=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res)
tests.test_regex_identifier/test_ssn10
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssn10(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["122-32-0000"]) <2> assert "American Social Security Number" not in str(res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier.test_unix_timestamp2 keys = [m["Regex Pattern"]["Name"] for m in res] ===========changed ref 0=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 10=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 16=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 17=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 18=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 19=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 20=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 21=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 22=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 23=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 24=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 25=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res) ===========changed ref 26=========== # module: tests.test_regex_identifier def test_discover_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011000000000004"]) _assert_match_first_item("Discover Card Number", res)
tests.test_regex_identifier/test_cors
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_cors(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["Access-Control-Allow: *"]) <2> _assert_match_first_item("Access-Control-Allow-Header", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier.test_unix_timestamp3 res = r.check(["1234567"]) # 7 numbers ===========changed ref 0=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 11=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 17=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 18=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 19=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 20=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 21=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 22=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"] ===========changed ref 23=========== # module: tests.test_regex_identifier @pytest.mark.skip("Key:Value Pair is not ran by default because of low rarity.") def test_username(): - r = regex_identifier.RegexIdentifier() res = r.check(["james:S3cr37_P@$$W0rd"]) _assert_match_first_item("Key:Value Pair", res) ===========changed ref 24=========== # module: tests.test_regex_identifier def test_maestro_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6759 6498 2643 8453"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 25=========== # module: tests.test_regex_identifier def test_maestro_card(): - r = regex_identifier.RegexIdentifier() res = r.check(["5038146401278870"]) _assert_match_first_item("Maestro Card Number", res) ===========changed ref 26=========== # module: tests.test_regex_identifier def test_discover_card_spaces(): - r = regex_identifier.RegexIdentifier() res = r.check(["6011 1111 1111 1117"]) _assert_match_first_item("Discover Card Number", res)
tests.test_regex_identifier/test_jwt
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_jwt(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check( <2> [ <3> "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" <4> ] <5> ) <6> _assert_match_first_item("JSON Web Token (JWT)", res) <7>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 14=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res)
tests.test_regex_identifier/test_s3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_s3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["http://s3.amazonaws.com/bucket/"]) <2> _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) <3>
===========unchanged ref 0=========== at: tests.test_regex_identifier.test_unix_timestamp5 keys = [m["Regex Pattern"]["Name"] for m in res] ===========changed ref 0=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 12=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 18=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 19=========== # module: tests.test_regex_identifier def test_jwt(): - r = regex_identifier.RegexIdentifier() res = r.check( [ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" ] ) _assert_match_first_item("JSON Web Token (JWT)", res) ===========changed ref 20=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"] ===========changed ref 21=========== # module: tests.test_regex_identifier def test_phone_number2(): - r = regex_identifier.RegexIdentifier() res = r.check(["+1-202-555-0156"]) _assert_match_first_item("Phone Number", res) assert "United States" in res[0]["Regex Pattern"]["Description"] ===========changed ref 22=========== # module: tests.test_regex_identifier def test_email2(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 23=========== # module: tests.test_regex_identifier def test_email(): - r = regex_identifier.RegexIdentifier() res = r.check(["[email protected]"]) _assert_match_first_item("Email Address", res) ===========changed ref 24=========== # module: tests.test_regex_identifier def test_email3(): - r = regex_identifier.RegexIdentifier() res = r.check( ["john.smith@[123.123.123.123]"], boundaryless=Filter({"Tags": ["Identifiers"]}) ) assert "Email Address" in res[2]["Regex Pattern"]["Name"]
tests.test_regex_identifier/test_s3_internal
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_s3_internal(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["s3://bucket/path/key"]) <2> _assert_match_first_item( <3> "Amazon Web Services Simple Storage (AWS S3) Internal URL", res <4> ) <5>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) ===========unchanged ref 1=========== at: tests.test_regex_identifier.test_ssh_rsa_key res = r.check( [ "ssh-rsa AAAAB3NzaC1tc2EAAAADAQABAAACAQDrnjkGtf3iA46rtwsvRiscvMTCw30l5Mmln/sf8Wohg4RPc7nuIx3/fB86K9jzBNoQk6Fb00p2cSW0dX6c3OTL5R5Q0rBjOFy6GV07MkS7rXa7WYh4ObxBh+M+LEzxVIw29anzQFZkR0TAf6x2rBoErK7JYU4fyqFBDFupTt3coQDPEEmVwtLLUCEnJrurbbnJKcWJ+/FbItLxYyMLPl8TwEn0iqiJ97onCU2DuBtiYv3hp1WoEH08b5WDF0F04zEPRdJT+WisxlEFRgaj51o2BtjOC+D2qZQDb4LHaAfJ0WcO4nu7YocdlcLp2JPfXKKgu9P5J8UDsmXbR3KCJ1oddFa2R6TbHc6d2hKyG4amBzMX5ltxXu7D6FLPZlFqua8YooY7A2zwIVirOUH/cfx+5O9o0CtspkNmj/iYzN0FPaOpELncWsuauy9hrGql/1cF4SUr20zHFoBoDQUtmvmBnWnKoGfpWXzuda449FVtmcrEjvBzCvCb3RStu0BbyOOybJagbKif3MkcYVO10pRbTveIUwgCD6F3ypD11XztoPNsgScmjme0sj/KWWNLyQkLWtpJEQ4k46745NAC</s> ===========changed ref 0=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 13=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 19=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"]
tests.test_regex_identifier/test_s3_internal2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_s3_internal2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["s3://bucket/path/directory/"]) <2> _assert_match_first_item( <3> "Amazon Web Services Simple Storage (AWS S3) Internal URL", res <4> ) <5>
===========unchanged ref 0=========== at: tests.test_regex_identifier _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_ssh_ecdsa_key res = r.check( [ "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCE9Uli8bGnD4hOWdeo5KKQJ/P/vOazI4MgqJK54w37emP2JwOAOdMmXuwpxbKng3KZz27mz+nKWIlXJ3rzSGMo= r00t@my-random_host" ] ) ===========changed ref 0=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 1=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 2=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res ===========changed ref 14=========== # module: tests.test_regex_identifier def test_youtube_channel_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["UCjXfkj5iapKHJrhYfAF9ZGg"]) _assert_match_first_item("YouTube Channel ID", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_youtube_id(): - r = regex_identifier.RegexIdentifier() res = r.check(["dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video ID", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_youtube2(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 17=========== # module: tests.test_regex_identifier def test_youtube(): - r = regex_identifier.RegexIdentifier() res = r.check(["https://www.youtube.com/watch?v=ScOAntcCa78"]) _assert_match_first_item("YouTube Video", res) ===========changed ref 18=========== # module: tests.test_regex_identifier def test_phone_number(): - r = regex_identifier.RegexIdentifier() res = r.check(["202-555-0178"]) _assert_match_first_item("Phone Number", res) ===========changed ref 19=========== # module: tests.test_regex_identifier def test_email4(): - r = regex_identifier.RegexIdentifier() res = r.check(["email@[email protected]"]) assert "Email Address" not in res ===========changed ref 20=========== # module: tests.test_regex_identifier def test_phone_number4(): - r = regex_identifier.RegexIdentifier() res = r.check(["+356 202 555 0156"]) _assert_match_first_item("Phone Number", res) assert "Malta" in res[0]["Regex Pattern"]["Description"] ===========changed ref 21=========== # module: tests.test_regex_identifier def test_jwt(): - r = regex_identifier.RegexIdentifier() res = r.check( [ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" ] ) _assert_match_first_item("JSON Web Token (JWT)", res) ===========changed ref 22=========== # module: tests.test_regex_identifier def test_phone_number3(): - r = regex_identifier.RegexIdentifier() res = r.check(["+662025550156"]) _assert_match_first_item("Phone Number", res) assert "Thailand" in res[0]["Regex Pattern"]["Description"]
tests.test_regex_identifier/test_arn
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_arn(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["arn:partition:service:region:account-id:resource"]) <2> _assert_match_first_item("Amazon Resource Name (ARN)", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_youtube_id2(): - r = regex_identifier.RegexIdentifier() res = r.check(["078-05-1120"]) assert "YouTube Video ID" not in res
tests.test_regex_identifier/test_arn2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_arn2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) <2> _assert_match_first_item("Amazon Resource Name (ARN)", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_ssn(): - r = regex_identifier.RegexIdentifier() res = r.check(["001-01-0001"]) _assert_match_first_item("American Social Security Number", res)
tests.test_regex_identifier/test_arn3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_arn3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) <2> _assert_match_first_item("Amazon Resource Name (ARN)", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_arn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_ssn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["001:01:0001"]) _assert_match_first_item("American Social Security Number", res)
tests.test_regex_identifier/test_arn4
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_arn4(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["arn:aws:s3:::my_corporate_bucket/Development/*"]) <2> _assert_match_first_item("Amazon Resource Name (ARN)", res) <3>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_arn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_arn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_ssn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["001.01.0001"]) _assert_match_first_item("American Social Security Number", res)
tests.test_regex_identifier/test_unix_timestamp
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_unix_timestamp(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["1577836800"]) # 2020-01-01 <2> keys = [m["Regex Pattern"]["Name"] for m in res] <3> assert "Unix Timestamp" in keys <4> assert "Recent Unix Timestamp" in keys <5>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_arn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:aws:s3:::my_corporate_bucket/Development/*"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_arn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_arn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_ssn5(): - r = regex_identifier.RegexIdentifier() res = r.check(["900-01-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 16=========== # module: tests.test_regex_identifier def test_ssn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["001 01 0001"]) _assert_match_first_item("American Social Security Number", res)
tests.test_regex_identifier/test_unix_timestamp2
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_unix_timestamp2(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["94694400"]) # 1973-01-01 <2> keys = [m["Regex Pattern"]["Name"] for m in res] <3> assert "Unix Timestamp" in keys <4> assert "Recent Unix Timestamp" not in keys <5>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_arn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:aws:s3:::my_corporate_bucket/Development/*"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 3=========== # module: tests.test_regex_identifier def test_unix_timestamp(): - r = regex_identifier.RegexIdentifier() res = r.check(["1577836800"]) # 2020-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" in keys ===========changed ref 4=========== # module: tests.test_regex_identifier def test_arn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_arn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn7(): - r = regex_identifier.RegexIdentifier() res = r.check(["666-21-2222"]) assert "American Social Security Number" not in str(res) ===========changed ref 15=========== # module: tests.test_regex_identifier def test_ssn6(): - r = regex_identifier.RegexIdentifier() res = r.check(["999-21-2222"]) assert "American Social Security Number" not in str(res)
tests.test_regex_identifier/test_unix_timestamp3
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_unix_timestamp3(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["1234567"]) # 7 numbers <2> keys = [m["Regex Pattern"]["Name"] for m in res] <3> assert "Unix Timestamp" not in keys <4> assert "Recent Unix Timestamp" not in keys <5>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) at: tests.test_regex_identifier.test_google_api_key res = r.check(["AIzaSyD7CQl6fRhagGok6CzFGOOPne2X1u1spoA"]) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_unix_timestamp2(): - r = regex_identifier.RegexIdentifier() res = r.check(["94694400"]) # 1973-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" not in keys ===========changed ref 3=========== # module: tests.test_regex_identifier def test_arn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:aws:s3:::my_corporate_bucket/Development/*"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 4=========== # module: tests.test_regex_identifier def test_unix_timestamp(): - r = regex_identifier.RegexIdentifier() res = r.check(["1577836800"]) # 2020-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" in keys ===========changed ref 5=========== # module: tests.test_regex_identifier def test_arn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_arn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn8(): - r = regex_identifier.RegexIdentifier() res = r.check(["000-21-5544"]) assert "American Social Security Number" not in str(res)
tests.test_regex_identifier/test_unix_timestamp4
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_unix_timestamp4(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["1577836800000"]) # 2020-01-01 <2> keys = [m["Regex Pattern"]["Name"] for m in res] <3> assert "Unix Millisecond Timestamp" in keys <4> assert "Recent Unix Millisecond Timestamp" in keys <5>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_unix_timestamp3(): - r = regex_identifier.RegexIdentifier() res = r.check(["1234567"]) # 7 numbers keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" not in keys assert "Recent Unix Timestamp" not in keys ===========changed ref 3=========== # module: tests.test_regex_identifier def test_unix_timestamp2(): - r = regex_identifier.RegexIdentifier() res = r.check(["94694400"]) # 1973-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" not in keys ===========changed ref 4=========== # module: tests.test_regex_identifier def test_arn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:aws:s3:::my_corporate_bucket/Development/*"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 5=========== # module: tests.test_regex_identifier def test_unix_timestamp(): - r = regex_identifier.RegexIdentifier() res = r.check(["1577836800"]) # 2020-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" in keys ===========changed ref 6=========== # module: tests.test_regex_identifier def test_arn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_arn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn9(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-00-5544"]) assert "American Social Security Number" not in str(res)
tests.test_regex_identifier/test_unix_timestamp5
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_unix_timestamp5(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check(["94694400000"]) # 1973-01-01 <2> keys = [m["Regex Pattern"]["Name"] for m in res] <3> assert "Unix Millisecond Timestamp" in keys <4> assert "Recent Unix Millisecond Timestamp" not in keys <5>
===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_unix_timestamp4(): - r = regex_identifier.RegexIdentifier() res = r.check(["1577836800000"]) # 2020-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Millisecond Timestamp" in keys assert "Recent Unix Millisecond Timestamp" in keys ===========changed ref 3=========== # module: tests.test_regex_identifier def test_unix_timestamp3(): - r = regex_identifier.RegexIdentifier() res = r.check(["1234567"]) # 7 numbers keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" not in keys assert "Recent Unix Timestamp" not in keys ===========changed ref 4=========== # module: tests.test_regex_identifier def test_unix_timestamp2(): - r = regex_identifier.RegexIdentifier() res = r.check(["94694400"]) # 1973-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" not in keys ===========changed ref 5=========== # module: tests.test_regex_identifier def test_arn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:aws:s3:::my_corporate_bucket/Development/*"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 6=========== # module: tests.test_regex_identifier def test_unix_timestamp(): - r = regex_identifier.RegexIdentifier() res = r.check(["1577836800"]) # 2020-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" in keys ===========changed ref 7=========== # module: tests.test_regex_identifier def test_arn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 8=========== # module: tests.test_regex_identifier def test_arn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_cors(): - r = regex_identifier.RegexIdentifier() res = r.check(["Access-Control-Allow: *"]) _assert_match_first_item("Access-Control-Allow-Header", res) ===========changed ref 14=========== # module: tests.test_regex_identifier def test_ssn10(): - r = regex_identifier.RegexIdentifier() res = r.check(["122-32-0000"]) assert "American Social Security Number" not in str(res)
tests.test_regex_identifier/test_ssh_rsa_key
Modified
bee-san~pyWhat
69425bb20360a6b57a8f22d43c9a31a33564d9c4
Merge branch 'main' into subcategories
<0>:<del> r = regex_identifier.RegexIdentifier()
# module: tests.test_regex_identifier def test_ssh_rsa_key(): <0> r = regex_identifier.RegexIdentifier() <1> res = r.check( <2> [ <3> "ssh-rsa AAAAB3NzaC1tc2EAAAADAQABAAACAQDrnjkGtf3iA46rtwsvRiscvMTCw30l5Mmln/sf8Wohg4RPc7nuIx3/fB86K9jzBNoQk6Fb00p2cSW0dX6c3OTL5R5Q0rBjOFy6GV07MkS7rXa7WYh4ObxBh+M+LEzxVIw29anzQFZkR0TAf6x2rBoErK7JYU4fyqFBDFupTt3coQDPEEmVwtLLUCEnJrurbbnJKcWJ+/FbItLxYyMLPl8TwEn0iqiJ97onCU2DuBtiYv3hp1WoEH08b5WDF0F04zEPRdJT+WisxlEFRgaj51o2BtjOC+D2qZQDb4LHaAfJ0WcO4nu7YocdlcLp2JPfXKKgu9P5J8UDsmXbR3KCJ1oddFa2R6TbHc6d2hKyG4amBzMX5ltxXu7D6FLPZlFqua8YooY7A2zwIVirOUH/cfx+5O9o0CtspkNmj/iYzN0FPaOpELncWsuauy9hrGql/1cF4SUr20zHFoBoDQUtmvmBnWnKoGfpWXzuda449FVtmcrEjvBzCvCb3RStu0BbyOOybJagbKif3MkcYVO10pRbTveIUwgCD6F3ypD11XztoPNsgScmjme0sj/</s>
===========below chunk 0=========== # module: tests.test_regex_identifier def test_ssh_rsa_key(): # offset: 1 ] ) _assert_match_first_item("SSH RSA Public Key", res) ===========unchanged ref 0=========== at: pywhat.regex_identifier.RegexIdentifier check(text, dist: Optional[Distribution]=None, *, boundaryless: Optional[Filter]=None) at: tests.test_regex_identifier r = regex_identifier.RegexIdentifier() _assert_match_first_item(name, res) ===========changed ref 0=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): if dist is None: dist = self.distribution if boundaryless is None: boundaryless = Filter({"Tags": []}) matches = [] for string in text: for reg in dist.get_regexes(): regex = ( reg["Boundaryless Regex"] if reg in boundaryless else reg["Regex"] ) for matched_regex in re.finditer(regex, string, re.MULTILINE): - reg = copy.copy(reg) # necessary, when checking phone - # numbers from file that may contain - # non-international numbers + reg = copy.copy(reg) matched = self.clean_text(matched_regex.group(0)) - if "Phone Number" in reg["Name"]: - number = re.sub(r"[-() ]", "", matched) - codes_path = "Data/phone_codes.json" - codes_fullpath = os.path.join( - os.path.dirname(os.path.abspath(__file__)), codes_path + children = reg.get("Children") + if children is not None: + processed_match = re.sub( + children.get("deletion_pattern", ""), "", matched ) + matched_children = [] + if children["method"] == "hashmap": + for length in children["lengths"]: + try: + matched_children.append( + children["Items"][processed_match[:length]] + ) + except KeyError: + continue + else: + for element in children["Items"]: + if ( + children["method"] == "regex" + and re.search( + element, processed_match, re.MULTILINE + ) + )</s> ===========changed ref 1=========== # module: pywhat.regex_identifier class RegexIdentifier: def check( self, text, dist: Optional[Distribution] = None, *, boundaryless: Optional[Filter] = None ): # offset: 1 <s> and re.search( + element, processed_match, re.MULTILINE + ) + ) or ( + children["method"] == "startswith" + and processed_match.startswith(element) + ): + matched_children.append(children["Items"][element]) - with open(codes_fullpath, "rb") as myfile: - codes = json.load(myfile) - locations = [] - for code in codes: - if number.startswith(code["dial_code"]): - locations.append(code["name"]) - if len(locations) > 0: - reg["Description"] = ( - "Location(s)" + ": " + ", ".join(locations) + if matched_children: + reg["Description"] = children.get("entry", "") + ", ".join( + matched_children ) matches.append( { "Matched": matched, "Regex Pattern": reg, } ) return matches ===========changed ref 2=========== # module: tests.test_regex_identifier def test_unix_timestamp5(): - r = regex_identifier.RegexIdentifier() res = r.check(["94694400000"]) # 1973-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Millisecond Timestamp" in keys assert "Recent Unix Millisecond Timestamp" not in keys ===========changed ref 3=========== # module: tests.test_regex_identifier def test_unix_timestamp4(): - r = regex_identifier.RegexIdentifier() res = r.check(["1577836800000"]) # 2020-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Millisecond Timestamp" in keys assert "Recent Unix Millisecond Timestamp" in keys ===========changed ref 4=========== # module: tests.test_regex_identifier def test_unix_timestamp3(): - r = regex_identifier.RegexIdentifier() res = r.check(["1234567"]) # 7 numbers keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" not in keys assert "Recent Unix Timestamp" not in keys ===========changed ref 5=========== # module: tests.test_regex_identifier def test_unix_timestamp2(): - r = regex_identifier.RegexIdentifier() res = r.check(["94694400"]) # 1973-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" not in keys ===========changed ref 6=========== # module: tests.test_regex_identifier def test_arn4(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:aws:s3:::my_corporate_bucket/Development/*"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 7=========== # module: tests.test_regex_identifier def test_unix_timestamp(): - r = regex_identifier.RegexIdentifier() res = r.check(["1577836800"]) # 2020-01-01 keys = [m["Regex Pattern"]["Name"] for m in res] assert "Unix Timestamp" in keys assert "Recent Unix Timestamp" in keys ===========changed ref 8=========== # module: tests.test_regex_identifier def test_arn3(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 9=========== # module: tests.test_regex_identifier def test_arn2(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resourcetype/resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 10=========== # module: tests.test_regex_identifier def test_arn(): - r = regex_identifier.RegexIdentifier() res = r.check(["arn:partition:service:region:account-id:resource"]) _assert_match_first_item("Amazon Resource Name (ARN)", res) ===========changed ref 11=========== # module: tests.test_regex_identifier def test_s3_internal2(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/directory/"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 12=========== # module: tests.test_regex_identifier def test_s3_internal(): - r = regex_identifier.RegexIdentifier() res = r.check(["s3://bucket/path/key"]) _assert_match_first_item( "Amazon Web Services Simple Storage (AWS S3) Internal URL", res ) ===========changed ref 13=========== # module: tests.test_regex_identifier def test_s3(): - r = regex_identifier.RegexIdentifier() res = r.check(["http://s3.amazonaws.com/bucket/"]) _assert_match_first_item("Amazon Web Services Simple Storage (AWS S3) URL", res)