Skip to content

Commit b663791

Browse files
committed
Fix python code style
1 parent aed5d21 commit b663791

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed
Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
import re
2+
23
from .base import RegexBasedDetector
34

4-
class EmailAddressDetector(RegexBasedDetector):
5-
"""Email Address Detector.
65

7-
This class is designed to efficiently and accurately detect email addresses within given text. It primarily
8-
validates the general format of email addresses, and does not adhere strictly to email format standards such as RFC 5322.
6+
class EmailAddressDetector(RegexBasedDetector):
7+
"""
8+
A detector for identifying email addresses within text. It uses regular expressions to
9+
focus on general email structures, not strictly adhering to standards like RFC 5322.
10+
Designed for efficient and broad detection, it also has some limitations.
911
10-
Key Features:
11-
- Ignores common, non-security-threatening email addresses to enhance precision.
12+
Features:
13+
- Detects a wide range of email formats efficiently.
14+
- Ignores common, non-critical emails to minimize false positives.
1215
1316
Limitations:
14-
- Despite robust detection mechanisms, the class is not infallible and may not cover all edge cases.
15-
- It does not support some examples from RFC 6530, e.g., email addresses with Greek alphabets.
17+
- May miss edge cases or unconventional email formats.
18+
- Not compliant with advanced formats, e.g., RFC 6530 non-Latin emails.
1619
17-
References:
20+
Regular Expression:
21+
Utilizes a regex pattern focusing on typical email components: local part, domain, TLD.
22+
Excludes predefined whitelist emails to reduce false positives.
23+
24+
References:
1825
- https://en.wikipedia.org/wiki/Email_address
1926
- https://stackoverflow.com/a/14321045
2027
"""
2128
secret_type = 'Email Address'
2229

23-
2430
# Excluses whitelist email addresses from detection to reduce false positives.
31+
2532

2633
base_pattern = r"""
2734
[\w+-]+ # Local part before the @ symbol
@@ -32,21 +39,23 @@ class EmailAddressDetector(RegexBasedDetector):
3239
(?:\.[a-zA-Z]{2,4}) # TLD part
3340
"""
3441
# Pattern Breakdown:
35-
# 1. [\w+-]+: Matches one or more of a-z, A-Z, _, +, -
42+
# 1. [\w+-]+: Matches one or more of a-z, A-Z, _, +, -
3643
# Represents the local part of the email address before the @ symbol.
3744
# 2. (?:\.[\w+-]+)*: Matches zero or more of a-z, A-Z, _, +, -, but must start with a . (dot)
3845
# Allows for dot-separated words in the local part of the email address.
3946
# 3. @: Matches the @ symbol.
40-
# 4. [\w+-]+: Matches one or more of a-z, A-Z, _, +, -
47+
# 4. [\w+-]+: Matches one or more of a-z, A-Z, _, +, -
4148
# Represents the domain part of the email address after the @ symbol.
4249
# 5. (?:\.[\w+-]+)*: Matches zero or more of a-z, A-Z, _, +, -, but must start with a . (dot)
4350
# Allows for dot-separated words in the domain part of the email address.
4451
# 6. (?:\.[a-zA-Z]{2,4}): Matches 2 to 4 instances of a-z, A-Z, starting with a . (dot)
4552
# Represents the TLD (top-level domain) part of the email address.
4653

47-
deny_pattern = r"(?!" + "|".join(re.escape(email) for email in whitelist) + r"$)" + base_pattern
54+
deny_pattern = r'(?!' \
55+
+ '|'.join(re.escape(email) for email in whitelist) \
56+
+ r'$)' + base_pattern
4857
# Combines the base pattern with a negative lookahead to exclude whitelist email addresses.
4958

5059
denylist = [
51-
re.compile(r"\b" + deny_pattern + r"\b", flags=re.VERBOSE)
60+
re.compile(r'\b' + deny_pattern + r'\b', flags=re.VERBOSE),
5261
]

tests/plugins/email_address_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
23
from detect_secrets.plugins.email_address import EmailAddressDetector
34

45

0 commit comments

Comments
 (0)