Compare commits
No commits in common. "2d8a1897f04f8f5e55b1cd77a6e94a9b43c6fb47" and "0a442e4ab56d72bd8dc19dfc3038347cea1f3dd7" have entirely different histories.
2d8a1897f0
...
0a442e4ab5
@ -3,7 +3,6 @@
|
|||||||
from .connection import Connection
|
from .connection import Connection
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
from . import messages
|
from . import messages
|
||||||
from . import types
|
|
||||||
|
|
||||||
class OMMClient2:
|
class OMMClient2:
|
||||||
"""
|
"""
|
||||||
@ -153,40 +152,3 @@ class OMMClient2:
|
|||||||
if r.errCode is None:
|
if r.errCode is None:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def set_user_name(self, uid, name):
|
|
||||||
"""
|
|
||||||
Set PP user name
|
|
||||||
|
|
||||||
:param uid: User id
|
|
||||||
:param name: User name
|
|
||||||
"""
|
|
||||||
t = types.PPUserType()
|
|
||||||
t.uid = uid
|
|
||||||
t.name = name
|
|
||||||
m = messages.SetPPUser()
|
|
||||||
m.childs.user = [t]
|
|
||||||
r = self.connection.request(m)
|
|
||||||
r.raise_on_error()
|
|
||||||
if r.childs.user is None:
|
|
||||||
return None
|
|
||||||
return r.childs.user[0]
|
|
||||||
|
|
||||||
def set_user_num(self, uid, num):
|
|
||||||
"""
|
|
||||||
Set PP user number
|
|
||||||
|
|
||||||
:param uid: User id
|
|
||||||
:param num: User number
|
|
||||||
"""
|
|
||||||
t = types.PPUserType()
|
|
||||||
t.uid = uid
|
|
||||||
t.num = num
|
|
||||||
m = messages.SetPPUser()
|
|
||||||
m.childs.user = [t]
|
|
||||||
r = self.connection.request(m)
|
|
||||||
|
|
||||||
r.raise_on_error()
|
|
||||||
if r.childs.user is None:
|
|
||||||
return None
|
|
||||||
return r.childs.user[0]
|
|
||||||
|
@ -44,11 +44,8 @@ class Message:
|
|||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
if name in self.CHILDS.keys():
|
if name in self.CHILDS.keys():
|
||||||
if not isinstance(value, list):
|
if self.CHILDS[name] is not None and type(value) != self.CHILDS[name]:
|
||||||
raise TypeError()
|
raise TypeError()
|
||||||
for v in value:
|
|
||||||
if self.CHILDS[name] is not None and type(v) != self.CHILDS[name]:
|
|
||||||
raise TypeError()
|
|
||||||
self._child_dict[name] = value
|
self._child_dict[name] = value
|
||||||
else:
|
else:
|
||||||
object.__setattr__(self, name, value)
|
object.__setattr__(self, name, value)
|
||||||
@ -58,8 +55,8 @@ class Message:
|
|||||||
self.name = name
|
self.name = name
|
||||||
if not self.name:
|
if not self.name:
|
||||||
self.name = self.__class__.__name__
|
self.name = self.__class__.__name__
|
||||||
self._attrs = {} | attrs
|
self._attrs = attrs
|
||||||
self._childs = {} | childs
|
self._childs = childs
|
||||||
self.childs = self.Childs(self.CHILDS, self._childs)
|
self.childs = self.Childs(self.CHILDS, self._childs)
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
@ -79,7 +76,7 @@ class Message:
|
|||||||
object.__setattr__(self, name, value)
|
object.__setattr__(self, name, value)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{}({}, {}, {})".format(self.__class__.__name__, repr(self.name), repr(self._attrs), repr(self._childs))
|
return "{}({}, {}, {})".format(self.__class__.__name__, self.name, repr(self._attrs), repr(self._childs))
|
||||||
|
|
||||||
|
|
||||||
class Request(Message):
|
class Request(Message):
|
||||||
@ -139,7 +136,6 @@ from .getppdev import GetPPDev, GetPPDevResp
|
|||||||
from .getppuser import GetPPUser, GetPPUserResp
|
from .getppuser import GetPPUser, GetPPUserResp
|
||||||
from .open import Open, OpenResp
|
from .open import Open, OpenResp
|
||||||
from .ping import Ping, PingResp
|
from .ping import Ping, PingResp
|
||||||
from .setppuser import SetPPUser, SetPPUserResp
|
|
||||||
|
|
||||||
def construct(request):
|
def construct(request):
|
||||||
"""
|
"""
|
||||||
@ -153,13 +149,12 @@ def construct(request):
|
|||||||
root.setAttribute(str(k), str(v))
|
root.setAttribute(str(k), str(v))
|
||||||
|
|
||||||
|
|
||||||
for child_name, child_list in request._childs.items():
|
for k, v in request._childs.items():
|
||||||
if child_list is not None:
|
child = message.createElement(k)
|
||||||
for child_list_item in child_list:
|
if v is not None:
|
||||||
child = message.createElement(child_name)
|
for c_k, c_v in v.items():
|
||||||
for child_item_key, child_item_value in child_list_item._attrs.items():
|
child.setAttribute(str(c_k), str(c_v))
|
||||||
child.setAttribute(str(child_item_key), str(child_item_value))
|
root.appendChild(child)
|
||||||
root.appendChild(child)
|
|
||||||
return root.toxml()
|
return root.toxml()
|
||||||
|
|
||||||
def parse(message):
|
def parse(message):
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from . import Request, Response, request_type, response_type
|
|
||||||
from ..types import PPUserType
|
|
||||||
|
|
||||||
|
|
||||||
@request_type
|
|
||||||
class SetPPUser(Request):
|
|
||||||
CHILDS = {
|
|
||||||
"user": PPUserType,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@response_type
|
|
||||||
class SetPPUserResp(Response):
|
|
||||||
CHILDS = {
|
|
||||||
"user": PPUserType,
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user