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):
self.commandnode = command.getAttr('node')
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)
try:
......
......@@ -588,7 +588,7 @@ def on_avatar_eventbox_button_press_event(self, widget, event):
def on_location_eventbox_button_release_event(self, widget, event):
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):
uri = 'https://www.openstreetmap.org/?' + \
'mlat=%(lat)s&mlon=%(lon)s&zoom=16' % {'lat': location['lat'],
......
......@@ -448,7 +448,7 @@ def append(self, stanza):
elif child.getName() == 'x':
if child.getNamespace() == nbxmpp.NS_DATA:
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:
# Not a MUC, don't cache info
......
......@@ -382,14 +382,14 @@ def unsubscribe_agent(self, agent):
def update_contact(self, jid, name, groups):
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):
"""
Update multiple roster items
"""
if self.connection:
self.getRoster().setItemMulti(contacts)
self.getRoster().set_item_multi(contacts)
def new_account(self, name, config, sync=False):
"""
......@@ -1578,7 +1578,7 @@ def unsubscribe_agent(self, agent):
iq.setID(id_)
self.awaiting_answers[id_] = (AGENT_REMOVED, agent)
self.connection.send(iq)
self.getRoster().delItem(agent)
self.getRoster().del_item(agent)
def send_new_account_infos(self, form, is_form):
if is_form:
......
......@@ -926,7 +926,7 @@ def generate(self):
form_tag = feature_tag.getTag('x', namespace=nbxmpp.NS_DATA)
if not form_tag:
return
self.dataform = dataforms.ExtendForm(node=form_tag)
self.dataform = dataforms.extend_form(node=form_tag)
for f in self.dataform.iter_fields():
if f.var == 'stream-method' and f.type_ == 'list-single':
values = [o[1] for o in f.options]
......
This diff is collapsed.
......@@ -44,10 +44,10 @@ class AtomData(AbstractPEPData):
type_ = PEPEventType.ATOM
def __init__(self, atom):
self._pep_specific_data = atom
self.data = atom
def get_entry(self):
return self._pep_specific_data
return self.data
class Atom(AbstractPEPModule):
......
......@@ -39,22 +39,22 @@ class WrongFieldValue(Error):
# helper class to change class of already existing object
class ExtendedNode(nbxmpp.Node, object):
class ExtendedNode(nbxmpp.Node):
@classmethod
def __new__(cls, *a, **b):
if 'extend' not in b.keys() or not b['extend']:
def __new__(cls, *args, **kwargs):
if 'extend' not in kwargs.keys() or not kwargs['extend']:
return object.__new__(cls)
extend = b['extend']
extend = kwargs['extend']
assert issubclass(cls, extend.__class__)
extend.__class__ = cls
return extend
# helper to create fields from scratch
def Field(typ, **attrs):
def create_field(typ, **attrs):
''' Helper function to create a field of given type. '''
f = {
field = {
'boolean': BooleanField,
'fixed': StringField,
'hidden': StringField,
......@@ -66,18 +66,18 @@ def Field(typ, **attrs):
'list-single': ListSingleField,
'text-multi': TextMultiField,
}[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
"""
# when validation (XEP-122) will go in, we could have another classes
# like DateTimeField - so that dicts in Field() and ExtendField() will
# be different...
# like DateTimeField - so that dicts in create_field() and
# extend_field() will be different...
typ = node.getAttr('type')
f = {
field = {
'boolean': BooleanField,
'fixed': StringField,
'hidden': StringField,
......@@ -89,25 +89,24 @@ def ExtendField(node):
'list-single': ListSingleField,
'text-multi': TextMultiField,
}
if typ not in f:
if typ not in field:
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
"""
if node.getTag('reported') is not None:
return MultipleDataForm(extend=node)
else:
return SimpleDataForm(extend=node)
return SimpleDataForm(extend=node)
class DataField(ExtendedNode):
"""
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
"""
......@@ -136,10 +135,10 @@ def type_(self):
'text-private', 'text-single'. If you set this to something different,
DataField will store given name, but treat all data as text-single
"""
t = self.getAttr('type')
if t is None:
type_ = self.getAttr('type')
if type_ is None:
return 'text-single'
return t
return type_
@type_.setter
def type_(self, value):
......@@ -199,9 +198,9 @@ def description(self, value):
@description.deleter
def description(self):
t = self.getTag('desc')
if t is not None:
self.delChild(t)
desc = self.getTag('desc')
if desc is not None:
self.delChild(desc)
@property
def required(self):
......@@ -212,10 +211,10 @@ def required(self):
@required.setter
def required(self, value):
t = self.getTag('required')
if t and not value:
self.delChild(t)
elif not t and value:
required = self.getTag('required')
if required and not value:
self.delChild(required)
elif not required and value:
self.addChild('required')
@property
......@@ -234,11 +233,12 @@ def media(self, value):
@media.deleter
def media(self):
t = self.getTag('media')
if t is not None:
self.delChild(t)
media = self.getTag('media')
if media is not None:
self.delChild(media)
def is_valid(self):
@staticmethod
def is_valid():
return True
......@@ -306,12 +306,12 @@ def value(self):
"""
Value of field. May contain True, False or None
"""
v = self.getTagData('value')
if v in ('0', 'false'):
value = self.getTagData('value')
if value in ('0', 'false'):
return False
if v in ('1', 'true'):
if value in ('1', 'true'):
return True
if v is None:
if value is None:
return False # default value is False
raise WrongFieldValue
......@@ -321,9 +321,9 @@ def value(self, value):
@value.deleter
def value(self):
t = self.getTag('value')
if t is not None:
self.delChild(t)
value = self.getTag('value')
if value is not None:
self.delChild(value)
class StringField(DataField):
......@@ -366,13 +366,13 @@ def options(self):
"""
options = []
for element in self.getTags('option'):
v = element.getTagData('value')
if v is None:
value = element.getTagData('value')
if value is None:
raise WrongFieldValue
label = element.getAttr('label')
if not label:
label = v
options.append((label, v))
label = value
options.append((label, value))
return options
@options.setter
......@@ -389,13 +389,13 @@ def options(self):
def iter_options(self):
for element in self.iterTags('option'):
v = element.getTagData('value')
if v is None:
value = element.getTagData('value')
if value is None:
raise WrongFieldValue
label = element.getAttr('label')
if not label:
label = v
yield (v, label)
label = value
yield (value, label)
class ListSingleField(ListField, StringField):
......@@ -469,7 +469,7 @@ class JidMultiField(ListMultiField):
Covers jid-multi fields
"""
def is_valid(self):
if len(self.values):
if self.values:
for value in self.values:
try:
helpers.parse_jid(value)
......@@ -526,7 +526,7 @@ def __init__(self, fields=None, associated=None, extend=None):
if fields is None:
for field in self.iterTags('field'):
if not isinstance(field, DataField):
ExtendField(field)
extend_field(field)
self.vars[field.var] = field
else:
for field in self.getTags('field'):
......@@ -545,7 +545,7 @@ def fields(self, fields):
del self.fields
for field in fields:
if not isinstance(field, DataField):
ExtendField(field)
extend_field(field)
self.addChild(node=field)
@fields.deleter
......@@ -572,8 +572,8 @@ def __getitem__(self, item):
return self.vars[item]
def is_valid(self):
for f in self.iter_fields():
if not f.is_valid():
for field in self.iter_fields():
if not field.is_valid():
return False
return True
......@@ -660,27 +660,29 @@ def __init__(self, type_=None, title=None, instructions=None, fields=None,
DataRecord.__init__(self, fields=fields, extend=self, associated=self)
def get_purged(self):
c = SimpleDataForm(extend=self)
del c.title
c.instructions = ''
simple_form = SimpleDataForm(extend=self)
del simple_form.title
simple_form.instructions = ''
to_be_removed = []
for f in c.iter_fields():
if f.required:
for field in simple_form.iter_fields():
if field.required:
# add <value> if there is not
if hasattr(f, 'value') and not f.value:
f.value = ''
if hasattr(field, 'value') and not field.value:
field.value = ''
# Keep all required fields
continue
if ((hasattr(f, 'value') and not f.value and f.value != 0) or
(hasattr(f, 'values') and len(f.values) == 0)):
to_be_removed.append(f)
if ((hasattr(field, 'value') and
not field.value and
field.value != 0) or
(hasattr(field, 'values') and not field.values)):
to_be_removed.append(field)
else:
del f.label
del f.description
del f.media
for f in to_be_removed:
c.delChild(f)
return c
del field.label
del field.description
del field.media
for field in to_be_removed:
simple_form.delChild(field)
return simple_form
class MultipleDataForm(DataForm):
......
......@@ -130,7 +130,7 @@ def _config_received(self, stanza):
for form in payload:
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)
app.nec.push_incoming_event(MucOwnerReceivedEvent(
None,
......
......@@ -211,10 +211,10 @@ def __eq__(self, other):
return other == self.type_
def __bool__(self):
return self._pep_specific_data is not None
return self.data is not None
def __str__(self):
return str(self._pep_specific_data)
return str(self.data)
class PEPReceivedEvent(NetworkIncomingEvent):
......
......@@ -138,15 +138,15 @@ def unsubscribe(self, jid, remove_auth=True):
if not app.account_is_connected(self._account):
return
if remove_auth:
self._con.getRoster().delItem(jid)
self._con.getRoster().del_item(jid)
jid_list = app.config.get_per('contacts')
for j in jid_list:
if j.startswith(jid):
app.config.del_per('contacts', j)
else:
log.info('Unsubscribe from %s', jid)
self._con.getRoster().Unsubscribe(jid)
self._con.getRoster().setItem(jid)
self._con.getRoster().unsubscribe(jid)
self._con.getRoster().set_item(jid)
def subscribe(self, jid, msg=None, name='', groups=None, auto_auth=False):
if not app.account_is_connected(self._account):
......
......@@ -254,7 +254,7 @@ def _received_pb_configuration(self, _con, stanza, node):
app.nec.push_incoming_event(PubSubConfigReceivedEvent(
None, conn=self._con, node=node,
form=dataforms.ExtendForm(node=form)))
form=dataforms.extend_form(node=form)))
@staticmethod
def _default_callback(_con, stanza, *args, **kwargs):
......
......@@ -45,7 +45,7 @@ def load_roster(self):
account_jid = self._con.get_own_jid().getStripped()
data = app.logger.get_roster(account_jid)
if data:
self.setRaw(data)
self.set_raw(data)
for jid, item in self._data.items():
app.nec.push_incoming_event(NetworkEvent(
'roster-info',
......@@ -170,7 +170,7 @@ def _get_item_attrs(item, update=True):
attrs = item.getAttrs()
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)
if update:
......@@ -241,14 +241,14 @@ def _presence_received(self, _con, pres):
self._data[jid]['ask'],
self._data[jid]['groups'])
def _getItemData(self, jid, dataname):
def _get_item_data(self, jid, dataname):
"""
Return specific jid's representation in internal format.
"""
jid = jid[:(jid + '/').find('/')]
return self._data[jid][dataname]
def delItem(self, jid):
def del_item(self, jid):
"""
Delete contact 'jid' from roster
"""
......@@ -256,19 +256,19 @@ def delItem(self, jid):
nbxmpp.Iq('set', nbxmpp.NS_ROSTER, payload=[
nbxmpp.Node('item', {'jid': jid, 'subscription': 'remove'})]))
def getGroups(self, jid):
def get_groups(self, jid):
"""
Return groups list that contact 'jid' belongs to
"""
return self._getItemData(jid, 'groups')
return self._get_item_data(jid, 'groups')
def getName(self, jid):
def get_name(self, jid):
"""
Return name of contact 'jid'
"""
return self._getItemData(jid, 'name')
return self._get_item_data(jid, 'name')
def setItem(self, jid, name=None, groups=None):
def set_item(self, jid, name=None, groups=None):
"""
Rename contact 'jid' and sets the groups list that it now belongs to
"""
......@@ -283,7 +283,7 @@ def setItem(self, jid, name=None, groups=None):
item.addChild(node=nbxmpp.Node('group', payload=[group]))
self._con.connection.send(iq)
def setItemMulti(self, items):
def set_item_multi(self, items):
"""
Rename multiple contacts and sets their group lists
"""
......@@ -298,7 +298,7 @@ def setItemMulti(self, items):
item.addChild(node=nbxmpp.Node('group', payload=[group]))
self._con.connection.send(iq)
def getItems(self):
def get_items(self):
"""
Return list of all [bare] JIDs that the roster is currently tracks
"""
......@@ -306,7 +306,7 @@ def getItems(self):
def keys(self):
"""
Same as getItems. Provided for the sake of dictionary interface
Same as get_items. Provided for the sake of dictionary interface
"""
return list(self._data.keys())
......@@ -317,7 +317,7 @@ def __getitem__(self, item):
"""
return self._data[item]
def getItem(self, item):
def get_item(self, item):
"""
Get the contact in the internal format (or None if JID 'item' is not in
roster)
......@@ -325,19 +325,19 @@ def getItem(self, item):
if item in self._data:
return self._data[item]
def Unsubscribe(self, jid):
def unsubscribe(self, jid):
"""
Ask for removing our subscription for JID 'jid'
"""
self._con.connection.send(nbxmpp.Presence(jid, 'unsubscribe'))
def getRaw(self):
def get_raw(self):
"""
Return the internal data representation of the roster
"""
return self._data
def setRaw(self, data):
def set_raw(self, data):
"""
Set the internal data representation of the roster
"""
......
......@@ -31,10 +31,10 @@ class UserActivityData(AbstractPEPData):
type_ = PEPEventType.ACTIVITY
def __init__(self, activity):
self._pep_specific_data = activity
self.data = activity
def asMarkupText(self):
pep = self._pep_specific_data
pep = self.data
activity = pep['activity']
subactivity = pep['subactivity'] if 'subactivity' in pep else None
text = pep['text'] if 'text' in pep else None
......
......@@ -33,7 +33,7 @@ class UserAvatarData(AbstractPEPData):
type_ = PEPEventType.AVATAR
def __init__(self, avatar):
self._pep_specific_data = avatar
self.data = avatar
class UserAvatar(AbstractPEPModule):
......@@ -124,7 +124,7 @@ def _extract_info(self, item):
return avatar or None
def _notification_received(self, jid, user_pep):
avatar = user_pep._pep_specific_data
avatar = user_pep.data
own_jid = self._con.get_own_jid()
if avatar is None:
# Remove avatar
......
......@@ -31,10 +31,12 @@ class UserLocationData(AbstractPEPData):
type_ = PEPEventType.LOCATION
def __init__(self, location):
# set_location plugin uses self._pep_specific_data
self._pep_specific_data = location
self.data = location
def asMarkupText(self):
location = self._pep_specific_data
location = self.data
location_string = ''
for entry in location.keys():
......
......@@ -31,13 +31,13 @@ class UserMoodData(AbstractPEPData):
type_ = PEPEventType.MOOD
def __init__(self, mood):
self._pep_specific_data = mood
self.data = mood
def asMarkupText(self):
mood = self._translate_mood(self._pep_specific_data['mood'])
mood = self._translate_mood(self.data['mood'])
markuptext = '<b>%s</b>' % GLib.markup_escape_text(mood)
if 'text' in self._pep_specific_data:
text = self._pep_specific_data['text']
if 'text' in self.data:
text = self.data['text']
markuptext += ' (%s)' % GLib.markup_escape_text(text)
return markuptext
......
......@@ -31,10 +31,10 @@ class UserNicknameData(AbstractPEPData):
type_ = PEPEventType.NICKNAME
def __init__(self, nickname):
self._pep_specific_data = nickname
self.data = nickname
def get_nick(self):
return self._pep_specific_data or ''
return self.data or ''
class UserNickname(AbstractPEPModule):
......
......@@ -31,10 +31,10 @@ class UserTuneData(AbstractPEPData):
type_ = PEPEventType.TUNE
def __init__(self, tune):
self._pep_specific_data = tune
self.data = tune
def asMarkupText(self):
tune = self._pep_specific_data
tune = self.data
artist = tune.get('artist', _('Unknown Artist'))
artist = GLib.markup_escape_text(artist)
......
......@@ -40,7 +40,7 @@ def get_tag_as_PEP(cls, jid, account, event_tag):