Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
040a927c
Kaydet (Commit)
040a927c
authored
Kas 12, 2006
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1065257: Support passing open files as body in
HTTPConnection.request().
üst
1ee79f16
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
3 deletions
+44
-3
libhttplib.tex
Doc/lib/libhttplib.tex
+5
-0
httplib.py
Lib/httplib.py
+24
-2
test_httplib.py
Lib/test/test_httplib.py
+12
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libhttplib.tex
Dosyayı görüntüle @
040a927c
...
@@ -304,9 +304,14 @@ Example: \code{httplib.responses[httplib.NOT_FOUND]} is \code{'Not Found'}.
...
@@ -304,9 +304,14 @@ Example: \code{httplib.responses[httplib.NOT_FOUND]} is \code{'Not Found'}.
This will send a request to the server using the HTTP request method
This will send a request to the server using the HTTP request method
\var
{
method
}
and the selector
\var
{
url
}
. If the
\var
{
body
}
argument is
\var
{
method
}
and the selector
\var
{
url
}
. If the
\var
{
body
}
argument is
present, it should be a string of data to send after the headers are finished.
present, it should be a string of data to send after the headers are finished.
Alternatively, it may be an open file object, in which case the
contents of the file is sent; this file object should support
\code
{
fileno()
}
and
\code
{
read()
}
methods.
The header Content-Length is automatically set to the correct value.
The header Content-Length is automatically set to the correct value.
The
\var
{
headers
}
argument should be a mapping of extra HTTP headers to send
The
\var
{
headers
}
argument should be a mapping of extra HTTP headers to send
with the request.
with the request.
\versionchanged
[\var{body} can be a file object]
{
2.6
}
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
getresponse
}{}
\begin{methoddesc}
{
getresponse
}{}
...
...
Lib/httplib.py
Dosyayı görüntüle @
040a927c
...
@@ -704,7 +704,15 @@ class HTTPConnection:
...
@@ -704,7 +704,15 @@ class HTTPConnection:
if
self
.
debuglevel
>
0
:
if
self
.
debuglevel
>
0
:
print
"send:"
,
repr
(
str
)
print
"send:"
,
repr
(
str
)
try
:
try
:
self
.
sock
.
sendall
(
str
)
blocksize
=
8192
if
hasattr
(
str
,
'read'
)
:
if
self
.
debuglevel
>
0
:
print
"sendIng a read()able"
data
=
str
.
read
(
blocksize
)
while
data
:
self
.
sock
.
sendall
(
data
)
data
=
str
.
read
(
blocksize
)
else
:
self
.
sock
.
sendall
(
str
)
except
socket
.
error
,
v
:
except
socket
.
error
,
v
:
if
v
[
0
]
==
32
:
# Broken pipe
if
v
[
0
]
==
32
:
# Broken pipe
self
.
close
()
self
.
close
()
...
@@ -879,7 +887,21 @@ class HTTPConnection:
...
@@ -879,7 +887,21 @@ class HTTPConnection:
self
.
putrequest
(
method
,
url
,
**
skips
)
self
.
putrequest
(
method
,
url
,
**
skips
)
if
body
and
(
'content-length'
not
in
header_names
):
if
body
and
(
'content-length'
not
in
header_names
):
self
.
putheader
(
'Content-Length'
,
str
(
len
(
body
)))
thelen
=
None
try
:
thelen
=
str
(
len
(
body
))
except
TypeError
,
te
:
# If this is a file-like object, try to
# fstat its file descriptor
import
os
try
:
thelen
=
str
(
os
.
fstat
(
body
.
fileno
())
.
st_size
)
except
(
AttributeError
,
OSError
):
# Don't send a length if this failed
if
self
.
debuglevel
>
0
:
print
"Cannot stat!!"
if
thelen
is
not
None
:
self
.
putheader
(
'Content-Length'
,
thelen
)
for
hdr
,
value
in
headers
.
iteritems
():
for
hdr
,
value
in
headers
.
iteritems
():
self
.
putheader
(
hdr
,
value
)
self
.
putheader
(
hdr
,
value
)
self
.
endheaders
()
self
.
endheaders
()
...
...
Lib/test/test_httplib.py
Dosyayı görüntüle @
040a927c
...
@@ -10,9 +10,10 @@ class FakeSocket:
...
@@ -10,9 +10,10 @@ class FakeSocket:
def
__init__
(
self
,
text
,
fileclass
=
StringIO
.
StringIO
):
def
__init__
(
self
,
text
,
fileclass
=
StringIO
.
StringIO
):
self
.
text
=
text
self
.
text
=
text
self
.
fileclass
=
fileclass
self
.
fileclass
=
fileclass
self
.
data
=
''
def
sendall
(
self
,
data
):
def
sendall
(
self
,
data
):
self
.
data
=
data
self
.
data
+
=
data
def
makefile
(
self
,
mode
,
bufsize
=
None
):
def
makefile
(
self
,
mode
,
bufsize
=
None
):
if
mode
!=
'r'
and
mode
!=
'rb'
:
if
mode
!=
'r'
and
mode
!=
'rb'
:
...
@@ -133,6 +134,16 @@ class BasicTest(TestCase):
...
@@ -133,6 +134,16 @@ class BasicTest(TestCase):
self
.
fail
(
"Did not expect response from HEAD request"
)
self
.
fail
(
"Did not expect response from HEAD request"
)
resp
.
close
()
resp
.
close
()
def
test_send_file
(
self
):
expected
=
'GET /foo HTTP/1.1
\r\n
Host: example.com
\r\n
'
\
'Accept-Encoding: identity
\r\n
Content-Length:'
body
=
open
(
__file__
,
'rb'
)
conn
=
httplib
.
HTTPConnection
(
'example.com'
)
sock
=
FakeSocket
(
body
)
conn
.
sock
=
sock
conn
.
request
(
'GET'
,
'/foo'
,
body
)
self
.
assertTrue
(
sock
.
data
.
startswith
(
expected
))
class
OfflineTest
(
TestCase
):
class
OfflineTest
(
TestCase
):
def
test_responses
(
self
):
def
test_responses
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
040a927c
...
@@ -96,6 +96,9 @@ Core and builtins
...
@@ -96,6 +96,9 @@ Core and builtins
Library
Library
-------
-------
- Patch #1065257: Support passing open files as body in
HTTPConnection.request().
- Bug #1569790: mailbox.py: Maildir.get_folder() and MH.get_folder()
- Bug #1569790: mailbox.py: Maildir.get_folder() and MH.get_folder()
weren'
t
passing
the
message
factory
on
to
newly
created
Maildir
/
MH
weren'
t
passing
the
message
factory
on
to
newly
created
Maildir
/
MH
objects
.
objects
.
...
...
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