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
33a40003
Kaydet (Commit)
33a40003
authored
Mar 21, 2014
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20627: xmlrpc.client.ServerProxy is now a context manager.
Patch by Claudiu Popa.
üst
051f37d2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
10 deletions
+42
-10
xmlrpc.client.rst
Doc/library/xmlrpc.client.rst
+14
-9
3.5.rst
Doc/whatsnew/3.5.rst
+2
-1
test_xmlrpc.py
Lib/test/test_xmlrpc.py
+18
-0
client.py
Lib/xmlrpc/client.py
+6
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/xmlrpc.client.rst
Dosyayı görüntüle @
33a40003
...
@@ -191,6 +191,11 @@ grouped under the reserved :attr:`system` attribute:
...
@@ -191,6 +191,11 @@ grouped under the reserved :attr:`system` attribute:
no such string is available, an empty string is returned. The documentation
no such string is available, an empty string is returned. The documentation
string may contain HTML markup.
string may contain HTML markup.
.. versionchanged:: 3.5
Instances of :class:`ServerProxy` support the :term:`context manager` protocol
for closing the underlying transport.
A working example follows. The server code::
A working example follows. The server code::
...
@@ -208,9 +213,9 @@ The client code for the preceding server::
...
@@ -208,9 +213,9 @@ The client code for the preceding server::
import xmlrpc.client
import xmlrpc.client
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
with xmlrpc.client.ServerProxy("http://localhost:8000/") as proxy:
print("3 is even: %s" % str(proxy.is_even(3)))
print("3 is even: %s" % str(proxy.is_even(3)))
print("100 is even: %s" % str(proxy.is_even(100)))
print("100 is even: %s" % str(proxy.is_even(100)))
.. _datetime-objects:
.. _datetime-objects:
...
@@ -518,14 +523,14 @@ Example of Client Usage
...
@@ -518,14 +523,14 @@ Example of Client Usage
from xmlrpc.client import ServerProxy, Error
from xmlrpc.client import ServerProxy, Error
# server = ServerProxy("http://localhost:8000") # local server
# server = ServerProxy("http://localhost:8000") # local server
server = ServerProxy("http://betty.userland.com")
with ServerProxy("http://betty.userland.com") as proxy:
print(server
)
print(proxy
)
try:
try:
print(server
.examples.getStateName(41))
print(proxy
.examples.getStateName(41))
except Error as v:
except Error as v:
print("ERROR", v)
print("ERROR", v)
To access an XML-RPC server through a proxy, you need to define a custom
To access an XML-RPC server through a proxy, you need to define a custom
transport. The following example shows how:
transport. The following example shows how:
...
...
Doc/whatsnew/3.5.rst
Dosyayı görüntüle @
33a40003
...
@@ -134,7 +134,8 @@ New Modules
...
@@ -134,7 +134,8 @@ New Modules
Improved Modules
Improved Modules
================
================
* None yet.
* :class:`xmlrpc.client.ServerProxy` is now a :term:`context manager`
(contributed by Claudiu Popa in :issue:`20627`).
Optimizations
Optimizations
...
...
Lib/test/test_xmlrpc.py
Dosyayı görüntüle @
33a40003
...
@@ -713,6 +713,23 @@ class SimpleServerTestCase(BaseServerTestCase):
...
@@ -713,6 +713,23 @@ class SimpleServerTestCase(BaseServerTestCase):
conn
.
request
(
'POST'
,
'/RPC2 HTTP/1.0
\r\n
Content-Length: 100
\r\n\r\n
bye'
)
conn
.
request
(
'POST'
,
'/RPC2 HTTP/1.0
\r\n
Content-Length: 100
\r\n\r\n
bye'
)
conn
.
close
()
conn
.
close
()
def
test_context_manager
(
self
):
with
xmlrpclib
.
ServerProxy
(
URL
)
as
server
:
server
.
add
(
2
,
3
)
self
.
assertNotEqual
(
server
(
'transport'
)
.
_connection
,
(
None
,
None
))
self
.
assertEqual
(
server
(
'transport'
)
.
_connection
,
(
None
,
None
))
def
test_context_manager_method_error
(
self
):
try
:
with
xmlrpclib
.
ServerProxy
(
URL
)
as
server
:
server
.
add
(
2
,
"a"
)
except
xmlrpclib
.
Fault
:
pass
self
.
assertEqual
(
server
(
'transport'
)
.
_connection
,
(
None
,
None
))
class
MultiPathServerTestCase
(
BaseServerTestCase
):
class
MultiPathServerTestCase
(
BaseServerTestCase
):
threadFunc
=
staticmethod
(
http_multi_server
)
threadFunc
=
staticmethod
(
http_multi_server
)
...
@@ -898,6 +915,7 @@ class ServerProxyTestCase(unittest.TestCase):
...
@@ -898,6 +915,7 @@ class ServerProxyTestCase(unittest.TestCase):
p
=
xmlrpclib
.
ServerProxy
(
self
.
url
,
transport
=
t
)
p
=
xmlrpclib
.
ServerProxy
(
self
.
url
,
transport
=
t
)
self
.
assertEqual
(
p
(
'transport'
),
t
)
self
.
assertEqual
(
p
(
'transport'
),
t
)
# This is a contrived way to make a failure occur on the server side
# This is a contrived way to make a failure occur on the server side
# in order to test the _send_traceback_header flag on the server
# in order to test the _send_traceback_header flag on the server
class
FailingMessageClass
(
http
.
client
.
HTTPMessage
):
class
FailingMessageClass
(
http
.
client
.
HTTPMessage
):
...
...
Lib/xmlrpc/client.py
Dosyayı görüntüle @
33a40003
...
@@ -1449,6 +1449,12 @@ class ServerProxy:
...
@@ -1449,6 +1449,12 @@ class ServerProxy:
return
self
.
__transport
return
self
.
__transport
raise
AttributeError
(
"Attribute
%
r not found"
%
(
attr
,))
raise
AttributeError
(
"Attribute
%
r not found"
%
(
attr
,))
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
__close
()
# compatibility
# compatibility
Server
=
ServerProxy
Server
=
ServerProxy
...
...
Misc/NEWS
Dosyayı görüntüle @
33a40003
...
@@ -23,6 +23,8 @@ Core and Builtins
...
@@ -23,6 +23,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #20627: xmlrpc.client.ServerProxy is now a context manager.
- Issue #19165: The formatter module now raises DeprecationWarning instead of
- Issue #19165: The formatter module now raises DeprecationWarning instead of
PendingDeprecationWarning.
PendingDeprecationWarning.
...
...
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