massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
This commit is contained in:
parent
d50412c7f7
commit
6a6f15707a
1 changed files with 9945 additions and 9945 deletions
|
|
@ -92,7 +92,7 @@ class ShareNode(object):
|
|||
if name == "..":
|
||||
name = "--"
|
||||
else:
|
||||
name = regex.pathEscape(name)
|
||||
name = regex.path_escape(name)
|
||||
self.name = name
|
||||
self.children = {}
|
||||
self.type = type_
|
||||
|
|
@ -128,7 +128,7 @@ class ShareNode(object):
|
|||
def values(self):
|
||||
return self.children.values()
|
||||
|
||||
def getOrCreate(self, name, type_=TYPE_VIRTUAL, access=None):
|
||||
def get_or_create(self, name, type_=TYPE_VIRTUAL, access=None):
|
||||
"""Get a node or create a virtual node and return it"""
|
||||
if access is None:
|
||||
access = {C.ACCESS_PERM_READ: {KEY_TYPE: C.ACCESS_TYPE_PUBLIC}}
|
||||
|
|
@ -144,7 +144,7 @@ class ShareNode(object):
|
|||
node.parent = self
|
||||
self.children[node.name] = node
|
||||
|
||||
def removeFromParent(self):
|
||||
def remove_from_parent(self):
|
||||
try:
|
||||
del self.parent.children[self.name]
|
||||
except TypeError:
|
||||
|
|
@ -155,7 +155,7 @@ class ShareNode(object):
|
|||
raise exceptions.InternalError("node not found in parent's children")
|
||||
self.parent = None
|
||||
|
||||
def _checkNodePermission(self, client, node, perms, peer_jid):
|
||||
def _check_node_permission(self, client, node, perms, peer_jid):
|
||||
"""Check access to this node for peer_jid
|
||||
|
||||
@param node(SharedNode): node to check access
|
||||
|
|
@ -165,13 +165,13 @@ class ShareNode(object):
|
|||
"""
|
||||
file_data = {"access": self.access, "owner": client.jid.userhostJID()}
|
||||
try:
|
||||
self.host.memory.checkFilePermission(file_data, peer_jid, perms)
|
||||
self.host.memory.check_file_permission(file_data, peer_jid, perms)
|
||||
except exceptions.PermissionError:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def checkPermissions(
|
||||
def check_permissions(
|
||||
self, client, peer_jid, perms=(C.ACCESS_PERM_READ,), check_parents=True
|
||||
):
|
||||
"""Check that peer_jid can access this node and all its parents
|
||||
|
|
@ -188,7 +188,7 @@ class ShareNode(object):
|
|||
|
||||
parent = self
|
||||
while parent != None:
|
||||
if not self._checkNodePermission(client, parent, perms, peer_jid):
|
||||
if not self._check_node_permission(client, parent, perms, peer_jid):
|
||||
return False
|
||||
parent = parent.parent
|
||||
|
||||
|
|
@ -225,27 +225,27 @@ class ShareNode(object):
|
|||
elif node.type == TYPE_PATH:
|
||||
break
|
||||
|
||||
if not node.checkPermissions(client, peer_jid, perms=perms):
|
||||
if not node.check_permissions(client, peer_jid, perms=perms):
|
||||
raise exceptions.PermissionError("permission denied")
|
||||
|
||||
return node, "/".join(path_elts)
|
||||
|
||||
def findByLocalPath(self, path):
|
||||
def find_by_local_path(self, path):
|
||||
"""retrieve nodes linking to local path
|
||||
|
||||
@return (list[ShareNode]): found nodes associated to path
|
||||
@raise exceptions.NotFound: no node has been found with this path
|
||||
"""
|
||||
shared_paths = self.getSharedPaths()
|
||||
shared_paths = self.get_shared_paths()
|
||||
try:
|
||||
return shared_paths[path]
|
||||
except KeyError:
|
||||
raise exceptions.NotFound
|
||||
|
||||
def _getSharedPaths(self, node, paths):
|
||||
def _get_shared_paths(self, node, paths):
|
||||
if node.type == TYPE_VIRTUAL:
|
||||
for node in node.values():
|
||||
self._getSharedPaths(node, paths)
|
||||
self._get_shared_paths(node, paths)
|
||||
elif node.type == TYPE_PATH:
|
||||
paths.setdefault(node.path, []).append(node)
|
||||
else:
|
||||
|
|
@ -253,7 +253,7 @@ class ShareNode(object):
|
|||
"unknown node type: {type}".format(type=node.type)
|
||||
)
|
||||
|
||||
def getSharedPaths(self):
|
||||
def get_shared_paths(self):
|
||||
"""retrieve nodes by shared path
|
||||
|
||||
this method will retrieve recursively shared path in children of this node
|
||||
|
|
@ -261,10 +261,10 @@ class ShareNode(object):
|
|||
"""
|
||||
if self.type == TYPE_PATH:
|
||||
raise exceptions.InternalError(
|
||||
"getSharedPaths must be used on a virtual node"
|
||||
"get_shared_paths must be used on a virtual node"
|
||||
)
|
||||
paths = {}
|
||||
self._getSharedPaths(self, paths)
|
||||
self._get_shared_paths(self, paths)
|
||||
return paths
|
||||
|
||||
|
||||
|
|
@ -276,86 +276,86 @@ class XEP_0329(object):
|
|||
self._b = host.plugins["XEP-0231"]
|
||||
self._h = host.plugins["XEP-0300"]
|
||||
self._jf = host.plugins["XEP-0234"]
|
||||
host.bridge.addMethod(
|
||||
"FISList",
|
||||
host.bridge.add_method(
|
||||
"fis_list",
|
||||
".plugin",
|
||||
in_sign="ssa{ss}s",
|
||||
out_sign="aa{ss}",
|
||||
method=self._listFiles,
|
||||
method=self._list_files,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"FISLocalSharesGet",
|
||||
host.bridge.add_method(
|
||||
"fis_local_shares_get",
|
||||
".plugin",
|
||||
in_sign="s",
|
||||
out_sign="as",
|
||||
method=self._localSharesGet,
|
||||
method=self._local_shares_get,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"FISSharePath",
|
||||
host.bridge.add_method(
|
||||
"fis_share_path",
|
||||
".plugin",
|
||||
in_sign="ssss",
|
||||
out_sign="s",
|
||||
method=self._sharePath,
|
||||
method=self._share_path,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"FISUnsharePath",
|
||||
host.bridge.add_method(
|
||||
"fis_unshare_path",
|
||||
".plugin",
|
||||
in_sign="ss",
|
||||
out_sign="",
|
||||
method=self._unsharePath,
|
||||
method=self._unshare_path,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"FISAffiliationsGet",
|
||||
host.bridge.add_method(
|
||||
"fis_affiliations_get",
|
||||
".plugin",
|
||||
in_sign="ssss",
|
||||
out_sign="a{ss}",
|
||||
method=self._affiliationsGet,
|
||||
method=self._affiliations_get,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"FISAffiliationsSet",
|
||||
host.bridge.add_method(
|
||||
"fis_affiliations_set",
|
||||
".plugin",
|
||||
in_sign="sssa{ss}s",
|
||||
out_sign="",
|
||||
method=self._affiliationsSet,
|
||||
method=self._affiliations_set,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"FISConfigurationGet",
|
||||
host.bridge.add_method(
|
||||
"fis_configuration_get",
|
||||
".plugin",
|
||||
in_sign="ssss",
|
||||
out_sign="a{ss}",
|
||||
method=self._configurationGet,
|
||||
method=self._configuration_get,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"FISConfigurationSet",
|
||||
host.bridge.add_method(
|
||||
"fis_configuration_set",
|
||||
".plugin",
|
||||
in_sign="sssa{ss}s",
|
||||
out_sign="",
|
||||
method=self._configurationSet,
|
||||
method=self._configuration_set,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"FISCreateDir",
|
||||
host.bridge.add_method(
|
||||
"fis_create_dir",
|
||||
".plugin",
|
||||
in_sign="sssa{ss}s",
|
||||
out_sign="",
|
||||
method=self._createDir,
|
||||
method=self._create_dir,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addSignal("FISSharedPathNew", ".plugin", signature="sss")
|
||||
host.bridge.addSignal("FISSharedPathRemoved", ".plugin", signature="ss")
|
||||
host.trigger.add("XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger)
|
||||
host.registerNamespace("fis", NS_FIS)
|
||||
host.bridge.add_signal("fis_shared_path_new", ".plugin", signature="sss")
|
||||
host.bridge.add_signal("fis_shared_path_removed", ".plugin", signature="ss")
|
||||
host.trigger.add("XEP-0234_fileSendingRequest", self._file_sending_request_trigger)
|
||||
host.register_namespace("fis", NS_FIS)
|
||||
|
||||
def getHandler(self, client):
|
||||
def get_handler(self, client):
|
||||
return XEP_0329_handler(self)
|
||||
|
||||
def profileConnected(self, client):
|
||||
def profile_connected(self, client):
|
||||
if client.is_component:
|
||||
client._file_sharing_allowed_hosts = self.host.memory.getConfig(
|
||||
client._file_sharing_allowed_hosts = self.host.memory.config_get(
|
||||
'component file_sharing',
|
||||
'http_upload_allowed_hosts_list') or [client.host]
|
||||
else:
|
||||
|
|
@ -367,7 +367,7 @@ class XEP_0329(object):
|
|||
)
|
||||
client._XEP_0329_names_data = {} # name to share map
|
||||
|
||||
def _fileSendingRequestTrigger(
|
||||
def _file_sending_request_trigger(
|
||||
self, client, session, content_data, content_name, file_data, file_elt
|
||||
):
|
||||
"""This trigger check that a requested file is available, and fill suitable data
|
||||
|
|
@ -425,7 +425,7 @@ class XEP_0329(object):
|
|||
else:
|
||||
return True, None
|
||||
parent_node = shared_file["parent"]
|
||||
if not parent_node.checkPermissions(client, session["peer_jid"]):
|
||||
if not parent_node.check_permissions(client, session["peer_jid"]):
|
||||
log.warning(
|
||||
_(
|
||||
"{peer_jid} requested a file (s)he can't access [{profile}]"
|
||||
|
|
@ -436,14 +436,14 @@ class XEP_0329(object):
|
|||
|
||||
file_data["size"] = size
|
||||
file_elt.addElement("size", content=str(size))
|
||||
hash_algo = file_data["hash_algo"] = self._h.getDefaultAlgo()
|
||||
hasher = file_data["hash_hasher"] = self._h.getHasher(hash_algo)
|
||||
file_elt.addChild(self._h.buildHashUsedElt(hash_algo))
|
||||
hash_algo = file_data["hash_algo"] = self._h.get_default_algo()
|
||||
hasher = file_data["hash_hasher"] = self._h.get_hasher(hash_algo)
|
||||
file_elt.addChild(self._h.build_hash_used_elt(hash_algo))
|
||||
content_data["stream_object"] = stream.FileStreamObject(
|
||||
self.host,
|
||||
client,
|
||||
path,
|
||||
uid=self._jf.getProgressId(session, content_name),
|
||||
uid=self._jf.get_progress_id(session, content_name),
|
||||
size=size,
|
||||
data_cb=lambda data: hasher.update(data),
|
||||
)
|
||||
|
|
@ -451,32 +451,32 @@ class XEP_0329(object):
|
|||
|
||||
# common methods
|
||||
|
||||
def _requestHandler(self, client, iq_elt, root_nodes_cb, files_from_node_cb):
|
||||
def _request_handler(self, client, iq_elt, root_nodes_cb, files_from_node_cb):
|
||||
iq_elt.handled = True
|
||||
node = iq_elt.query.getAttribute("node")
|
||||
if not node:
|
||||
d = utils.asDeferred(root_nodes_cb, client, iq_elt)
|
||||
d = utils.as_deferred(root_nodes_cb, client, iq_elt)
|
||||
else:
|
||||
d = utils.asDeferred(files_from_node_cb, client, iq_elt, node)
|
||||
d = utils.as_deferred(files_from_node_cb, client, iq_elt, node)
|
||||
d.addErrback(
|
||||
lambda failure_: log.error(
|
||||
_("error while retrieving files: {msg}").format(msg=failure_)
|
||||
)
|
||||
)
|
||||
|
||||
def _iqError(self, client, iq_elt, condition="item-not-found"):
|
||||
def _iq_error(self, client, iq_elt, condition="item-not-found"):
|
||||
error_elt = jabber_error.StanzaError(condition).toResponse(iq_elt)
|
||||
client.send(error_elt)
|
||||
|
||||
# client
|
||||
|
||||
def _addPathData(self, client, query_elt, path, parent_node):
|
||||
def _add_path_data(self, client, query_elt, path, parent_node):
|
||||
"""Fill query_elt with files/directories found in path"""
|
||||
name = os.path.basename(path)
|
||||
if os.path.isfile(path):
|
||||
size = os.path.getsize(path)
|
||||
mime_type = mimetypes.guess_type(path, strict=False)[0]
|
||||
file_elt = self._jf.buildFileElement(
|
||||
file_elt = self._jf.build_file_element(
|
||||
client=client, name=name, size=size, mime_type=mime_type,
|
||||
modified=os.path.getmtime(path)
|
||||
)
|
||||
|
|
@ -497,15 +497,15 @@ class XEP_0329(object):
|
|||
directory_elt = query_elt.addElement("directory")
|
||||
directory_elt["name"] = name
|
||||
|
||||
def _pathNodeHandler(self, client, iq_elt, query_elt, node, path):
|
||||
def _path_node_handler(self, client, iq_elt, query_elt, node, path):
|
||||
"""Fill query_elt for path nodes, i.e. physical directories"""
|
||||
path = os.path.join(node.path, path)
|
||||
|
||||
if not os.path.exists(path):
|
||||
# path may have been moved since it has been shared
|
||||
return self._iqError(client, iq_elt)
|
||||
return self._iq_error(client, iq_elt)
|
||||
elif os.path.isfile(path):
|
||||
self._addPathData(client, query_elt, path, node)
|
||||
self._add_path_data(client, query_elt, path, node)
|
||||
else:
|
||||
for name in sorted(os.listdir(path.encode("utf-8")), key=lambda n: n.lower()):
|
||||
try:
|
||||
|
|
@ -518,44 +518,44 @@ class XEP_0329(object):
|
|||
)
|
||||
continue
|
||||
full_path = os.path.join(path, name)
|
||||
self._addPathData(client, query_elt, full_path, node)
|
||||
self._add_path_data(client, query_elt, full_path, node)
|
||||
|
||||
def _virtualNodeHandler(self, client, peer_jid, iq_elt, query_elt, node):
|
||||
def _virtual_node_handler(self, client, peer_jid, iq_elt, query_elt, node):
|
||||
"""Fill query_elt for virtual nodes"""
|
||||
for name, child_node in node.items():
|
||||
if not child_node.checkPermissions(client, peer_jid, check_parents=False):
|
||||
if not child_node.check_permissions(client, peer_jid, check_parents=False):
|
||||
continue
|
||||
node_type = child_node.type
|
||||
if node_type == TYPE_VIRTUAL:
|
||||
directory_elt = query_elt.addElement("directory")
|
||||
directory_elt["name"] = name
|
||||
elif node_type == TYPE_PATH:
|
||||
self._addPathData(client, query_elt, child_node.path, child_node)
|
||||
self._add_path_data(client, query_elt, child_node.path, child_node)
|
||||
else:
|
||||
raise exceptions.InternalError(
|
||||
_("unexpected type: {type}").format(type=node_type)
|
||||
)
|
||||
|
||||
def _getRootNodesCb(self, client, iq_elt):
|
||||
def _get_root_nodes_cb(self, client, iq_elt):
|
||||
peer_jid = jid.JID(iq_elt["from"])
|
||||
iq_result_elt = xmlstream.toResponse(iq_elt, "result")
|
||||
query_elt = iq_result_elt.addElement((NS_FIS, "query"))
|
||||
for name, node in client._XEP_0329_root_node.items():
|
||||
if not node.checkPermissions(client, peer_jid, check_parents=False):
|
||||
if not node.check_permissions(client, peer_jid, check_parents=False):
|
||||
continue
|
||||
directory_elt = query_elt.addElement("directory")
|
||||
directory_elt["name"] = name
|
||||
client.send(iq_result_elt)
|
||||
|
||||
def _getFilesFromNodeCb(self, client, iq_elt, node_path):
|
||||
def _get_files_from_node_cb(self, client, iq_elt, node_path):
|
||||
"""Main method to retrieve files/directories from a node_path"""
|
||||
peer_jid = jid.JID(iq_elt["from"])
|
||||
try:
|
||||
node, path = ShareNode.find(client, node_path, peer_jid)
|
||||
except (exceptions.PermissionError, exceptions.NotFound):
|
||||
return self._iqError(client, iq_elt)
|
||||
return self._iq_error(client, iq_elt)
|
||||
except exceptions.DataError:
|
||||
return self._iqError(client, iq_elt, condition="not-acceptable")
|
||||
return self._iq_error(client, iq_elt, condition="not-acceptable")
|
||||
|
||||
node_type = node.type
|
||||
peer_jid = jid.JID(iq_elt["from"])
|
||||
|
|
@ -566,10 +566,10 @@ class XEP_0329(object):
|
|||
# we now fill query_elt according to node_type
|
||||
if node_type == TYPE_PATH:
|
||||
# it's a physical path
|
||||
self._pathNodeHandler(client, iq_elt, query_elt, node, path)
|
||||
self._path_node_handler(client, iq_elt, query_elt, node, path)
|
||||
elif node_type == TYPE_VIRTUAL:
|
||||
assert not path
|
||||
self._virtualNodeHandler(client, peer_jid, iq_elt, query_elt, node)
|
||||
self._virtual_node_handler(client, peer_jid, iq_elt, query_elt, node)
|
||||
else:
|
||||
raise exceptions.InternalError(
|
||||
_("unknown node type: {type}").format(type=node_type)
|
||||
|
|
@ -577,23 +577,23 @@ class XEP_0329(object):
|
|||
|
||||
client.send(iq_result_elt)
|
||||
|
||||
def onRequest(self, iq_elt, client):
|
||||
return self._requestHandler(
|
||||
client, iq_elt, self._getRootNodesCb, self._getFilesFromNodeCb
|
||||
def on_request(self, iq_elt, client):
|
||||
return self._request_handler(
|
||||
client, iq_elt, self._get_root_nodes_cb, self._get_files_from_node_cb
|
||||
)
|
||||
|
||||
# Component
|
||||
|
||||
def _compParseJids(self, client, iq_elt):
|
||||
def _comp_parse_jids(self, client, iq_elt):
|
||||
"""Retrieve peer_jid and owner to use from IQ stanza
|
||||
|
||||
@param iq_elt(domish.Element): IQ stanza of the FIS request
|
||||
@return (tuple[jid.JID, jid.JID]): peer_jid and owner
|
||||
"""
|
||||
|
||||
async def _compGetRootNodesCb(self, client, iq_elt):
|
||||
peer_jid, owner = client.getOwnerAndPeer(iq_elt)
|
||||
files_data = await self.host.memory.getFiles(
|
||||
async def _comp_get_root_nodes_cb(self, client, iq_elt):
|
||||
peer_jid, owner = client.get_owner_and_peer(iq_elt)
|
||||
files_data = await self.host.memory.get_files(
|
||||
client,
|
||||
peer_jid=peer_jid,
|
||||
parent="",
|
||||
|
|
@ -608,7 +608,7 @@ class XEP_0329(object):
|
|||
directory_elt["name"] = name
|
||||
client.send(iq_result_elt)
|
||||
|
||||
async def _compGetFilesFromNodeCb(self, client, iq_elt, node_path):
|
||||
async def _comp_get_files_from_node_cb(self, client, iq_elt, node_path):
|
||||
"""Retrieve files from local files repository according to permissions
|
||||
|
||||
result stanza is then built and sent to requestor
|
||||
|
|
@ -616,21 +616,21 @@ class XEP_0329(object):
|
|||
files_data):
|
||||
can be used to add data/elements
|
||||
"""
|
||||
peer_jid, owner = client.getOwnerAndPeer(iq_elt)
|
||||
peer_jid, owner = client.get_owner_and_peer(iq_elt)
|
||||
try:
|
||||
files_data = await self.host.memory.getFiles(
|
||||
files_data = await self.host.memory.get_files(
|
||||
client, peer_jid=peer_jid, path=node_path, owner=owner
|
||||
)
|
||||
except exceptions.NotFound:
|
||||
self._iqError(client, iq_elt)
|
||||
self._iq_error(client, iq_elt)
|
||||
return
|
||||
except exceptions.PermissionError:
|
||||
self._iqError(client, iq_elt, condition='not-allowed')
|
||||
self._iq_error(client, iq_elt, condition='not-allowed')
|
||||
return
|
||||
except Exception as e:
|
||||
tb = traceback.format_tb(e.__traceback__)
|
||||
log.error(f"internal server error: {e}\n{''.join(tb)}")
|
||||
self._iqError(client, iq_elt, condition='internal-server-error')
|
||||
self._iq_error(client, iq_elt, condition='internal-server-error')
|
||||
return
|
||||
iq_result_elt = xmlstream.toResponse(iq_elt, "result")
|
||||
query_elt = iq_result_elt.addElement((NS_FIS, "query"))
|
||||
|
|
@ -658,7 +658,7 @@ class XEP_0329(object):
|
|||
node_path,
|
||||
)
|
||||
else:
|
||||
file_elt = self._jf.buildFileElementFromDict(
|
||||
file_elt = self._jf.build_file_element_from_dict(
|
||||
client,
|
||||
file_data,
|
||||
modified=file_data.get("modified", file_data["created"])
|
||||
|
|
@ -666,12 +666,12 @@ class XEP_0329(object):
|
|||
query_elt.addChild(file_elt)
|
||||
client.send(iq_result_elt)
|
||||
|
||||
def onComponentRequest(self, iq_elt, client):
|
||||
return self._requestHandler(
|
||||
client, iq_elt, self._compGetRootNodesCb, self._compGetFilesFromNodeCb
|
||||
def on_component_request(self, iq_elt, client):
|
||||
return self._request_handler(
|
||||
client, iq_elt, self._comp_get_root_nodes_cb, self._comp_get_files_from_node_cb
|
||||
)
|
||||
|
||||
async def _parseResult(self, client, peer_jid, iq_elt):
|
||||
async def _parse_result(self, client, peer_jid, iq_elt):
|
||||
query_elt = next(iq_elt.elements(NS_FIS, "query"))
|
||||
files = []
|
||||
|
||||
|
|
@ -679,7 +679,7 @@ class XEP_0329(object):
|
|||
if elt.name == "file":
|
||||
# we have a file
|
||||
try:
|
||||
file_data = await self._jf.parseFileElement(client, elt)
|
||||
file_data = await self._jf.parse_file_element(client, elt)
|
||||
except exceptions.DataError:
|
||||
continue
|
||||
file_data["type"] = C.FILE_TYPE_FILE
|
||||
|
|
@ -691,7 +691,7 @@ class XEP_0329(object):
|
|||
for thumb in thumbs:
|
||||
if 'url' not in thumb and "id" in thumb:
|
||||
try:
|
||||
file_path = await self._b.getFile(client, peer_jid, thumb['id'])
|
||||
file_path = await self._b.get_file(client, peer_jid, thumb['id'])
|
||||
except Exception as e:
|
||||
log.warning(f"Can't get thumbnail {thumb['id']!r} for {file_data}: {e}")
|
||||
else:
|
||||
|
|
@ -718,14 +718,14 @@ class XEP_0329(object):
|
|||
|
||||
# affiliations #
|
||||
|
||||
async def _parseElement(self, client, iq_elt, element, namespace):
|
||||
peer_jid, owner = client.getOwnerAndPeer(iq_elt)
|
||||
async def _parse_element(self, client, iq_elt, element, namespace):
|
||||
peer_jid, owner = client.get_owner_and_peer(iq_elt)
|
||||
elt = next(iq_elt.elements(namespace, element))
|
||||
path = Path("/", elt['path'])
|
||||
if len(path.parts) < 2:
|
||||
raise RootPathException
|
||||
namespace = elt.getAttribute('namespace')
|
||||
files_data = await self.host.memory.getFiles(
|
||||
files_data = await self.host.memory.get_files(
|
||||
client,
|
||||
peer_jid=peer_jid,
|
||||
path=str(path.parent),
|
||||
|
|
@ -739,8 +739,8 @@ class XEP_0329(object):
|
|||
file_data = files_data[0]
|
||||
return peer_jid, elt, path, namespace, file_data
|
||||
|
||||
def _affiliationsGet(self, service_jid_s, namespace, path, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def _affiliations_get(self, service_jid_s, namespace, path, profile):
|
||||
client = self.host.get_client(profile)
|
||||
service = jid.JID(service_jid_s)
|
||||
d = defer.ensureDeferred(self.affiliationsGet(
|
||||
client, service, namespace or None, path))
|
||||
|
|
@ -782,8 +782,8 @@ class XEP_0329(object):
|
|||
|
||||
return affiliations
|
||||
|
||||
def _affiliationsSet(self, service_jid_s, namespace, path, affiliations, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def _affiliations_set(self, service_jid_s, namespace, path, affiliations, profile):
|
||||
client = self.host.get_client(profile)
|
||||
service = jid.JID(service_jid_s)
|
||||
affiliations = {jid.JID(e): a for e, a in affiliations.items()}
|
||||
return defer.ensureDeferred(self.affiliationsSet(
|
||||
|
|
@ -811,20 +811,20 @@ class XEP_0329(object):
|
|||
affiliation_elt['affiliation'] = affiliation
|
||||
await iq_elt.send()
|
||||
|
||||
def _onComponentAffiliationsGet(self, iq_elt, client):
|
||||
def _on_component_affiliations_get(self, iq_elt, client):
|
||||
iq_elt.handled = True
|
||||
defer.ensureDeferred(self.onComponentAffiliationsGet(client, iq_elt))
|
||||
defer.ensureDeferred(self.on_component_affiliations_get(client, iq_elt))
|
||||
|
||||
async def onComponentAffiliationsGet(self, client, iq_elt):
|
||||
async def on_component_affiliations_get(self, client, iq_elt):
|
||||
try:
|
||||
(
|
||||
from_jid, affiliations_elt, path, namespace, file_data
|
||||
) = await self._parseElement(client, iq_elt, "affiliations", NS_FIS_AFFILIATION)
|
||||
) = await self._parse_element(client, iq_elt, "affiliations", NS_FIS_AFFILIATION)
|
||||
except exceptions.CancelError:
|
||||
return
|
||||
except RootPathException:
|
||||
# if root path is requested, we only get owner affiliation
|
||||
peer_jid, owner = client.getOwnerAndPeer(iq_elt)
|
||||
peer_jid, owner = client.get_owner_and_peer(iq_elt)
|
||||
is_owner = peer_jid.userhostJID() == owner
|
||||
affiliations = {owner: 'owner'}
|
||||
except exceptions.NotFound:
|
||||
|
|
@ -836,7 +836,7 @@ class XEP_0329(object):
|
|||
else:
|
||||
from_jid_bare = from_jid.userhostJID()
|
||||
is_owner = from_jid_bare == file_data.get('owner')
|
||||
affiliations = self.host.memory.getFileAffiliations(file_data)
|
||||
affiliations = self.host.memory.get_file_affiliations(file_data)
|
||||
iq_result_elt = xmlstream.toResponse(iq_elt, "result")
|
||||
affiliations_elt = iq_result_elt.addElement((NS_FIS_AFFILIATION, 'affiliations'))
|
||||
for entity_jid, affiliation in affiliations.items():
|
||||
|
|
@ -848,15 +848,15 @@ class XEP_0329(object):
|
|||
affiliation_elt['affiliation'] = affiliation
|
||||
client.send(iq_result_elt)
|
||||
|
||||
def _onComponentAffiliationsSet(self, iq_elt, client):
|
||||
def _on_component_affiliations_set(self, iq_elt, client):
|
||||
iq_elt.handled = True
|
||||
defer.ensureDeferred(self.onComponentAffiliationsSet(client, iq_elt))
|
||||
defer.ensureDeferred(self.on_component_affiliations_set(client, iq_elt))
|
||||
|
||||
async def onComponentAffiliationsSet(self, client, iq_elt):
|
||||
async def on_component_affiliations_set(self, client, iq_elt):
|
||||
try:
|
||||
(
|
||||
from_jid, affiliations_elt, path, namespace, file_data
|
||||
) = await self._parseElement(client, iq_elt, "affiliations", NS_FIS_AFFILIATION)
|
||||
) = await self._parse_element(client, iq_elt, "affiliations", NS_FIS_AFFILIATION)
|
||||
except exceptions.CancelError:
|
||||
return
|
||||
except RootPathException:
|
||||
|
|
@ -890,17 +890,17 @@ class XEP_0329(object):
|
|||
client.sendError(iq_elt, 'internal-server-error', f"{e}")
|
||||
return
|
||||
|
||||
await self.host.memory.setFileAffiliations(client, file_data, affiliations)
|
||||
await self.host.memory.set_file_affiliations(client, file_data, affiliations)
|
||||
|
||||
iq_result_elt = xmlstream.toResponse(iq_elt, "result")
|
||||
client.send(iq_result_elt)
|
||||
|
||||
# configuration
|
||||
|
||||
def _configurationGet(self, service_jid_s, namespace, path, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def _configuration_get(self, service_jid_s, namespace, path, profile):
|
||||
client = self.host.get_client(profile)
|
||||
service = jid.JID(service_jid_s)
|
||||
d = defer.ensureDeferred(self.configurationGet(
|
||||
d = defer.ensureDeferred(self.configuration_get(
|
||||
client, service, namespace or None, path))
|
||||
d.addCallback(
|
||||
lambda configuration: {
|
||||
|
|
@ -909,7 +909,7 @@ class XEP_0329(object):
|
|||
)
|
||||
return d
|
||||
|
||||
async def configurationGet(
|
||||
async def configuration_get(
|
||||
self,
|
||||
client: SatXMPPEntity,
|
||||
service: jid.JID,
|
||||
|
|
@ -935,13 +935,13 @@ class XEP_0329(object):
|
|||
|
||||
return configuration
|
||||
|
||||
def _configurationSet(self, service_jid_s, namespace, path, configuration, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def _configuration_set(self, service_jid_s, namespace, path, configuration, profile):
|
||||
client = self.host.get_client(profile)
|
||||
service = jid.JID(service_jid_s)
|
||||
return defer.ensureDeferred(self.configurationSet(
|
||||
return defer.ensureDeferred(self.configuration_set(
|
||||
client, service, namespace or None, path, configuration))
|
||||
|
||||
async def configurationSet(
|
||||
async def configuration_set(
|
||||
self,
|
||||
client: SatXMPPEntity,
|
||||
service: jid.JID,
|
||||
|
|
@ -962,15 +962,15 @@ class XEP_0329(object):
|
|||
configuration_elt.addChild(form.toElement())
|
||||
await iq_elt.send()
|
||||
|
||||
def _onComponentConfigurationGet(self, iq_elt, client):
|
||||
def _on_component_configuration_get(self, iq_elt, client):
|
||||
iq_elt.handled = True
|
||||
defer.ensureDeferred(self.onComponentConfigurationGet(client, iq_elt))
|
||||
defer.ensureDeferred(self.on_component_configuration_get(client, iq_elt))
|
||||
|
||||
async def onComponentConfigurationGet(self, client, iq_elt):
|
||||
async def on_component_configuration_get(self, client, iq_elt):
|
||||
try:
|
||||
(
|
||||
from_jid, configuration_elt, path, namespace, file_data
|
||||
) = await self._parseElement(client, iq_elt, "configuration", NS_FIS_CONFIGURATION)
|
||||
) = await self._parse_element(client, iq_elt, "configuration", NS_FIS_CONFIGURATION)
|
||||
except exceptions.CancelError:
|
||||
return
|
||||
except RootPathException:
|
||||
|
|
@ -990,25 +990,25 @@ class XEP_0329(object):
|
|||
configuration_elt.addChild(form.toElement())
|
||||
client.send(iq_result_elt)
|
||||
|
||||
async def _setConfiguration(self, client, configuration_elt, file_data):
|
||||
async def _set_configuration(self, client, configuration_elt, file_data):
|
||||
form = data_form.findForm(configuration_elt, NS_FIS_CONFIGURATION)
|
||||
for name, value in form.items():
|
||||
if name == 'access_model':
|
||||
await self.host.memory.setFileAccessModel(client, file_data, value)
|
||||
await self.host.memory.set_file_access_model(client, file_data, value)
|
||||
else:
|
||||
# TODO: send a IQ error?
|
||||
log.warning(
|
||||
f"Trying to set a not implemented configuration option: {name}")
|
||||
|
||||
def _onComponentConfigurationSet(self, iq_elt, client):
|
||||
def _on_component_configuration_set(self, iq_elt, client):
|
||||
iq_elt.handled = True
|
||||
defer.ensureDeferred(self.onComponentConfigurationSet(client, iq_elt))
|
||||
defer.ensureDeferred(self.on_component_configuration_set(client, iq_elt))
|
||||
|
||||
async def onComponentConfigurationSet(self, client, iq_elt):
|
||||
async def on_component_configuration_set(self, client, iq_elt):
|
||||
try:
|
||||
(
|
||||
from_jid, configuration_elt, path, namespace, file_data
|
||||
) = await self._parseElement(client, iq_elt, "configuration", NS_FIS_CONFIGURATION)
|
||||
) = await self._parse_element(client, iq_elt, "configuration", NS_FIS_CONFIGURATION)
|
||||
except exceptions.CancelError:
|
||||
return
|
||||
except RootPathException:
|
||||
|
|
@ -1025,20 +1025,20 @@ class XEP_0329(object):
|
|||
client.sendError(iq_elt, 'forbidden')
|
||||
return
|
||||
|
||||
await self._setConfiguration(client, configuration_elt, file_data)
|
||||
await self._set_configuration(client, configuration_elt, file_data)
|
||||
|
||||
iq_result_elt = xmlstream.toResponse(iq_elt, "result")
|
||||
client.send(iq_result_elt)
|
||||
|
||||
# directory creation
|
||||
|
||||
def _createDir(self, service_jid_s, namespace, path, configuration, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def _create_dir(self, service_jid_s, namespace, path, configuration, profile):
|
||||
client = self.host.get_client(profile)
|
||||
service = jid.JID(service_jid_s)
|
||||
return defer.ensureDeferred(self.createDir(
|
||||
return defer.ensureDeferred(self.create_dir(
|
||||
client, service, namespace or None, path, configuration or None))
|
||||
|
||||
async def createDir(
|
||||
async def create_dir(
|
||||
self,
|
||||
client: SatXMPPEntity,
|
||||
service: jid.JID,
|
||||
|
|
@ -1061,12 +1061,12 @@ class XEP_0329(object):
|
|||
configuration_elt.addChild(form.toElement())
|
||||
await iq_elt.send()
|
||||
|
||||
def _onComponentCreateDir(self, iq_elt, client):
|
||||
def _on_component_create_dir(self, iq_elt, client):
|
||||
iq_elt.handled = True
|
||||
defer.ensureDeferred(self.onComponentCreateDir(client, iq_elt))
|
||||
defer.ensureDeferred(self.on_component_create_dir(client, iq_elt))
|
||||
|
||||
async def onComponentCreateDir(self, client, iq_elt):
|
||||
peer_jid, owner = client.getOwnerAndPeer(iq_elt)
|
||||
async def on_component_create_dir(self, client, iq_elt):
|
||||
peer_jid, owner = client.get_owner_and_peer(iq_elt)
|
||||
if peer_jid.host not in client._file_sharing_allowed_hosts:
|
||||
client.sendError(iq_elt, 'forbidden')
|
||||
return
|
||||
|
|
@ -1084,8 +1084,8 @@ class XEP_0329(object):
|
|||
)
|
||||
client.sendError(iq_elt, 'forbidden', "You can't create a directory there")
|
||||
return
|
||||
# when going further into the path, the permissions will be checked by getFiles
|
||||
files_data = await self.host.memory.getFiles(
|
||||
# when going further into the path, the permissions will be checked by get_files
|
||||
files_data = await self.host.memory.get_files(
|
||||
client,
|
||||
peer_jid=peer_jid,
|
||||
path=path.parent,
|
||||
|
|
@ -1107,7 +1107,7 @@ class XEP_0329(object):
|
|||
except StopIteration:
|
||||
configuration_elt = None
|
||||
|
||||
await self.host.memory.setFile(
|
||||
await self.host.memory.set_file(
|
||||
client,
|
||||
path.name,
|
||||
path=path.parent,
|
||||
|
|
@ -1118,7 +1118,7 @@ class XEP_0329(object):
|
|||
)
|
||||
|
||||
if configuration_elt is not None:
|
||||
file_data = (await self.host.memory.getFiles(
|
||||
file_data = (await self.host.memory.get_files(
|
||||
client,
|
||||
peer_jid=peer_jid,
|
||||
path=path.parent,
|
||||
|
|
@ -1127,14 +1127,14 @@ class XEP_0329(object):
|
|||
owner=owner,
|
||||
))[0]
|
||||
|
||||
await self._setConfiguration(client, configuration_elt, file_data)
|
||||
await self._set_configuration(client, configuration_elt, file_data)
|
||||
|
||||
iq_result_elt = xmlstream.toResponse(iq_elt, "result")
|
||||
client.send(iq_result_elt)
|
||||
|
||||
# file methods #
|
||||
|
||||
def _serializeData(self, files_data):
|
||||
def _serialize_data(self, files_data):
|
||||
for file_data in files_data:
|
||||
for key, value in file_data.items():
|
||||
file_data[key] = (
|
||||
|
|
@ -1142,14 +1142,14 @@ class XEP_0329(object):
|
|||
)
|
||||
return files_data
|
||||
|
||||
def _listFiles(self, target_jid, path, extra, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def _list_files(self, target_jid, path, extra, profile):
|
||||
client = self.host.get_client(profile)
|
||||
target_jid = client.jid if not target_jid else jid.JID(target_jid)
|
||||
d = defer.ensureDeferred(self.listFiles(client, target_jid, path or None))
|
||||
d.addCallback(self._serializeData)
|
||||
d = defer.ensureDeferred(self.list_files(client, target_jid, path or None))
|
||||
d.addCallback(self._serialize_data)
|
||||
return d
|
||||
|
||||
async def listFiles(self, client, peer_jid, path=None, extra=None):
|
||||
async def list_files(self, client, peer_jid, path=None, extra=None):
|
||||
"""List file shared by an entity
|
||||
|
||||
@param peer_jid(jid.JID): jid of the sharing entity
|
||||
|
|
@ -1164,21 +1164,21 @@ class XEP_0329(object):
|
|||
if path:
|
||||
query_elt["node"] = path
|
||||
iq_result_elt = await iq_elt.send()
|
||||
return await self._parseResult(client, peer_jid, iq_result_elt)
|
||||
return await self._parse_result(client, peer_jid, iq_result_elt)
|
||||
|
||||
def _localSharesGet(self, profile):
|
||||
client = self.host.getClient(profile)
|
||||
return self.localSharesGet(client)
|
||||
def _local_shares_get(self, profile):
|
||||
client = self.host.get_client(profile)
|
||||
return self.local_shares_get(client)
|
||||
|
||||
def localSharesGet(self, client):
|
||||
return list(client._XEP_0329_root_node.getSharedPaths().keys())
|
||||
def local_shares_get(self, client):
|
||||
return list(client._XEP_0329_root_node.get_shared_paths().keys())
|
||||
|
||||
def _sharePath(self, name, path, access, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def _share_path(self, name, path, access, profile):
|
||||
client = self.host.get_client(profile)
|
||||
access = json.loads(access)
|
||||
return self.sharePath(client, name or None, path, access)
|
||||
return self.share_path(client, name or None, path, access)
|
||||
|
||||
def sharePath(self, client, name, path, access):
|
||||
def share_path(self, client, name, path, access):
|
||||
if client.is_component:
|
||||
raise exceptions.ClientTypeError
|
||||
if not os.path.exists(path):
|
||||
|
|
@ -1193,7 +1193,7 @@ class XEP_0329(object):
|
|||
if os.path.isfile(path):
|
||||
# we have a single file, the workflow is diferrent as we store all single
|
||||
# files in the same dir
|
||||
node = node.getOrCreate(SINGLE_FILES_DIR)
|
||||
node = node.get_or_create(SINGLE_FILES_DIR)
|
||||
|
||||
if not name:
|
||||
name = os.path.basename(path.rstrip(" /"))
|
||||
|
|
@ -1212,18 +1212,18 @@ class XEP_0329(object):
|
|||
"[{profile}]".format( new_name=new_name, profile=client.profile)))
|
||||
|
||||
ShareNode(name=name, parent=node, type_=node_type, access=access, path=path)
|
||||
self.host.bridge.FISSharedPathNew(path, name, client.profile)
|
||||
self.host.bridge.fis_shared_path_new(path, name, client.profile)
|
||||
return name
|
||||
|
||||
def _unsharePath(self, path, profile):
|
||||
client = self.host.getClient(profile)
|
||||
return self.unsharePath(client, path)
|
||||
def _unshare_path(self, path, profile):
|
||||
client = self.host.get_client(profile)
|
||||
return self.unshare_path(client, path)
|
||||
|
||||
def unsharePath(self, client, path):
|
||||
nodes = client._XEP_0329_root_node.findByLocalPath(path)
|
||||
def unshare_path(self, client, path):
|
||||
nodes = client._XEP_0329_root_node.find_by_local_path(path)
|
||||
for node in nodes:
|
||||
node.removeFromParent()
|
||||
self.host.bridge.FISSharedPathRemoved(path, client.profile)
|
||||
node.remove_from_parent()
|
||||
self.host.bridge.fis_shared_path_removed(path, client.profile)
|
||||
|
||||
|
||||
@implementer(iwokkel.IDisco)
|
||||
|
|
@ -1236,36 +1236,36 @@ class XEP_0329_handler(xmlstream.XMPPHandler):
|
|||
def connectionInitialized(self):
|
||||
if self.parent.is_component:
|
||||
self.xmlstream.addObserver(
|
||||
IQ_FIS_REQUEST, self.plugin_parent.onComponentRequest, client=self.parent
|
||||
IQ_FIS_REQUEST, self.plugin_parent.on_component_request, client=self.parent
|
||||
)
|
||||
self.xmlstream.addObserver(
|
||||
IQ_FIS_AFFILIATION_GET,
|
||||
self.plugin_parent._onComponentAffiliationsGet,
|
||||
self.plugin_parent._on_component_affiliations_get,
|
||||
client=self.parent
|
||||
)
|
||||
self.xmlstream.addObserver(
|
||||
IQ_FIS_AFFILIATION_SET,
|
||||
self.plugin_parent._onComponentAffiliationsSet,
|
||||
self.plugin_parent._on_component_affiliations_set,
|
||||
client=self.parent
|
||||
)
|
||||
self.xmlstream.addObserver(
|
||||
IQ_FIS_CONFIGURATION_GET,
|
||||
self.plugin_parent._onComponentConfigurationGet,
|
||||
self.plugin_parent._on_component_configuration_get,
|
||||
client=self.parent
|
||||
)
|
||||
self.xmlstream.addObserver(
|
||||
IQ_FIS_CONFIGURATION_SET,
|
||||
self.plugin_parent._onComponentConfigurationSet,
|
||||
self.plugin_parent._on_component_configuration_set,
|
||||
client=self.parent
|
||||
)
|
||||
self.xmlstream.addObserver(
|
||||
IQ_FIS_CREATE_DIR,
|
||||
self.plugin_parent._onComponentCreateDir,
|
||||
self.plugin_parent._on_component_create_dir,
|
||||
client=self.parent
|
||||
)
|
||||
else:
|
||||
self.xmlstream.addObserver(
|
||||
IQ_FIS_REQUEST, self.plugin_parent.onRequest, client=self.parent
|
||||
IQ_FIS_REQUEST, self.plugin_parent.on_request, client=self.parent
|
||||
)
|
||||
|
||||
def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
|
||||
|
|
|
|||
Loading…
Reference in a new issue