Show
Ignore:
Timestamp:
09/03/07 11:07:03 (15 months ago)
Author:
asterix
Message:

Handle malformed timestamps (which would cause an unhandled exception and hork the connection) and XEP-82 (dashes in timestamps).

Location:
branches/gajim_0.11.1/src/common
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/gajim_0.11.1/src/common/connection_handlers.py

    r8673 r8699  
    2525 
    2626from time import (altzone, daylight, gmtime, localtime, mktime, strftime, 
    27                   strptime, time as time_time, timezone, tzname) 
     27                  time as time_time, timezone, tzname) 
    2828from calendar import timegm 
    2929 
     
    13861386                subject = msg.getSubject() # if not there, it's None 
    13871387                tim = msg.getTimestamp() 
    1388                 tim = strptime(tim, '%Y%m%dT%H:%M:%S') 
     1388                tim = helpers.datetime_tuple(tim) 
    13891389                tim = localtime(timegm(tim)) 
    13901390                frm = helpers.get_full_jid_from_iq(msg) 
     
    15861586                                # XEP-0091 
    15871587                                tim = prs.getTimestamp() 
    1588                                 tim = strptime(tim, '%Y%m%dT%H:%M:%S') 
     1588                                tim = helpers.datetime_tuple(tim) 
    15891589                                timestamp = localtime(timegm(tim)) 
    15901590                        if namespace == 'http://delx.cjb.net/protocol/roster-subsync': 
  • branches/gajim_0.11.1/src/common/helpers.py

    r8681 r8699  
    947947                                'show': status, 'message': message}) 
    948948        return accounts 
     949 
     950def datetime_tuple(timestamp): 
     951        '''Converts timestamp using strptime and the format: %Y%m%dT%H:%M:%S 
     952        Because of various datetime formats are used the following exceptions 
     953        are handled: 
     954                - Optional milliseconds appened to the string are removed 
     955                - XEP-082 datetime strings have all '-' cahrs removed to meet 
     956                  the above format.''' 
     957        timestamp = timestamp.split('.')[0] 
     958        timestamp = timestamp.replace('-', '') 
     959        from time import strptime 
     960        return strptime(timestamp, '%Y%m%dT%H:%M:%S') 
  • branches/gajim_0.11.1/src/common/zeroconf/connection_handlers_zeroconf.py

    r8683 r8699  
    629629                subject = msg.getSubject() # if not there, it's None 
    630630                tim = msg.getTimestamp() 
    631                 tim = time.strptime(tim, '%Y%m%dT%H:%M:%S') 
     631                tim = helpers.datetime_tuple(tim) 
    632632                tim = time.localtime(timegm(tim)) 
    633633                frm = msg.getFrom()