coding style

This commit is contained in:
Denis Fomin 2011-01-03 23:08:13 +03:00
parent ed8b7a51d2
commit bd3d4f60a0
2 changed files with 194 additions and 180 deletions

View file

@ -981,7 +981,8 @@ def get_os_info():
path_to_file.endswith('arch-release'): path_to_file.endswith('arch-release'):
# file doesn't have version # file doesn't have version
text = distro_name text = distro_name
elif path_to_file.endswith('lfs-release'): # file just has version elif path_to_file.endswith('lfs-release'):
# file just has version
text = distro_name + ' ' + text text = distro_name + ' ' + text
os_info = text.replace('\n', '') os_info = text.replace('\n', '')
gajim.os_info = os_info gajim.os_info = os_info
@ -1137,9 +1138,7 @@ def get_notification_icon_tooltip_dict():
account['event_lines'].append(text) account['event_lines'].append(text)
else: else:
for jid in non_messages.keys(): for jid in non_messages.keys():
text = ngettext( text = ngettext('%d event pending', '%d events pending',
'%d event pending',
'%d events pending',
non_messages[jid], non_messages[jid], non_messages[jid]) non_messages[jid], non_messages[jid], non_messages[jid])
text += _(' from user %s') % (jid) text += _(' from user %s') % (jid)
account[account]['event_lines'].append(text) account[account]['event_lines'].append(text)
@ -1273,9 +1272,11 @@ def prepare_and_validate_gpg_keyID(account, jid, keyID):
if keyID in public_keys: if keyID in public_keys:
for u in gajim.contacts.get_contacts(account, jid): for u in gajim.contacts.get_contacts(account, jid):
u.keyID = keyID u.keyID = keyID
keys_str = gajim.config.get_per('accounts', account, 'attached_gpg_keys') keys_str = gajim.config.get_per('accounts', account,
'attached_gpg_keys')
keys_str += jid + ' ' + keyID + ' ' keys_str += jid + ' ' + keyID + ' '
gajim.config.set_per('accounts', account, 'attached_gpg_keys', keys_str) gajim.config.set_per('accounts', account, 'attached_gpg_keys',
keys_str)
elif keyID is None: elif keyID is None:
keyID = 'UNKNOWN' keyID = 'UNKNOWN'
return keyID return keyID

View file

@ -68,7 +68,7 @@ NS_FEATURE ='http://jabber.org/protocol/feature-neg'
NS_FILE = 'http://jabber.org/protocol/si/profile/file-transfer' # JEP-0096 NS_FILE = 'http://jabber.org/protocol/si/profile/file-transfer' # JEP-0096
NS_GAMING = 'http://jabber.org/protocol/gaming' # XEP-0196 NS_GAMING = 'http://jabber.org/protocol/gaming' # XEP-0196
NS_GATEWAY = 'jabber:iq:gateway' # XEP-0100 NS_GATEWAY = 'jabber:iq:gateway' # XEP-0100
NS_GEOLOC ='http://jabber.org/protocol/geoloc' # JEP-0080 NS_GEOLOC = 'http://jabber.org/protocol/geoloc' # XEP-0080
NS_GROUPCHAT = 'gc-1.0' NS_GROUPCHAT = 'gc-1.0'
NS_HTTP_AUTH = 'http://jabber.org/protocol/http-auth' # XEP-0070 NS_HTTP_AUTH = 'http://jabber.org/protocol/http-auth' # XEP-0070
NS_HTTP_BIND = 'http://jabber.org/protocol/httpbind' # XEP-0124 NS_HTTP_BIND = 'http://jabber.org/protocol/httpbind' # XEP-0124
@ -204,8 +204,8 @@ not-authorized -- -- -- The authentication failed because the initiating entit
temporary-auth-failure -- -- -- The authentication failed because of a temporary error condition within the receiving entity; sent in reply to an <auth/> element or <response/> element.''' temporary-auth-failure -- -- -- The authentication failed because of a temporary error condition within the receiving entity; sent in reply to an <auth/> element or <response/> element.'''
ERRORS, _errorcodes = {}, {} ERRORS, _errorcodes = {}, {}
for ns, errname, errpool in ((NS_XMPP_STREAMS, 'STREAM', xmpp_stream_error_conditions), for ns, errname, errpool in ((NS_XMPP_STREAMS, 'STREAM',
(NS_STANZAS, 'ERR', xmpp_stanza_error_conditions), xmpp_stream_error_conditions), (NS_STANZAS, 'ERR', xmpp_stanza_error_conditions),
(NS_SASL, 'SASL', sasl_error_conditions)): (NS_SASL, 'SASL', sasl_error_conditions)):
for err in errpool.split('\n')[1:]: for err in errpool.split('\n')[1:]:
cond, code, typ, text = err.split(' -- ') cond, code, typ, text = err.split(' -- ')
@ -354,7 +354,8 @@ class JID:
if not jid and not domain: if not jid and not domain:
raise ValueError('JID must contain at least domain name') raise ValueError('JID must contain at least domain name')
elif type(jid) == type(self): elif type(jid) == type(self):
self.node, self.domain, self.resource = jid.node, jid.domain, jid.resource self.node, self.domain = jid.node, jid.domain
self.resource = jid.resource
elif domain: elif domain:
self.node, self.domain, self.resource = node, domain, resource self.node, self.domain, self.resource = node, domain, resource
else: else:
@ -375,7 +376,8 @@ class JID:
def setNode(self, node): def setNode(self, node):
""" """
Set the node part of the JID to new value. Specify None to remove the node part Set the node part of the JID to new value. Specify None to remove
the node part
""" """
self.node = node.lower() self.node = node.lower()
@ -418,7 +420,8 @@ class JID:
other = JID(other) other = JID(other)
except ValueError: except ValueError:
return 0 return 0
return self.resource == other.resource and self.__str__(0) == other.__str__(0) return self.resource == other.resource and \
self.__str__(0) == other.__str__(0)
def __ne__(self, other): def __ne__(self, other):
""" """
@ -446,7 +449,8 @@ class JID:
def __hash__(self): def __hash__(self):
""" """
Produce hash of the JID, Allows to use JID objects as keys of the dictionary Produce hash of the JID, Allows to use JID objects as keys of the
dictionary
""" """
return hash(str(self)) return hash(str(self))
@ -469,7 +473,8 @@ class Protocol(Node):
def __init__(self, name=None, to=None, typ=None, frm=None, attrs={}, def __init__(self, name=None, to=None, typ=None, frm=None, attrs={},
payload=[], timestamp=None, xmlns=None, node=None): payload=[], timestamp=None, xmlns=None, node=None):
""" """
Constructor, name is the name of the stanza i.e. 'message' or 'presence' or 'iq' Constructor, name is the name of the stanza
i.e. 'message' or 'presence'or 'iq'
to is the value of 'to' attribure, 'typ' - 'type' attribute to is the value of 'to' attribure, 'typ' - 'type' attribute
frn - from attribure, attrs - other attributes mapping, frn - from attribure, attrs - other attributes mapping,
@ -493,7 +498,8 @@ class Protocol(Node):
self.setTo(self['to']) self.setTo(self['to'])
if self['from']: if self['from']:
self.setFrom(self['from']) self.setFrom(self['from'])
if node and type(self) == type(node) and self.__class__ == node.__class__ and self.attrs.has_key('id'): if node and type(self) == type(node) and \
self.__class__ == node.__class__ and self.attrs.has_key('id'):
del self.attrs['id'] del self.attrs['id']
self.timestamp = None self.timestamp = None
for d in self.getTags('delay', namespace=NS_DELAY2): for d in self.getTags('delay', namespace=NS_DELAY2):
@ -584,19 +590,20 @@ class Protocol(Node):
def getError(self): def getError(self):
""" """
Return the error-condition (if present) or the textual description of the Return the error-condition (if present) or the textual description
error (otherwise) of the error (otherwise)
""" """
errtag = self.getTag('error') errtag = self.getTag('error')
if errtag: if errtag:
for tag in errtag.getChildren(): for tag in errtag.getChildren():
if tag.getName() <> 'text': if tag.getName() != 'text':
return tag.getName() return tag.getName()
return errtag.getData() return errtag.getData()
def getErrorMsg(self): def getErrorMsg(self):
""" """
Return the textual description of the error (if present) or the error condition Return the textual description of the error (if present)
or the error condition
""" """
errtag = self.getTag('error') errtag = self.getTag('error')
if errtag: if errtag:
@ -619,7 +626,8 @@ class Protocol(Node):
if str(code) in _errorcodes.keys(): if str(code) in _errorcodes.keys():
error = ErrorNode(_errorcodes[str(code)], text=error) error = ErrorNode(_errorcodes[str(code)], text=error)
else: else:
error = ErrorNode(ERR_UNDEFINED_CONDITION, code=code, typ='cancel', text=error) error = ErrorNode(ERR_UNDEFINED_CONDITION, code=code,
typ='cancel', text=error)
elif type(error) in [type(''), type(u'')]: elif type(error) in [type(''), type(u'')]:
error=ErrorNode(error) error=ErrorNode(error)
self.setType('error') self.setType('error')
@ -724,7 +732,8 @@ class Message(Protocol):
""" """
try: try:
if xmllang: if xmllang:
dom = NodeBuilder('<body xmlns="%s" xml:lang="%s">%s</body>' % (NS_XHTML, xmllang, val)).getDom() dom = NodeBuilder('<body xmlns="%s" xml:lang="%s">%s</body>' \
% (NS_XHTML, xmllang, val)).getDom()
else: else:
dom = NodeBuilder('<body xmlns="%s">%s</body>' % (NS_XHTML, dom = NodeBuilder('<body xmlns="%s">%s</body>' % (NS_XHTML,
val), 0).getDom() val), 0).getDom()
@ -848,6 +857,7 @@ class Presence(Protocol):
Return the presence role (for groupchat) Return the presence role (for groupchat)
""" """
return self._muc_getItemAttr('item', 'role') return self._muc_getItemAttr('item', 'role')
def getAffiliation(self): def getAffiliation(self):
""" """
Return the presence affiliation (for groupchat) Return the presence affiliation (for groupchat)
@ -903,7 +913,8 @@ class Iq(Protocol):
Alternatively you can pass in the other XML object as the 'node' Alternatively you can pass in the other XML object as the 'node'
parameted to replicate it as an iq parameted to replicate it as an iq
""" """
Protocol.__init__(self, 'iq', to=to, typ=typ, attrs=attrs, frm=frm, xmlns=xmlns, node=node) Protocol.__init__(self, 'iq', to=to, typ=typ, attrs=attrs, frm=frm,
xmlns=xmlns, node=node)
if payload: if payload:
self.setQueryPayload(payload) self.setQueryPayload(payload)
if queryNS: if queryNS:
@ -978,7 +989,8 @@ class ErrorNode(Node):
def __init__(self, name, code=None, typ=None, text=None): def __init__(self, name, code=None, typ=None, text=None):
""" """
Mandatory parameter: name - name of error condition. Mandatory parameter: name - name of error condition.
Optional parameters: code, typ, text. Used for backwards compartibility with older jabber protocol. Optional parameters: code, typ, text.
Used for backwards compartibility with older jabber protocol.
""" """
if name in ERRORS: if name in ERRORS:
cod, type_, txt = ERRORS[name] cod, type_, txt = ERRORS[name]
@ -1043,8 +1055,8 @@ class DataField(Node):
Create new data field of specified name,value and type Create new data field of specified name,value and type
Also 'required','desc' and 'options' fields can be set. Alternatively Also 'required','desc' and 'options' fields can be set. Alternatively
other XML object can be passed in as the 'node' parameted to replicate it other XML object can be passed in as the 'node' parameted
as a new datafiled. to replicate it as a new datafiled.
""" """
Node.__init__(self, 'field', node=node) Node.__init__(self, 'field', node=node)
if name: if name:
@ -1153,7 +1165,8 @@ class DataField(Node):
if isinstance(opt, basestring): if isinstance(opt, basestring):
self.addChild('option').setTagData('value', opt) self.addChild('option').setTagData('value', opt)
else: else:
self.addChild('option', {'label': opt[0]}).setTagData('value', opt[1]) self.addChild('option', {'label': opt[0]}).setTagData('value',
opt[1])
def getType(self): def getType(self):
""" """