Miscellaneous functions.
More...
Functions |
def | addr2bin |
def | bin2long6 |
def | inet_ntop |
def | inet_pton |
def | cidr |
def | iniplist |
def | parseaddr |
| Split email into Fullname and address.
|
def | parse_addr |
def | parse_header |
| Decode headers gratuitously encoded to hide the content.
|
Variables |
string | PAT_IP4 = r'\.' |
tuple | ip4re = re.compile(PAT_IP4+'$') |
tuple | ip6re |
int | MASK = 0xFFFFFFFFL |
int | MASK6 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL |
Detailed Description
Function Documentation
Convert a string IPv4 address into an unsigned integer.
Convert binary IP6 address into an unsigned Python long integer.
Return whether ip is in cidr list
>>> iniplist('66.179.26.146',['127.0.0.1','66.179.26.128/26'])
True
>>> iniplist('127.0.0.1',['127.0.0.1','66.179.26.128/26'])
True
>>> iniplist('192.168.0.45',['192.168.0.*'])
True
>>> iniplist('2001:610:779:0:223:6cff:fe9a:9cf3',['127.0.0.1','172.20.1.0/24','2001:610:779::/48'])
True
>>> iniplist('2G01:610:779:0:223:6cff:fe9a:9cf3',['127.0.0.1','172.20.1.0/24','2001:610:779::/48'])
Traceback (most recent call last):
...
ValueError: Invalid ip syntax:2G01:610:779:0:223:6cff:fe9a:9cf3
Split email into user,domain.
>>> parse_addr('user@example.com')
['user', 'example.com']
>>> parse_addr('"user@example.com"')
['user@example.com']
>>> parse_addr('"user@bar"@example.com')
['user@bar', 'example.com']
>>> parse_addr('foo')
['foo']
>>> parse_addr('@mx.example.com:user@example.com')
['user', 'example.com']
>>> parse_addr('@user@example.com')
['@user', 'example.com']
Decode headers gratuitously encoded to hide the content.
Spammers often encode headers to obscure the content from spam filters. This function decodes gratuitously encoded headers.
- Parameters:
-
- Returns:
- the decoded value or the original raw value
Decode headers gratuitously encoded to hide the content.
Split email into Fullname and address.
This replaces email.Utils.parseaddr
but fixes some tricky test cases.
Split email into Fullname and address.
>>> parseaddr('user@example.com')
('', 'user@example.com')
>>> parseaddr('"Full Name" <foo@example.com>')
('Full Name', 'foo@example.com')
>>> parseaddr('spam@spammer.com <foo@example.com>')
('spam@spammer.com', 'foo@example.com')
>>> parseaddr('God@heaven <@hop1.org,@hop2.net:jeff@spec.org>')
('God@heaven', 'jeff@spec.org')
>>> parseaddr('Real Name ((comment)) <addr...@example.com>')
('Real Name', 'addr...@example.com')
>>> parseaddr('a(WRONG)@b')
('WRONG', 'a@b')
Variable Documentation
tuple Milter::utils::ip6re |
Initial value:00001 re.compile( '(?:%(hex4)s:){6}%(ls32)s$'
00002 '|::(?:%(hex4)s:){5}%(ls32)s$'
00003 '|(?:%(hex4)s)?::(?:%(hex4)s:){4}%(ls32)s$'
00004 '|(?:(?:%(hex4)s:){0,1}%(hex4)s)?::(?:%(hex4)s:){3}%(ls32)s$'
00005 '|(?:(?:%(hex4)s:){0,2}%(hex4)s)?::(?:%(hex4)s:){2}%(ls32)s$'
00006 '|(?:(?:%(hex4)s:){0,3}%(hex4)s)?::%(hex4)s:%(ls32)s$'
00007 '|(?:(?:%(hex4)s:){0,4}%(hex4)s)?::%(ls32)s$'
00008 '|(?:(?:%(hex4)s:){0,5}%(hex4)s)?::%(hex4)s$'
00009 '|(?:(?:%(hex4)s:){0,6}%(hex4)s)?::$'
00010 % {
00011 'ls32': r'(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|%s)'%PAT_IP4,
00012 'hex4': r'[0-9a-f]{1,4}'
00013 }, re.IGNORECASE)