Author: nicfit Date: 2007-06-29 23:21:08 +0200 (Fri, 29 Jun 2007) New Revision: 8345
Modified: trunk/src/common/connection_handlers.py trunk/src/common/helpers.py trunk/src/common/zeroconf/connection_handlers_zeroconf.py Log: Handle malformed timestamps (which would cause an unhandled exception and hork the connection) and XEP-82 (dashes in timestamps).
Modified: trunk/src/common/connection_handlers.py =================================================================== --- trunk/src/common/connection_handlers.py 2007-06-29 21:19:47 UTC (rev 8344) +++ trunk/src/common/connection_handlers.py 2007-06-29 21:21:08 UTC (rev 8345) @@ -24,7 +24,7 @@ import sys
from time import (altzone, daylight, gmtime, localtime, mktime, strftime, - strptime, time as time_time, timezone, tzname) + time as time_time, timezone, tzname) from calendar import timegm
import socks5 @@ -1424,7 +1424,7 @@ mtype = msg.getType() subject = msg.getSubject() # if not there, it's None tim = msg.getTimestamp() - tim = strptime(tim, '%Y%m%dT%H:%M:%S') + tim = helpers.datetime_tuple(tim) tim = localtime(timegm(tim)) frm = helpers.get_full_jid_from_iq(msg) jid = helpers.get_jid_from_iq(msg) @@ -1614,7 +1614,7 @@ elif namespace == common.xmpp.NS_DELAY: # XEP-0091 tim = prs.getTimestamp() - tim = strptime(tim, '%Y%m%dT%H:%M:%S') + tim = helpers.datetime_tuple(tim) timestamp = localtime(timegm(tim)) elif namespace == 'http://delx.cjb.net/protocol/roster-subsync': # see http://trac.gajim.org/ticket/326
Modified: trunk/src/common/helpers.py =================================================================== --- trunk/src/common/helpers.py 2007-06-29 21:19:47 UTC (rev 8344) +++ trunk/src/common/helpers.py 2007-06-29 21:21:08 UTC (rev 8345) @@ -970,3 +970,15 @@ if os.path.exists(file_): return file_ return None + +def datetime_tuple(timestamp): + '''Converts timestamp using strptime and the format: %Y%m%dT%H:%M:%S + Because of various datetime formats are used the following exceptions + are handled: + - Optional milliseconds appened to the string are removed + - XEP-082 datetime strings have all '-' cahrs removed to meet + the above format.''' + timestamp = timestamp.split('.')[0] + timestamp = timestamp.replace('-', '') + from time import strptime + return strptime(timestamp, '%Y%m%dT%H:%M:%S')
Modified: trunk/src/common/zeroconf/connection_handlers_zeroconf.py =================================================================== --- trunk/src/common/zeroconf/connection_handlers_zeroconf.py 2007-06-29 21:19:47 UTC (rev 8344) +++ trunk/src/common/zeroconf/connection_handlers_zeroconf.py 2007-06-29 21:21:08 UTC (rev 8345) @@ -640,7 +640,7 @@ mtype = msg.getType() subject = msg.getSubject() # if not there, it's None tim = msg.getTimestamp() - tim = time.strptime(tim, '%Y%m%dT%H:%M:%S') + tim = helpers.datetime_tuple(tim) tim = time.localtime(timegm(tim)) frm = msg.getFrom() if frm == None: