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
3405792b
Kaydet (Commit)
3405792b
authored
Mar 05, 2017
tarafından
Petr Motejlek
Kaydeden (comit)
Serhiy Storchaka
Mar 05, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-29615: backport to 3.6 (#478)
üst
8192402e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
20 deletions
+117
-20
test_xmlrpc.py
Lib/test/test_xmlrpc.py
+89
-1
server.py
Lib/xmlrpc/server.py
+24
-19
NEWS
Misc/NEWS
+4
-0
No files found.
Lib/test/test_xmlrpc.py
Dosyayı görüntüle @
3405792b
...
@@ -343,6 +343,94 @@ class XMLRPCTestCase(unittest.TestCase):
...
@@ -343,6 +343,94 @@ class XMLRPCTestCase(unittest.TestCase):
self
.
assertEqual
(
p
.
method
(),
5
)
self
.
assertEqual
(
p
.
method
(),
5
)
self
.
assertEqual
(
p
.
method
(),
5
)
self
.
assertEqual
(
p
.
method
(),
5
)
class
SimpleXMLRPCDispatcherTestCase
(
unittest
.
TestCase
):
class
DispatchExc
(
Exception
):
"""Raised inside the dispatched functions when checking for
chained exceptions"""
def
test_call_registered_func
(
self
):
"""Calls explicitly registered function"""
# Makes sure any exception raised inside the function has no other
# exception chained to it
exp_params
=
1
,
2
,
3
def
dispatched_func
(
*
params
):
raise
self
.
DispatchExc
(
params
)
dispatcher
=
xmlrpc
.
server
.
SimpleXMLRPCDispatcher
()
dispatcher
.
register_function
(
dispatched_func
)
with
self
.
assertRaises
(
self
.
DispatchExc
)
as
exc_ctx
:
dispatcher
.
_dispatch
(
'dispatched_func'
,
exp_params
)
self
.
assertEqual
(
exc_ctx
.
exception
.
args
,
(
exp_params
,))
self
.
assertIsNone
(
exc_ctx
.
exception
.
__cause__
)
self
.
assertIsNone
(
exc_ctx
.
exception
.
__context__
)
def
test_call_instance_func
(
self
):
"""Calls a registered instance attribute as a function"""
# Makes sure any exception raised inside the function has no other
# exception chained to it
exp_params
=
1
,
2
,
3
class
DispatchedClass
:
def
dispatched_func
(
self
,
*
params
):
raise
SimpleXMLRPCDispatcherTestCase
.
DispatchExc
(
params
)
dispatcher
=
xmlrpc
.
server
.
SimpleXMLRPCDispatcher
()
dispatcher
.
register_instance
(
DispatchedClass
())
with
self
.
assertRaises
(
self
.
DispatchExc
)
as
exc_ctx
:
dispatcher
.
_dispatch
(
'dispatched_func'
,
exp_params
)
self
.
assertEqual
(
exc_ctx
.
exception
.
args
,
(
exp_params
,))
self
.
assertIsNone
(
exc_ctx
.
exception
.
__cause__
)
self
.
assertIsNone
(
exc_ctx
.
exception
.
__context__
)
def
test_call_dispatch_func
(
self
):
"""Calls the registered instance's `_dispatch` function"""
# Makes sure any exception raised inside the function has no other
# exception chained to it
exp_method
=
'method'
exp_params
=
1
,
2
,
3
class
TestInstance
:
def
_dispatch
(
self
,
method
,
params
):
raise
SimpleXMLRPCDispatcherTestCase
.
DispatchExc
(
method
,
params
)
dispatcher
=
xmlrpc
.
server
.
SimpleXMLRPCDispatcher
()
dispatcher
.
register_instance
(
TestInstance
())
with
self
.
assertRaises
(
self
.
DispatchExc
)
as
exc_ctx
:
dispatcher
.
_dispatch
(
exp_method
,
exp_params
)
self
.
assertEqual
(
exc_ctx
.
exception
.
args
,
(
exp_method
,
exp_params
))
self
.
assertIsNone
(
exc_ctx
.
exception
.
__cause__
)
self
.
assertIsNone
(
exc_ctx
.
exception
.
__context__
)
def
test_registered_func_is_none
(
self
):
"""Calls explicitly registered function which is None"""
dispatcher
=
xmlrpc
.
server
.
SimpleXMLRPCDispatcher
()
dispatcher
.
register_function
(
None
,
name
=
'method'
)
with
self
.
assertRaises
(
Exception
,
expected_regex
=
'method'
):
dispatcher
.
_dispatch
(
'method'
,
(
'param'
,))
def
test_instance_has_no_func
(
self
):
"""Attempts to call nonexistent function on a registered instance"""
dispatcher
=
xmlrpc
.
server
.
SimpleXMLRPCDispatcher
()
dispatcher
.
register_instance
(
object
())
with
self
.
assertRaises
(
Exception
,
expected_regex
=
'method'
):
dispatcher
.
_dispatch
(
'method'
,
(
'param'
,))
def
test_cannot_locate_func
(
self
):
"""Calls a function that the dispatcher cannot locate"""
dispatcher
=
xmlrpc
.
server
.
SimpleXMLRPCDispatcher
()
with
self
.
assertRaises
(
Exception
,
expected_regex
=
'method'
):
dispatcher
.
_dispatch
(
'method'
,
(
'param'
,))
class
HelperTestCase
(
unittest
.
TestCase
):
class
HelperTestCase
(
unittest
.
TestCase
):
def
test_escape
(
self
):
def
test_escape
(
self
):
self
.
assertEqual
(
xmlrpclib
.
escape
(
"a&b"
),
"a&b"
)
self
.
assertEqual
(
xmlrpclib
.
escape
(
"a&b"
),
"a&b"
)
...
@@ -1312,7 +1400,7 @@ def test_main():
...
@@ -1312,7 +1400,7 @@ def test_main():
KeepaliveServerTestCase1
,
KeepaliveServerTestCase2
,
KeepaliveServerTestCase1
,
KeepaliveServerTestCase2
,
GzipServerTestCase
,
GzipUtilTestCase
,
GzipServerTestCase
,
GzipUtilTestCase
,
MultiPathServerTestCase
,
ServerProxyTestCase
,
FailingServerTestCase
,
MultiPathServerTestCase
,
ServerProxyTestCase
,
FailingServerTestCase
,
CGIHandlerTestCase
)
CGIHandlerTestCase
,
SimpleXMLRPCDispatcherTestCase
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
Lib/xmlrpc/server.py
Dosyayı görüntüle @
3405792b
...
@@ -386,31 +386,36 @@ class SimpleXMLRPCDispatcher:
...
@@ -386,31 +386,36 @@ class SimpleXMLRPCDispatcher:
not be called.
not be called.
"""
"""
func
=
None
try
:
try
:
# c
heck to see if a matching function has been registered
# c
all the matching registered function
func
=
self
.
funcs
[
method
]
func
=
self
.
funcs
[
method
]
except
KeyError
:
except
KeyError
:
if
self
.
instance
is
not
None
:
pass
# check for a _dispatch method
if
hasattr
(
self
.
instance
,
'_dispatch'
):
return
self
.
instance
.
_dispatch
(
method
,
params
)
else
:
# call instance method directly
try
:
func
=
resolve_dotted_attribute
(
self
.
instance
,
method
,
self
.
allow_dotted_names
)
except
AttributeError
:
pass
if
func
is
not
None
:
return
func
(
*
params
)
else
:
else
:
if
func
is
not
None
:
return
func
(
*
params
)
raise
Exception
(
'method "
%
s" is not supported'
%
method
)
raise
Exception
(
'method "
%
s" is not supported'
%
method
)
if
self
.
instance
is
not
None
:
if
hasattr
(
self
.
instance
,
'_dispatch'
):
# call the `_dispatch` method on the instance
return
self
.
instance
.
_dispatch
(
method
,
params
)
# call the instance's method directly
try
:
func
=
resolve_dotted_attribute
(
self
.
instance
,
method
,
self
.
allow_dotted_names
)
except
AttributeError
:
pass
else
:
if
func
is
not
None
:
return
func
(
*
params
)
raise
Exception
(
'method "
%
s" is not supported'
%
method
)
class
SimpleXMLRPCRequestHandler
(
BaseHTTPRequestHandler
):
class
SimpleXMLRPCRequestHandler
(
BaseHTTPRequestHandler
):
"""Simple XML-RPC request handler class.
"""Simple XML-RPC request handler class.
...
...
Misc/NEWS
Dosyayı görüntüle @
3405792b
...
@@ -13,6 +13,10 @@ Core and Builtins
...
@@ -13,6 +13,10 @@ Core and Builtins
Library
Library
-------
-------
- bpo-29615: SimpleXMLRPCDispatcher no longer chains KeyError (or any other
exception) to exception(s) raised in the dispatched methods.
Patch by Petr Motejlek.
What'
s
New
in
Python
3.6.1
release
candidate
1
What'
s
New
in
Python
3.6.1
release
candidate
1
==============================================
==============================================
...
...
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