Compare commits
8 Commits
slix-1.5.1
...
slix-1.5.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7bd224182 | ||
|
|
bac1e9b44a | ||
|
|
b62f0e90c1 | ||
|
|
9ace053992 | ||
|
|
c7cd2fcf33 | ||
|
|
e57289358f | ||
|
|
4aa35c11ab | ||
|
|
d6f7d32bbe |
@@ -29,61 +29,61 @@ class MUCPresence(ElementBase):
|
||||
affiliations = {'', }
|
||||
roles = {'', }
|
||||
|
||||
def get_xml_item(self):
|
||||
def get_item_attr(self, attr, default):
|
||||
item = self.xml.find('{http://jabber.org/protocol/muc#user}item')
|
||||
if item is None:
|
||||
return default
|
||||
return item.get(attr)
|
||||
|
||||
def set_item_attr(self, attr, value):
|
||||
item = self.xml.find('{http://jabber.org/protocol/muc#user}item')
|
||||
if item is None:
|
||||
item = ET.Element('{http://jabber.org/protocol/muc#user}item')
|
||||
self.xml.append(item)
|
||||
item.attrib[attr] = value
|
||||
return item
|
||||
|
||||
def del_item_attr(self, attr):
|
||||
item = self.xml.find('{http://jabber.org/protocol/muc#user}item')
|
||||
if item is not None and attr in item.attrib:
|
||||
del item.attrib[attr]
|
||||
|
||||
def get_affiliation(self):
|
||||
#TODO if no affilation, set it to the default and return default
|
||||
item = self.get_xml_item()
|
||||
return item.get('affiliation', '')
|
||||
return self.get_item_attr('affiliation', '')
|
||||
|
||||
def set_affiliation(self, value):
|
||||
item = self.get_xml_item()
|
||||
#TODO check for valid affiliation
|
||||
item.attrib['affiliation'] = value
|
||||
self.set_item_attr('affiliation', value)
|
||||
return self
|
||||
|
||||
def del_affiliation(self):
|
||||
item = self.get_xml_item()
|
||||
#TODO set default affiliation
|
||||
if 'affiliation' in item.attrib: del item.attrib['affiliation']
|
||||
# TODO: set default affiliation
|
||||
self.del_item_attr('affiliation')
|
||||
return self
|
||||
|
||||
def get_jid(self):
|
||||
item = self.get_xml_item()
|
||||
return JID(item.get('jid', ''))
|
||||
return JID(self.get_item_attr('jid', ''))
|
||||
|
||||
def set_jid(self, value):
|
||||
item = self.get_xml_item()
|
||||
if not isinstance(value, str):
|
||||
value = str(value)
|
||||
item.attrib['jid'] = value
|
||||
self.set_item_attr('jid', value)
|
||||
return self
|
||||
|
||||
def del_jid(self):
|
||||
item = self.get_xml_item()
|
||||
if 'jid' in item.attrib: del item.attrib['jid']
|
||||
self.del_item_attr('jid')
|
||||
return self
|
||||
|
||||
def get_role(self):
|
||||
item = self.get_xml_item()
|
||||
#TODO get default role, set default role if none
|
||||
return item.get('role', '')
|
||||
return self.get_item_attr('role', '')
|
||||
|
||||
def set_role(self, value):
|
||||
item = self.get_xml_item()
|
||||
#TODO check for valid role
|
||||
item.attrib['role'] = value
|
||||
# TODO: check for valid role
|
||||
self.set_item_attr('role', value)
|
||||
return self
|
||||
|
||||
def del_role(self):
|
||||
item = self.get_xml_item()
|
||||
#TODO set default role
|
||||
if 'role' in item.attrib: del item.attrib['role']
|
||||
# TODO: set default role
|
||||
self.del_item_attr('role')
|
||||
return self
|
||||
|
||||
def get_nick(self):
|
||||
|
||||
@@ -28,7 +28,9 @@ class UploadServiceNotFound(FileUploadError):
|
||||
pass
|
||||
|
||||
class FileTooBig(FileUploadError):
|
||||
pass
|
||||
def __str__(self):
|
||||
return 'File size too large: {} (max: {} bytes)' \
|
||||
.format(self.args[0], self.args[1])
|
||||
|
||||
class HTTPError(FileUploadError):
|
||||
def __str__(self):
|
||||
@@ -116,7 +118,7 @@ class XEP_0363(BasePlugin):
|
||||
except (TypeError, ValueError):
|
||||
log.error('Invalid max size received from HTTP File Upload service')
|
||||
self.max_file_size = float('+inf')
|
||||
break
|
||||
break
|
||||
|
||||
if input_file is None:
|
||||
input_file = open(filename, 'rb')
|
||||
@@ -126,7 +128,7 @@ class XEP_0363(BasePlugin):
|
||||
input_file.seek(0)
|
||||
|
||||
if size > self.max_file_size:
|
||||
raise FileTooBig()
|
||||
raise FileTooBig(size, self.max_file_size)
|
||||
|
||||
if content_type is None:
|
||||
content_type = guess_type(filename)[0]
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
# We don't want to have to import the entire library
|
||||
# just to get the version info for setup.py
|
||||
|
||||
__version__ = '1.5.1'
|
||||
__version_info__ = (1, 5, 1)
|
||||
__version__ = '1.5.2'
|
||||
__version_info__ = (1, 5, 2)
|
||||
|
||||
Reference in New Issue
Block a user