Commit b99632ab authored by Philipp Hörist's avatar Philipp Hörist

Fix pylint errors

parent 691678b0
...@@ -404,7 +404,7 @@ def stage3_next_form(self, command): ...@@ -404,7 +404,7 @@ def stage3_next_form(self, command):
self.commandnode = command.getAttr('node') self.commandnode = command.getAttr('node')
if command.getTag('x'): if command.getTag('x'):
self.dataform = dataforms.ExtendForm(node=command.getTag('x')) self.dataform = dataforms.extend_form(node=command.getTag('x'))
self.data_form_widget.set_sensitive(True) self.data_form_widget.set_sensitive(True)
try: try:
......
...@@ -588,7 +588,7 @@ def on_avatar_eventbox_button_press_event(self, widget, event): ...@@ -588,7 +588,7 @@ def on_avatar_eventbox_button_press_event(self, widget, event):
def on_location_eventbox_button_release_event(self, widget, event): def on_location_eventbox_button_release_event(self, widget, event):
if 'geoloc' in self.contact.pep: if 'geoloc' in self.contact.pep:
location = self.contact.pep['geoloc']._pep_specific_data location = self.contact.pep['geoloc'].data
if ('lat' in location) and ('lon' in location): if ('lat' in location) and ('lon' in location):
uri = 'https://www.openstreetmap.org/?' + \ uri = 'https://www.openstreetmap.org/?' + \
'mlat=%(lat)s&mlon=%(lon)s&zoom=16' % {'lat': location['lat'], 'mlat=%(lat)s&mlon=%(lon)s&zoom=16' % {'lat': location['lat'],
......
...@@ -448,7 +448,7 @@ def append(self, stanza): ...@@ -448,7 +448,7 @@ def append(self, stanza):
elif child.getName() == 'x': elif child.getName() == 'x':
if child.getNamespace() == nbxmpp.NS_DATA: if child.getNamespace() == nbxmpp.NS_DATA:
from gajim.common.modules import dataforms from gajim.common.modules import dataforms
data.append(dataforms.ExtendForm(node=child)) data.append(dataforms.extend_form(node=child))
if nbxmpp.NS_MUC not in features: if nbxmpp.NS_MUC not in features:
# Not a MUC, don't cache info # Not a MUC, don't cache info
......
...@@ -382,14 +382,14 @@ def unsubscribe_agent(self, agent): ...@@ -382,14 +382,14 @@ def unsubscribe_agent(self, agent):
def update_contact(self, jid, name, groups): def update_contact(self, jid, name, groups):
if self.connection: if self.connection:
self.getRoster().setItem(jid=jid, name=name, groups=groups) self.getRoster().set_item(jid=jid, name=name, groups=groups)
def update_contacts(self, contacts): def update_contacts(self, contacts):
""" """
Update multiple roster items Update multiple roster items
""" """
if self.connection: if self.connection:
self.getRoster().setItemMulti(contacts) self.getRoster().set_item_multi(contacts)
def new_account(self, name, config, sync=False): def new_account(self, name, config, sync=False):
""" """
...@@ -1578,7 +1578,7 @@ def unsubscribe_agent(self, agent): ...@@ -1578,7 +1578,7 @@ def unsubscribe_agent(self, agent):
iq.setID(id_) iq.setID(id_)
self.awaiting_answers[id_] = (AGENT_REMOVED, agent) self.awaiting_answers[id_] = (AGENT_REMOVED, agent)
self.connection.send(iq) self.connection.send(iq)
self.getRoster().delItem(agent) self.getRoster().del_item(agent)
def send_new_account_infos(self, form, is_form): def send_new_account_infos(self, form, is_form):
if is_form: if is_form:
......
...@@ -926,7 +926,7 @@ def generate(self): ...@@ -926,7 +926,7 @@ def generate(self):
form_tag = feature_tag.getTag('x', namespace=nbxmpp.NS_DATA) form_tag = feature_tag.getTag('x', namespace=nbxmpp.NS_DATA)
if not form_tag: if not form_tag:
return return
self.dataform = dataforms.ExtendForm(node=form_tag) self.dataform = dataforms.extend_form(node=form_tag)
for f in self.dataform.iter_fields(): for f in self.dataform.iter_fields():
if f.var == 'stream-method' and f.type_ == 'list-single': if f.var == 'stream-method' and f.type_ == 'list-single':
values = [o[1] for o in f.options] values = [o[1] for o in f.options]
......
This diff is collapsed.
...@@ -44,10 +44,10 @@ class AtomData(AbstractPEPData): ...@@ -44,10 +44,10 @@ class AtomData(AbstractPEPData):
type_ = PEPEventType.ATOM type_ = PEPEventType.ATOM
def __init__(self, atom): def __init__(self, atom):
self._pep_specific_data = atom self.data = atom
def get_entry(self): def get_entry(self):
return self._pep_specific_data return self.data
class Atom(AbstractPEPModule): class Atom(AbstractPEPModule):
......
...@@ -39,22 +39,22 @@ class WrongFieldValue(Error): ...@@ -39,22 +39,22 @@ class WrongFieldValue(Error):
# helper class to change class of already existing object # helper class to change class of already existing object
class ExtendedNode(nbxmpp.Node, object): class ExtendedNode(nbxmpp.Node):
@classmethod @classmethod
def __new__(cls, *a, **b): def __new__(cls, *args, **kwargs):
if 'extend' not in b.keys() or not b['extend']: if 'extend' not in kwargs.keys() or not kwargs['extend']:
return object.__new__(cls) return object.__new__(cls)
extend = b['extend'] extend = kwargs['extend']
assert issubclass(cls, extend.__class__) assert issubclass(cls, extend.__class__)
extend.__class__ = cls extend.__class__ = cls
return extend return extend
# helper to create fields from scratch # helper to create fields from scratch
def Field(typ, **attrs): def create_field(typ, **attrs):
''' Helper function to create a field of given type. ''' ''' Helper function to create a field of given type. '''
f = { field = {
'boolean': BooleanField, 'boolean': BooleanField,
'fixed': StringField, 'fixed': StringField,
'hidden': StringField, 'hidden': StringField,
...@@ -66,18 +66,18 @@ def Field(typ, **attrs): ...@@ -66,18 +66,18 @@ def Field(typ, **attrs):
'list-single': ListSingleField, 'list-single': ListSingleField,
'text-multi': TextMultiField, 'text-multi': TextMultiField,
}[typ](typ=typ, **attrs) }[typ](typ=typ, **attrs)
return f return field
def ExtendField(node): def extend_field(node):
""" """
Helper function to extend a node to field of appropriate type Helper function to extend a node to field of appropriate type
""" """
# when validation (XEP-122) will go in, we could have another classes # when validation (XEP-122) will go in, we could have another classes
# like DateTimeField - so that dicts in Field() and ExtendField() will # like DateTimeField - so that dicts in create_field() and
# be different... # extend_field() will be different...
typ = node.getAttr('type') typ = node.getAttr('type')
f = { field = {
'boolean': BooleanField, 'boolean': BooleanField,
'fixed': StringField, 'fixed': StringField,
'hidden': StringField, 'hidden': StringField,
...@@ -89,25 +89,24 @@ def ExtendField(node): ...@@ -89,25 +89,24 @@ def ExtendField(node):
'list-single': ListSingleField, 'list-single': ListSingleField,
'text-multi': TextMultiField, 'text-multi': TextMultiField,
} }
if typ not in f: if typ not in field:
typ = 'text-single' typ = 'text-single'
return f[typ](extend=node) return field[typ](extend=node)
def ExtendForm(node): def extend_form(node):
""" """
Helper function to extend a node to form of appropriate type Helper function to extend a node to form of appropriate type
""" """
if node.getTag('reported') is not None: if node.getTag('reported') is not None:
return MultipleDataForm(extend=node) return MultipleDataForm(extend=node)
else: return SimpleDataForm(extend=node)
return SimpleDataForm(extend=node)
class DataField(ExtendedNode): class DataField(ExtendedNode):
""" """
Keeps data about one field - var, field type, labels, instructions... Base Keeps data about one field - var, field type, labels, instructions... Base
class for different kinds of fields. Use Field() function to construct one class for different kinds of fields. Use create_field() function to construct one
of these of these
""" """
...@@ -136,10 +135,10 @@ def type_(self): ...@@ -136,10 +135,10 @@ def type_(self):
'text-private', 'text-single'. If you set this to something different, 'text-private', 'text-single'. If you set this to something different,
DataField will store given name, but treat all data as text-single DataField will store given name, but treat all data as text-single
""" """
t = self.getAttr('type') type_ = self.getAttr('type')
if t is None: if type_ is None:
return 'text-single' return 'text-single'
return t return type_
@type_.setter @type_.setter
def type_(self, value): def type_(self, value):
...@@ -199,9 +198,9 @@ def description(self, value): ...@@ -199,9 +198,9 @@ def description(self, value):
@description.deleter @description.deleter
def description(self): def description(self):
t = self.getTag('desc') desc = self.getTag('desc')
if t is not None: if desc is not None:
self.delChild(t) self.delChild(desc)
@property @property
def required(self): def required(self):
...@@ -212,10 +211,10 @@ def required(self): ...@@ -212,10 +211,10 @@ def required(self):
@required.setter @required.setter
def required(self, value): def required(self, value):
t = self.getTag('required') required = self.getTag('required')
if t and not value: if required and not value:
self.delChild(t) self.delChild(required)
elif not t and value: elif not required and value:
self.addChild('required') self.addChild('required')
@property @property
...@@ -234,11 +233,12 @@ def media(self, value): ...@@ -234,11 +233,12 @@ def media(self, value):
@media.deleter @media.deleter
def media(self): def media(self):
t = self.getTag('media') media = self.getTag('media')
if t is not None: if media is not None:
self.delChild(t) self.delChild(media)
def is_valid(self): @staticmethod
def is_valid():
return True return True
...@@ -306,12 +306,12 @@ def value(self): ...@@ -306,12 +306,12 @@ def value(self):
""" """
Value of field. May contain True, False or None Value of field. May contain True, False or None
""" """
v = self.getTagData('value') value = self.getTagData('value')
if v in ('0', 'false'): if value in ('0', 'false'):
return False return False
if v in ('1', 'true'): if value in ('1', 'true'):
return True return True
if v is None: if value is None:
return False # default value is False return False # default value is False
raise WrongFieldValue raise WrongFieldValue
...@@ -321,9 +321,9 @@ def value(self, value): ...@@ -321,9 +321,9 @@ def value(self, value):
@value.deleter @value.deleter
def value(self): def value(self):
t = self.getTag('value') value = self.getTag('value')
if t is not None: if value is not None:
self.delChild(t) self.delChild(value)
class StringField(DataField): class StringField(DataField):
...@@ -366,13 +366,13 @@ def options(self): ...@@ -366,13 +366,13 @@ def options(self):
""" """
options = [] options = []
for element in self.getTags('option'): for element in self.getTags('option'):
v = element.getTagData('value') value = element.getTagData('value')
if v is None: if value is None:
raise WrongFieldValue raise WrongFieldValue
label = element.getAttr('label') label = element.getAttr('label')
if not label: if not label:
label = v label = value
options.append((label, v)) options.append((label, value))
return options return options
@options.setter @options.setter
...@@ -389,13 +389,13 @@ def options(self): ...@@ -389,13 +389,13 @@ def options(self):
def iter_options(self): def iter_options(self):
for element in self.iterTags('option'): for element in self.iterTags('option'):
v = element.getTagData('value') value = element.getTagData('value')
if v is None: if value is None:
raise WrongFieldValue raise WrongFieldValue
label = element.getAttr('label') label = element.getAttr('label')
if not label: if not label:
label = v label = value
yield (v, label) yield (value, label)
class ListSingleField(ListField, StringField): class ListSingleField(ListField, StringField):
...@@ -469,7 +469,7 @@ class JidMultiField(ListMultiField): ...@@ -469,7 +469,7 @@ class JidMultiField(ListMultiField):
Covers jid-multi fields Covers jid-multi fields
""" """
def is_valid(self): def is_valid(self):
if len(self.values): if self.values:
for value in self.values: for value in self.values:
try: try:
helpers.parse_jid(value) helpers.parse_jid(value)
...@@ -526,7 +526,7 @@ def __init__(self, fields=None, associated=None, extend=None): ...@@ -526,7 +526,7 @@ def __init__(self, fields=None, associated=None, extend=None):
if fields is None: if fields is None:
for field in self.iterTags('field'): for field in self.iterTags('field'):
if not isinstance(field, DataField): if not isinstance(field, DataField):
ExtendField(field) extend_field(field)
self.vars[field.var] = field self.vars[field.var] = field
else: else:
for field in self.getTags('field'): for field in self.getTags('field'):
...@@ -545,7 +545,7 @@ def fields(self, fields): ...@@ -545,7 +545,7 @@ def fields(self, fields):
del self.fields del self.fields
for field in fields: for field in fields:
if not isinstance(field, DataField): if not isinstance(field, DataField):
ExtendField(field) extend_field(field)
self.addChild(node=field) self.addChild(node=field)
@fields.deleter @fields.deleter
...@@ -572,8 +572,8 @@ def __getitem__(self, item): ...@@ -572,8 +572,8 @@ def __getitem__(self, item):
return self.vars[item] return self.vars[item]
def is_valid(self): def is_valid(self):
for f in self.iter_fields(): for field in self.iter_fields():
if not f.is_valid(): if not field.is_valid():
return False return False
return True return True
...@@ -660,27 +660,29 @@ def __init__(self, type_=None, title=None, instructions=None, fields=None, ...@@ -660,27 +660,29 @@ def __init__(self, type_=None, title=None, instructions=None, fields=None,
DataRecord.__init__(self, fields=fields, extend=self, associated=self) DataRecord.__init__(self, fields=fields, extend=self, associated=self)
def get_purged(self): def get_purged(self):
c = SimpleDataForm(extend=self) simple_form = SimpleDataForm(extend=self)
del c.title del simple_form.title
c.instructions = '' simple_form.instructions = ''
to_be_removed = [] to_be_removed = []
for f in c.iter_fields(): for field in simple_form.iter_fields():
if f.required: if field.required:
# add <value> if there is not # add <value> if there is not
if hasattr(f, 'value') and not f.value: if hasattr(field, 'value') and not field.value:
f.value = '' field.value = ''
# Keep all required fields # Keep all required fields
continue continue
if ((hasattr(f, 'value') and not f.value and f.value != 0) or if ((hasattr(field, 'value') and
(hasattr(f, 'values') and len(f.values) == 0)): not field.value and
to_be_removed.append(f) field.value != 0) or
(hasattr(field, 'values') and not field.values)):
to_be_removed.append(field)
else: else:
del f.label del field.label
del f.description del field.description
del f.media del field.media
for f in to_be_removed: for field in to_be_removed:
c.delChild(f) simple_form.delChild(field)
return c return simple_form
class MultipleDataForm(DataForm): class MultipleDataForm(DataForm):
......
...@@ -130,7 +130,7 @@ def _config_received(self, stanza): ...@@ -130,7 +130,7 @@ def _config_received(self, stanza):
for form in payload: for form in payload:
if form.getNamespace() == nbxmpp.NS_DATA: if form.getNamespace() == nbxmpp.NS_DATA:
dataform = dataforms.ExtendForm(node=form) dataform = dataforms.extend_form(node=form)
log.info('Config form received for %s', room_jid) log.info('Config form received for %s', room_jid)
app.nec.push_incoming_event(MucOwnerReceivedEvent( app.nec.push_incoming_event(MucOwnerReceivedEvent(
None, None,
......
...@@ -211,10 +211,10 @@ def __eq__(self, other): ...@@ -211,10 +211,10 @@ def __eq__(self, other):
return other == self.type_ return other == self.type_
def __bool__(self): def __bool__(self):
return self._pep_specific_data is not None return self.data is not None
def __str__(self): def __str__(self):
return str(self._pep_specific_data) return str(self.data)
class PEPReceivedEvent(NetworkIncomingEvent): class PEPReceivedEvent(NetworkIncomingEvent):
......
...@@ -138,15 +138,15 @@ def unsubscribe(self, jid, remove_auth=True): ...@@ -138,15 +138,15 @@ def unsubscribe(self, jid, remove_auth=True):
if not app.account_is_connected(self._account): if not app.account_is_connected(self._account):
return return
if remove_auth: if remove_auth:
self._con.getRoster().delItem(jid) self._con.getRoster().del_item(jid)
jid_list = app.config.get_per('contacts') jid_list = app.config.get_per('contacts')
for j in jid_list: for j in jid_list:
if j.startswith(jid): if j.startswith(jid):
app.config.del_per('contacts', j) app.config.del_per('contacts', j)
else: else:
log.info('Unsubscribe from %s', jid) log.info('Unsubscribe from %s', jid)
self._con.getRoster().Unsubscribe(jid) self._con.getRoster().unsubscribe(jid)
self._con.getRoster().setItem(jid) self._con.getRoster().set_item(jid)
def subscribe(self, jid, msg=None, name='', groups=None, auto_auth=False): def subscribe(self, jid, msg=None, name='', groups=None, auto_auth=False):
if not app.account_is_connected(self._account): if not app.account_is_connected(self._account):
......
...@@ -254,7 +254,7 @@ def _received_pb_configuration(self, _con, stanza, node): ...@@ -254,7 +254,7 @@ def _received_pb_configuration(self, _con, stanza, node):
app.nec.push_incoming_event(PubSubConfigReceivedEvent( app.nec.push_incoming_event(PubSubConfigReceivedEvent(
None, conn=self._con, node=node, None, conn=self._con, node=node,
form=dataforms.ExtendForm(node=form))) form=dataforms.extend_form(node=form)))
@staticmethod @staticmethod
def _default_callback(_con, stanza, *args, **kwargs): def _default_callback(_con, stanza, *args, **kwargs):
......
...@@ -45,7 +45,7 @@ def load_roster(self): ...@@ -45,7 +45,7 @@ def load_roster(self):
account_jid = self._con.get_own_jid().getStripped() account_jid = self._con.get_own_jid().getStripped()
data = app.logger.get_roster(account_jid) data = app.logger.get_roster(account_jid)
if data: if data:
self.setRaw(data) self.set_raw(data)
for jid, item in self._data.items(): for jid, item in self._data.items():
app.nec.push_incoming_event(NetworkEvent( app.nec.push_incoming_event(NetworkEvent(
'roster-info', 'roster-info',
...@@ -170,7 +170,7 @@ def _get_item_attrs(item, update=True): ...@@ -170,7 +170,7 @@ def _get_item_attrs(item, update=True):
attrs = item.getAttrs() attrs = item.getAttrs()
del attrs['jid'] del attrs['jid']
groups = set([group.getData() for group in item.getTags('group')]) groups = {group.getData() for group in item.getTags('group')}
attrs['groups'] = list(groups) attrs['groups'] = list(groups)
if update: if update:
...@@ -241,14 +241,14 @@ def _presence_received(self, _con, pres): ...@@ -241,14 +241,14 @@ def _presence_received(self, _con, pres):
self._data[jid]['ask'], self._data[jid]['ask'],
self._data[jid]['groups']) self._data[jid]['groups'])
def _getItemData(self, jid, dataname): def _get_item_data(self, jid, dataname):