mirror of
https://github.com/disposable-email-domains/disposable-email-domains.git
synced 2024-11-25 10:08:12 +08:00
Improvements for the Python example code (#329)
* docs(readme): Fix missing `open()` in Python example code * docs(readme): Use set instead of list in Python example code This reduces the computational complexity of a list lookup from O(n) to O(1). * docs(readme): Replace `split()` with `partition()` in Python example The will always work and never throw an exception, even if `email` is in fact not a valid email address or doesn't contain an `@` character at all. It also prevents unexpected behavior if `email` contains multiple `@` signs, i.e.: | `email` | Lookup Before | Lookup After | | ------------- | ------------- | ------------- | | 'foo@bar' | 'bar' | 'bar' | | 'foo@bar@baz' | 'bar' | 'bar@baz' | | 'foo' | *Exception* | '' |
This commit is contained in:
parent
2258b1b6f9
commit
f3fa1f0720
@ -15,9 +15,9 @@ Example Usage
|
||||
=============
|
||||
**Python**
|
||||
```Python
|
||||
blocklist = ('disposable_email_blocklist.conf')
|
||||
blocklist_content = [line.rstrip() for line in blocklist.readlines()]
|
||||
if email.split('@')[1] in blocklist_content:
|
||||
with open('disposable_email_blocklist.conf') as blocklist:
|
||||
blocklist_content = {line.rstrip() for line in blocklist.readlines()}
|
||||
if email.partition('@')[2] in blocklist_content:
|
||||
message = "Please enter your permanent email address."
|
||||
return (False, message)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user