summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2016-10-20 21:03:44 -0400
committerBernard Normier <bernard@zeroc.com>2016-10-20 21:03:44 -0400
commit3cb9c15995b828c52dba34d0a222f572d5bbc41b (patch)
tree87bad249c2ee04972be5f3c7635880cb0c556128 /python
parentupdating IceBT to BlueZ 5 (diff)
downloadice-3cb9c15995b828c52dba34d0a222f572d5bbc41b.tar.bz2
ice-3cb9c15995b828c52dba34d0a222f572d5bbc41b.tar.xz
ice-3cb9c15995b828c52dba34d0a222f572d5bbc41b.zip
Added support for non-ASCII characters and universal character names
to stringified identities and proxies. This includes a new Ice.ToStringMode property.
Diffstat (limited to 'python')
-rw-r--r--python/modules/IcePy/Communicator.cpp21
-rw-r--r--python/modules/IcePy/Init.cpp4
-rw-r--r--python/modules/IcePy/Operation.cpp4
-rw-r--r--python/python/Ice.py4
-rw-r--r--python/test/Ice/location/AllTests.py2
-rw-r--r--python/test/Ice/proxy/AllTests.py29
6 files changed, 52 insertions, 12 deletions
diff --git a/python/modules/IcePy/Communicator.cpp b/python/modules/IcePy/Communicator.cpp
index 1549cd1043c..eb223c85853 100644
--- a/python/modules/IcePy/Communicator.cpp
+++ b/python/modules/IcePy/Communicator.cpp
@@ -1740,19 +1740,34 @@ IcePy::getCommunicatorWrapper(const Ice::CommunicatorPtr& communicator)
extern "C"
PyObject*
-IcePy_identityToString(PyObject* /*self*/, PyObject* obj)
+IcePy_identityToString(PyObject* /*self*/, PyObject* args)
{
+ PyObject* identityType = lookupType("Ice.Identity");
+ PyObject* obj;
+ PyObject* mode = 0;
+ if(!PyArg_ParseTuple(args, STRCAST("O!O"), identityType, &obj, &mode))
+ {
+ return 0;
+ }
+
Ice::Identity id;
if(!getIdentity(obj, id))
{
return 0;
}
-
+
+ Ice::ToStringMode toStringMode = Ice::Unicode;
+ if(mode != Py_None && PyObject_HasAttrString(mode, STRCAST("value")))
+ {
+ PyObjectHandle modeValue = PyObject_GetAttrString(mode, STRCAST("value"));
+ toStringMode = static_cast<Ice::ToStringMode>(PyLong_AsLong(modeValue.get()));
+ }
+
string str;
try
{
- str = Ice::identityToString(id);
+ str = identityToString(id, toStringMode);
}
catch(const Ice::Exception& ex)
{
diff --git a/python/modules/IcePy/Init.cpp b/python/modules/IcePy/Init.cpp
index 88205ebc571..581e4f649c5 100644
--- a/python/modules/IcePy/Init.cpp
+++ b/python/modules/IcePy/Init.cpp
@@ -60,8 +60,8 @@ static PyMethodDef methods[] =
PyDoc_STR(STRCAST("createProperties([args]) -> Ice.Properties")) },
{ STRCAST("stringToIdentity"), reinterpret_cast<PyCFunction>(IcePy_stringToIdentity), METH_O,
PyDoc_STR(STRCAST("stringToIdentity(string) -> Ice.Identity")) },
- { STRCAST("identityToString"), reinterpret_cast<PyCFunction>(IcePy_identityToString), METH_O,
- PyDoc_STR(STRCAST("identityToString(Ice.Identity) -> string")) },
+ { STRCAST("identityToString"), reinterpret_cast<PyCFunction>(IcePy_identityToString), METH_VARARGS,
+ PyDoc_STR(STRCAST("identityToString(Ice.Identity, Ice.ToStringMode) -> string")) },
{ STRCAST("getProcessLogger"), reinterpret_cast<PyCFunction>(IcePy_getProcessLogger), METH_NOARGS,
PyDoc_STR(STRCAST("getProcessLogger() -> Ice.Logger")) },
{ STRCAST("setProcessLogger"), reinterpret_cast<PyCFunction>(IcePy_setProcessLogger), METH_VARARGS,
diff --git a/python/modules/IcePy/Operation.cpp b/python/modules/IcePy/Operation.cpp
index 3b59074a8e5..c8dad9a0c96 100644
--- a/python/modules/IcePy/Operation.cpp
+++ b/python/modules/IcePy/Operation.cpp
@@ -3349,7 +3349,7 @@ IcePy::TypedUpcall::dispatch(PyObject* servant, const pair<const Ice::Byte*, con
if(!method.get())
{
ostringstream ostr;
- ostr << "servant for identity " << identityToString(current.id)
+ ostr << "servant for identity " << _communicator->identityToString(current.id)
<< " does not define operation `" << _op->dispatchName << "'";
string str = ostr.str();
PyErr_Warn(PyExc_RuntimeWarning, const_cast<char*>(str.c_str()));
@@ -3712,7 +3712,7 @@ IcePy::BlobjectUpcall::dispatch(PyObject* servant, const pair<const Ice::Byte*,
if(!method.get())
{
ostringstream ostr;
- ostr << "servant for identity " << identityToString(current.id)
+ ostr << "servant for identity " << communicator->identityToString(current.id)
<< " does not define operation `" << dispatchName << "'";
string str = ostr.str();
PyErr_Warn(PyExc_RuntimeWarning, const_cast<char*>(str.c_str()));
diff --git a/python/python/Ice.py b/python/python/Ice.py
index 162f626682d..7c06a1fec77 100644
--- a/python/python/Ice.py
+++ b/python/python/Ice.py
@@ -716,8 +716,8 @@ the list that were recognized by the Ice run time.
#
# Ice.identityToString
#
-def identityToString(id):
- return IcePy.identityToString(id)
+def identityToString(id, toStringMode=None):
+ return IcePy.identityToString(id, toStringMode)
#
# Ice.stringToIdentity
diff --git a/python/test/Ice/location/AllTests.py b/python/test/Ice/location/AllTests.py
index bf0a378b85f..91519152101 100644
--- a/python/test/Ice/location/AllTests.py
+++ b/python/test/Ice/location/AllTests.py
@@ -248,7 +248,7 @@ def allTests(communicator, ref):
registry.addObject(adapter.add(HelloI(), id));
adapter.activate();
- helloPrx = Test.HelloPrx.checkedCast(communicator.stringToProxy(Ice.identityToString(id)));
+ helloPrx = Test.HelloPrx.checkedCast(communicator.stringToProxy(communicator.identityToString(id)));
test(not helloPrx.ice_getConnection());
adapter.deactivate();
diff --git a/python/test/Ice/proxy/AllTests.py b/python/test/Ice/proxy/AllTests.py
index bd889945639..6e04cc674fa 100644
--- a/python/test/Ice/proxy/AllTests.py
+++ b/python/test/Ice/proxy/AllTests.py
@@ -358,10 +358,35 @@ def allTests(communicator, collocated):
sys.stdout.write("testing proxy methods... ")
sys.stdout.flush()
+
+
test(communicator.identityToString(base.ice_identity(communicator.stringToIdentity("other")).ice_getIdentity()) \
== "other")
- test(Ice.identityToString(base.ice_identity(Ice.stringToIdentity("other")).ice_getIdentity()) == "other")
-
+
+ #
+ # Verify that ToStringMode is passed correctly
+ #
+ ident = Ice.Identity("test", "\x7F\xE2\x82\xAC")
+
+ idStr = Ice.identityToString(ident, Ice.ToStringMode.Unicode)
+ test(idStr == "\\u007f\xE2\x82\xAC/test")
+ ident2 = Ice.stringToIdentity(idStr)
+ test(ident == ident2)
+ test(Ice.identityToString(ident) == idStr)
+
+ idStr = Ice.identityToString(ident, Ice.ToStringMode.ASCII)
+ test(idStr == "\\u007f\\u20ac/test")
+ ident2 = Ice.stringToIdentity(idStr)
+ test(ident == ident2)
+
+ idStr = Ice.identityToString(ident, Ice.ToStringMode.Compat)
+ test(idStr == "\\177\\342\\202\\254/test")
+ ident2 = Ice.stringToIdentity(idStr)
+ test(ident == ident2)
+
+ ident2 = Ice.stringToIdentity(communicator.identityToString(ident))
+ test(ident == ident2)
+
test(base.ice_facet("facet").ice_getFacet() == "facet")
test(base.ice_adapterId("id").ice_getAdapterId() == "id")
test(base.ice_twoway().ice_isTwoway())