Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5596a8c1
Commit
5596a8c1
authored
Mar 15, 2011
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Plain Diff
Merge with remote
parents
d25fd4d7
ba3a978f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
52 deletions
+99
-52
Lib/email/generator.py
Lib/email/generator.py
+5
-2
Lib/email/header.py
Lib/email/header.py
+1
-1
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+34
-1
Lib/urllib/request.py
Lib/urllib/request.py
+56
-48
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/email/generator.py
View file @
5596a8c1
...
@@ -59,7 +59,7 @@ class Generator:
...
@@ -59,7 +59,7 @@ class Generator:
self
.
_fp
.
write
(
s
)
self
.
_fp
.
write
(
s
)
def
flatten
(
self
,
msg
,
unixfrom
=
False
,
linesep
=
'
\
n
'
):
def
flatten
(
self
,
msg
,
unixfrom
=
False
,
linesep
=
'
\
n
'
):
"""Print the message object tree rooted at msg to the output file
r
"""Print the message object tree rooted at msg to the output file
specified when the Generator instance was created.
specified when the Generator instance was created.
unixfrom is a flag that forces the printing of a Unix From_ delimiter
unixfrom is a flag that forces the printing of a Unix From_ delimiter
...
@@ -70,7 +70,10 @@ class Generator:
...
@@ -70,7 +70,10 @@ class Generator:
Note that for subobjects, no From_ line is printed.
Note that for subobjects, no From_ line is printed.
linesep specifies the characters used to indicate a new line in
linesep specifies the characters used to indicate a new line in
the output.
the output. The default value is the most useful for typical
Python applications, but it can be set to \r\n to produce RFC-compliant
line separators when needed.
"""
"""
# We use the _XXX constants for operating on data that comes directly
# We use the _XXX constants for operating on data that comes directly
# from the msg, and _encoded_XXX constants for operating on data that
# from the msg, and _encoded_XXX constants for operating on data that
...
...
Lib/email/header.py
View file @
5596a8c1
...
@@ -276,7 +276,7 @@ class Header:
...
@@ -276,7 +276,7 @@ class Header:
self
.
_chunks
.
append
((
s
,
charset
))
self
.
_chunks
.
append
((
s
,
charset
))
def
encode
(
self
,
splitchars
=
';,
\
t
'
,
maxlinelen
=
None
,
linesep
=
'
\
n
'
):
def
encode
(
self
,
splitchars
=
';,
\
t
'
,
maxlinelen
=
None
,
linesep
=
'
\
n
'
):
"""Encode a message header into an RFC-compliant format.
r
"""Encode a message header into an RFC-compliant format.
There are many issues involved in converting a given string for use in
There are many issues involved in converting a given string for use in
an email header. Only certain character sets are readable in most
an email header. Only certain character sets are readable in most
...
...
Lib/test/test_urllib2.py
View file @
5596a8c1
...
@@ -7,7 +7,9 @@ import socket
...
@@ -7,7 +7,9 @@ import socket
import
array
import
array
import
urllib.request
import
urllib.request
from
urllib.request
import
Request
,
OpenerDirector
# The proxy bypass method imported below has logic specific to the OSX
# proxy config data structure but is testable on all platforms.
from
urllib.request
import
Request
,
OpenerDirector
,
_proxy_bypass_macosx_sysconf
# XXX
# XXX
# Request
# Request
...
@@ -1076,6 +1078,17 @@ class HandlerTests(unittest.TestCase):
...
@@ -1076,6 +1078,17 @@ class HandlerTests(unittest.TestCase):
self
.
assertEqual
(
req
.
get_host
(),
"www.python.org"
)
self
.
assertEqual
(
req
.
get_host
(),
"www.python.org"
)
del
os
.
environ
[
'no_proxy'
]
del
os
.
environ
[
'no_proxy'
]
def
test_proxy_no_proxy_all
(
self
):
os
.
environ
[
'no_proxy'
]
=
'*'
o
=
OpenerDirector
()
ph
=
urllib
.
request
.
ProxyHandler
(
dict
(
http
=
"proxy.example.com"
))
o
.
add_handler
(
ph
)
req
=
Request
(
"http://www.python.org"
)
self
.
assertEqual
(
req
.
get_host
(),
"www.python.org"
)
r
=
o
.
open
(
req
)
self
.
assertEqual
(
req
.
get_host
(),
"www.python.org"
)
del
os
.
environ
[
'no_proxy'
]
def
test_proxy_https
(
self
):
def
test_proxy_https
(
self
):
o
=
OpenerDirector
()
o
=
OpenerDirector
()
...
@@ -1116,6 +1129,26 @@ class HandlerTests(unittest.TestCase):
...
@@ -1116,6 +1129,26 @@ class HandlerTests(unittest.TestCase):
self
.
assertEqual
(
req
.
get_host
(),
"proxy.example.com:3128"
)
self
.
assertEqual
(
req
.
get_host
(),
"proxy.example.com:3128"
)
self
.
assertEqual
(
req
.
get_header
(
"Proxy-authorization"
),
"FooBar"
)
self
.
assertEqual
(
req
.
get_header
(
"Proxy-authorization"
),
"FooBar"
)
def
test_osx_proxy_bypass
(
self
):
bypass
=
{
'exclude_simple'
:
False
,
'exceptions'
:
[
'foo.bar'
,
'*.bar.com'
,
'127.0.0.1'
,
'10.10'
,
'10.0/16'
]
}
# Check hosts that should trigger the proxy bypass
for
host
in
(
'foo.bar'
,
'www.bar.com'
,
'127.0.0.1'
,
'10.10.0.1'
,
'10.0.0.1'
):
self
.
assertTrue
(
_proxy_bypass_macosx_sysconf
(
host
,
bypass
),
'expected bypass of %s to be True'
%
host
)
# Check hosts that should not trigger the proxy bypass
for
host
in
(
'abc.foo.bar'
,
'bar.com'
,
'127.0.0.2'
,
'10.11.0.1'
,
'test'
):
self
.
assertFalse
(
_proxy_bypass_macosx_sysconf
(
host
,
bypass
),
'expected bypass of %s to be False'
%
host
)
# Check the exclude_simple flag
bypass
=
{
'exclude_simple'
:
True
,
'exceptions'
:
[]}
self
.
assertTrue
(
_proxy_bypass_macosx_sysconf
(
'test'
,
bypass
))
def
test_basic_auth
(
self
,
quote_char
=
'"'
):
def
test_basic_auth
(
self
,
quote_char
=
'"'
):
opener
=
OpenerDirector
()
opener
=
OpenerDirector
()
password_manager
=
MockPasswordManager
()
password_manager
=
MockPasswordManager
()
...
...
Lib/urllib/request.py
View file @
5596a8c1
...
@@ -2208,68 +2208,76 @@ def proxy_bypass_environment(host):
...
@@ -2208,68 +2208,76 @@ def proxy_bypass_environment(host):
return
0
return
0
if
sys
.
platform
==
'darwin'
:
# This code tests an OSX specific data structure but is testable on all
from
_scproxy
import
_get_proxy_settings
,
_get_proxies
# platforms
def
_proxy_bypass_macosx_sysconf
(
host
,
proxy_settings
):
def
proxy_bypass_macosx_sysconf
(
host
):
"""
"""
Return True iff this host shouldn't be accessed using a proxy
Return True iff this host shouldn't be accessed using a proxy
This function uses the MacOSX framework SystemConfiguration
This function uses the MacOSX framework SystemConfiguration
to fetch the proxy information.
to fetch the proxy information.
"""
import
re
import
socket
from
fnmatch
import
fnmatch
hostonly
,
port
=
splitport
(
host
)
proxy_settings come from _scproxy._get_proxy_settings or get mocked ie:
{ 'exclude_simple': bool,
'exceptions': ['foo.bar', '*.bar.com', '127.0.0.1', '10.1', '10.0/16']
}
"""
import
re
import
socket
from
fnmatch
import
fnmatch
def
ip2num
(
ipAddr
):
hostonly
,
port
=
splitport
(
host
)
parts
=
ipAddr
.
split
(
'.'
)
parts
=
list
(
map
(
int
,
parts
))
if
len
(
parts
)
!=
4
:
parts
=
(
parts
+
[
0
,
0
,
0
,
0
])[:
4
]
return
(
parts
[
0
]
<<
24
)
|
(
parts
[
1
]
<<
16
)
|
(
parts
[
2
]
<<
8
)
|
parts
[
3
]
proxy_settings
=
_get_proxy_settings
()
def
ip2num
(
ipAddr
):
parts
=
ipAddr
.
split
(
'.'
)
parts
=
list
(
map
(
int
,
parts
))
if
len
(
parts
)
!=
4
:
parts
=
(
parts
+
[
0
,
0
,
0
,
0
])[:
4
]
return
(
parts
[
0
]
<<
24
)
|
(
parts
[
1
]
<<
16
)
|
(
parts
[
2
]
<<
8
)
|
parts
[
3
]
# Check for simple host names:
# Check for simple host names:
if
'.'
not
in
host
:
if
'.'
not
in
host
:
if
proxy_settings
[
'exclude_simple'
]:
if
proxy_settings
[
'exclude_simple'
]:
return
True
return
True
hostIP
=
None
hostIP
=
None
for
value
in
proxy_settings
.
get
(
'exceptions'
,
()):
for
value
in
proxy_settings
.
get
(
'exceptions'
,
()):
# Items in the list are strings like these: *.local, 169.254/16
# Items in the list are strings like these: *.local, 169.254/16
if
not
value
:
continue
if
not
value
:
continue
m
=
re
.
match
(
r"(\
d+(?:
\.\
d+)*)(/
\d+)?"
,
value
)
m
=
re
.
match
(
r"(\
d+(?:
\.\
d+)*)(/
\d+)?"
,
value
)
if
m
is
not
None
:
if
m
is
not
None
:
if
hostIP
is
None
:
if
hostIP
is
None
:
try
:
try
:
hostIP
=
socket
.
gethostbyname
(
hostonly
)
hostIP
=
socket
.
gethostbyname
(
hostonly
)
hostIP
=
ip2num
(
hostIP
)
hostIP
=
ip2num
(
hostIP
)
except
socket
.
error
:
except
socket
.
error
:
continue
continue
base
=
ip2num
(
m
.
group
(
1
))
mask
=
m
.
group
(
2
)
if
mask
is
None
:
mask
=
8
*
(
m
.
group
(
1
).
count
(
'.'
)
+
1
)
else
:
mask
=
int
(
mask
[
1
:])
mask
=
32
-
mask
base
=
ip2num
(
m
.
group
(
1
))
if
(
hostIP
>>
mask
)
==
(
base
>>
mask
):
mask
=
m
.
group
(
2
)
return
True
if
mask
is
None
:
mask
=
8
*
(
m
.
group
(
1
).
count
(
'.'
)
+
1
)
else
:
elif
fnmatch
(
host
,
value
):
mask
=
int
(
mask
[
1
:])
return
True
mask
=
32
-
mask
if
(
hostIP
>>
mask
)
==
(
base
>>
mask
):
return
False
return
True
elif
fnmatch
(
host
,
value
):
return
True
return
False
if
sys
.
platform
==
'darwin'
:
from
_scproxy
import
_get_proxy_settings
,
_get_proxies
def
proxy_bypass_macosx_sysconf
(
host
):
proxy_settings
=
_get_proxy_settings
()
return
_proxy_bypass_macosx_sysconf
(
host
,
proxy_settings
)
def
getproxies_macosx_sysconf
():
def
getproxies_macosx_sysconf
():
"""Return a dictionary of scheme -> proxy server URL mappings.
"""Return a dictionary of scheme -> proxy server URL mappings.
...
...
Misc/NEWS
View file @
5596a8c1
...
@@ -68,6 +68,9 @@ Core and Builtins
...
@@ -68,6 +68,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
11500
:
Fixed
a
bug
in
the
os
x
proxy
bypass
code
for
fully
qualified
IP
addresses
in
the
proxy
exception
list
.
-
Issue
#
11491
:
dbm
.
error
is
no
longer
raised
when
dbm
.
open
is
called
with
-
Issue
#
11491
:
dbm
.
error
is
no
longer
raised
when
dbm
.
open
is
called
with
the
"n"
as
the
flag
argument
and
the
file
exists
.
The
behavior
matches
the
"n"
as
the
flag
argument
and
the
file
exists
.
The
behavior
matches
the
documentation
and
general
logic
.
the
documentation
and
general
logic
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment