[thorstenp] use startswith and endswith instead of array indices on strings

This commit is contained in:
Yann Leboulanger 2008-10-11 09:32:59 +00:00
parent 6cc8204319
commit 84e717c8df
10 changed files with 12 additions and 12 deletions

View File

@ -1093,7 +1093,7 @@ class Connection(ConnectionHandlers):
if keyID and self.USE_GPG:
if keyID == 'UNKNOWN':
error = _('Neither the remote presence is signed, nor a key was assigned.')
elif keyID[8:] == 'MISMATCH':
elif keyID.endswith('MISMATCH'):
error = _('The contact\'s key (%s) does not match the key assigned in Gajim.' % keyID[:8])
else:
#encrypt

View File

@ -470,7 +470,7 @@ class ConnectionBytestream:
raise common.xmpp.NodeProcessed
if streamhost is None:
# proxy approves the activate query
if real_id[:3] == 'au_':
if real_id.startswith('au_'):
id = real_id[3:]
if 'streamhost-used' not in file_props or \
file_props['streamhost-used'] is False:
@ -488,7 +488,7 @@ class ConnectionBytestream:
file_props['streamhost-used'] is True:
raise common.xmpp.NodeProcessed
if real_id[:3] == 'au_':
if real_id.startswith('au_'):
if 'stopped' in file and file_props['stopped']:
self.remove_transfer(file_props)
else:

View File

@ -175,7 +175,7 @@ class SASL(PlugIn):
self.DEBUG('Got challenge:'+data,'ok')
for pair in data.split(','):
key,value=pair.split('=', 1)
if value[:1]=='"' and value[-1:]=='"': value=value[1:-1]
if value.startswith('"') and value.endswith('"'): value=value[1:-1]
chal[key]=value
if 'qop' in chal and chal['qop']=='auth':
resp={}

View File

@ -22,7 +22,7 @@ def c14n(node):
s = s + c14n(a)
cnt=cnt+1
if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt])
if not node.kids and s[-1:]=='>':
if not node.kids and s.endswith('>'):
s=s[:-1]+' />'
else:
s = s + "</" + node.name + ">"

View File

@ -775,7 +775,7 @@ class DataForm(Node):
for field in self.getTags('field'):
name=field.getAttr('var')
typ=field.getType()
if type(typ) in [type(''),type(u'')] and typ[-6:]=='-multi':
if type(typ) in [type(''),type(u'')] and typ.endswith('-multi'):
val=[]
for i in field.getTags('value'): val.append(i.getData())
else: val=field.getTagData('value')

View File

@ -129,7 +129,7 @@ class Node(object):
cnt=cnt+1
if not fancy and (len(self.data)-1) >= cnt: s = s + XMLescape(self.data[cnt])
elif (len(self.data)-1) >= cnt: s = s + XMLescape(self.data[cnt].strip())
if not self.kids and s[-1:]=='>':
if not self.kids and s.endswith('>'):
s=s[:-1]+' />'
if fancy: s = s + "\n"
else:

View File

@ -235,7 +235,7 @@ class ConnectionBytestream(connection_handlers.ConnectionBytestream):
raise common.xmpp.NodeProcessed
if streamhost is None:
# proxy approves the activate query
if real_id[:3] == 'au_':
if real_id.startswith('au_'):
id = real_id[3:]
if 'streamhost-used' not in file_props or \
file_props['streamhost-used'] is False:
@ -253,7 +253,7 @@ class ConnectionBytestream(connection_handlers.ConnectionBytestream):
file_props['streamhost-used'] is True:
raise common.xmpp.NodeProcessed
if real_id[:3] == 'au_':
if real_id.startswith('au_'):
gajim.socks5queue.send_file(file_props, self.name)
raise common.xmpp.NodeProcessed

View File

@ -379,7 +379,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
if keyID and self.USE_GPG:
if keyID == 'UNKNOWN':
error = _('Neither the remote presence is signed, nor a key was assigned.')
elif keyID[8:] == 'MISMATCH':
elif keyID.endswith('MISMATCH'):
error = _('The contact\'s key (%s) does not match the key assigned in Gajim.' % keyID[:8])
else:
# encrypt

View File

@ -3893,7 +3893,7 @@ class GPGInfoWindow:
verify_now_button.set_no_show_all(True)
verify_now_button.hide()
if keyID[8:] == 'MISMATCH':
if keyID.endswith('MISMATCH'):
verification_status = _('''Contact's identity NOT verified''')
info = _('The contact\'s key (%s) <b>does not match</b> the key '
'assigned in Gajim.') % keyID[:8]

View File

@ -271,7 +271,7 @@ class SignalObject(dbus.service.Object):
connected_account, contact = self._get_account_and_contact(account, jid)
if connected_account:
if file_path[:7] == 'file://':
if file_path.startswith('file://'):
file_path=file_path[7:]
if os.path.isfile(file_path): # is it file?
gajim.interface.instances['file_transfers'].send_file(