Changeset 4763 for TI12-security


Ignore:
Timestamp:
07/01/09 10:06:07 (11 years ago)
Author:
pjkersha
Message:

Python 2.4 backwards compatibility: added workaround for datetime.strptime in ndg.security.common.wssecurity.dom and ndg.security.common.wssecurity.etree

Location:
TI12-security/trunk/python/ndg.security.common/ndg/security/common/wssecurity
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg.security.common/ndg/security/common/wssecurity/dom.py

    r4761 r4763  
    5959 
    6060from datetime import datetime, timedelta 
     61 
     62# Workaround for lack of datetime.strptime in Python < 2.5 
     63if hasattr(datetime, 'strptime'): 
     64    _strptime = datetime.strptime 
     65else: 
     66    from time import strptime 
     67    _strptime = lambda datetimeStr, format: datetime(*(strptime(datetimeStr,  
     68                                                                format)[0:6])) 
     69 
    6170import logging 
    6271log = logging.getLogger(__name__) 
     
    7079 
    7180from ndg.security.common.X509 import X509Cert, X509CertParse, X509CertRead, \ 
    72 X509Stack, X509StackParseFromDER 
     81    X509Stack, X509StackParseFromDER 
    7382 
    7483class SignatureHandler(BaseSignatureHandler): 
     
    172181            createdDateTime, createdSecFraction = \ 
    173182                            createdNode[0].childNodes[0].nodeValue.split('.') 
    174             dtCreated = datetime.strptime(createdDateTime, '%Y-%m-%dT%H:%M:%S') 
     183            dtCreated = _strptime(createdDateTime, '%Y-%m-%dT%H:%M:%S') 
    175184            createdSeconds = float("0." + createdSecFraction.replace('Z', '')) 
    176185            dtCreated += timedelta(seconds=createdSeconds) 
     
    194203            expiresDateTime, expiresSecFraction = \ 
    195204                            expiresNode[0].childNodes[0].nodeValue.split('.') 
    196             dtExpiry = datetime.strptime(expiresDateTime, '%Y-%m-%dT%H:%M:%S') 
     205            dtExpiry = _strptime(expiresDateTime, '%Y-%m-%dT%H:%M:%S') 
    197206            expirySeconds = float("0." + expiresSecFraction.replace('Z', '')) 
    198207            dtExpiry += timedelta(seconds=expirySeconds) 
  • TI12-security/trunk/python/ndg.security.common/ndg/security/common/wssecurity/etree.py

    r4680 r4763  
    6868 
    6969from datetime import datetime, timedelta 
     70 
     71# Workaround for lack of datetime.strptime in Python < 2.5 
     72if hasattr(datetime, 'strptime'): 
     73    _strptime = datetime.strptime 
     74else: 
     75    from time import strptime 
     76    _strptime = lambda datetimeStr, format: datetime(*(strptime(datetimeStr,  
     77                                                                format)[0:6])) 
    7078import logging 
    7179log = logging.getLogger(__name__) 
     
    198206         
    199207 
    200         dtCreated = datetime.strptime(createdDateTime, '%Y-%m-%dT%H:%M:%S') 
     208        dtCreated = _strptime(createdDateTime, '%Y-%m-%dT%H:%M:%S') 
    201209        dtCreated += timedelta(seconds=createdSecFraction) 
    202210        if dtCreated >= dtNow: 
     
    219227            raise ValueError("Parsing timestamp Expires element: %s" % e) 
    220228         
    221         dtExpiry = datetime.strptime(expiryDateTime, '%Y-%m-%dT%H:%M:%S') 
     229        dtExpiry = _strptime(expiryDateTime, '%Y-%m-%dT%H:%M:%S') 
    222230        dtExpiry += timedelta(seconds=expirySecFraction) 
    223231        if dtExpiry < dtNow: 
Note: See TracChangeset for help on using the changeset viewer.