Allow modification of PPUser

This commit is contained in:
clerie 2022-05-02 18:33:21 +02:00
parent 36187c18b3
commit e3f9fbf36b
3 changed files with 50 additions and 7 deletions

View File

@ -3,6 +3,7 @@
from .connection import Connection
from . import exceptions
from . import messages
from . import types
class OMMClient2:
"""
@ -152,3 +153,22 @@ class OMMClient2:
if r.errCode is None:
return True
return False
def set_user_name(self, uid, name):
"""
Get PP user
:param uid: User id
"""
t = types.PPUserType()
t.uid = uid
t.name = name
m = messages.SetPPUser()
m.childs.user = [t]
print(m)
r = self.connection.request(m)
r.raise_on_error()
if r.childs.user is None:
return None
return r.childs.user[0]

View File

@ -44,7 +44,10 @@ class Message:
def __setattr__(self, name, value):
if name in self.CHILDS.keys():
if self.CHILDS[name] is not None and type(value) != self.CHILDS[name]:
if not isinstance(value, list):
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
else:
@ -136,6 +139,7 @@ from .getppdev import GetPPDev, GetPPDevResp
from .getppuser import GetPPUser, GetPPUserResp
from .open import Open, OpenResp
from .ping import Ping, PingResp
from .setppuser import SetPPUser, SetPPUserResp
def construct(request):
"""
@ -149,11 +153,12 @@ def construct(request):
root.setAttribute(str(k), str(v))
for k, v in request._childs.items():
child = message.createElement(k)
if v is not None:
for c_k, c_v in v.items():
child.setAttribute(str(c_k), str(c_v))
for child_name, child_list in request._childs.items():
if child_list is not None:
for child_list_item in child_list:
child = message.createElement(child_name)
for child_item_key, child_item_value in child_list_item._attrs.items():
child.setAttribute(str(child_item_key), str(child_item_value))
root.appendChild(child)
return root.toxml()

View File

@ -0,0 +1,18 @@
#!/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,
}