diff --git a/CHANGES b/CHANGES index 137f684..888eb55 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Installation: Lib/ * LDAPObject.unbind_ext() now removes class attribute LDAPObject._l to completely invalidate C wrapper object +* added functions ldap.strf_secs() and ldap.strp_secs() Modules/ * Fixed #69 Segmentation fault on whoami_s after unbind @@ -1260,4 +1261,4 @@ Released 2.0.0pre02 2002-02-01 ---------------------------------------------------------------- Released 1.10alpha3 2000-09-19 -$Id: CHANGES,v 1.379 2016/04/07 20:22:17 stroeder Exp $ +$Id: CHANGES,v 1.380 2016/07/17 15:12:58 stroeder Exp $ diff --git a/Lib/ldap/__init__.py b/Lib/ldap/__init__.py index ef106be..0cb29f1 100644 --- a/Lib/ldap/__init__.py +++ b/Lib/ldap/__init__.py @@ -3,7 +3,7 @@ See http://www.python-ldap.org/ for details. -$Id: __init__.py,v 1.103 2016/01/26 10:43:24 stroeder Exp $ +$Id: __init__.py,v 1.104 2016/07/17 15:12:58 stroeder Exp $ """ # This is also the overall release version number @@ -82,7 +82,7 @@ def release(self): # Create module-wide lock for serializing all calls into underlying LDAP lib _ldap_module_lock = LDAPLock(desc='Module wide') -from functions import open,initialize,init,get_option,set_option,escape_str +from functions import open,initialize,init,get_option,set_option,escape_str,strf_secs,strp_secs from ldapobject import NO_UNIQUE_ENTRY diff --git a/Lib/ldap/functions.py b/Lib/ldap/functions.py index 8ba0130..3e04744 100644 --- a/Lib/ldap/functions.py +++ b/Lib/ldap/functions.py @@ -3,7 +3,7 @@ See http://www.python-ldap.org/ for details. -\$Id: functions.py,v 1.31 2015/06/06 09:21:37 stroeder Exp $ +\$Id: functions.py,v 1.32 2016/07/17 15:12:58 stroeder Exp $ Compability: - Tested with Python 2.0+ but should work with Python 1.5.x @@ -27,7 +27,8 @@ 'escape_str', ] -import sys,pprint,_ldap,ldap +import sys,pprint,time,_ldap,ldap +from calendar import timegm from ldap import LDAPError @@ -140,3 +141,17 @@ def escape_str(escape_func,s,*args): """ escape_args = map(escape_func,args) return s % tuple(escape_args) + + +def strf_secs(secs): + """ + Convert seconds since epoch to a string compliant to LDAP syntax GeneralizedTime + """ + return time.strftime('%Y%m%d%H%M%SZ', time.gmtime(secs)) + + +def strp_secs(dt_str): + """ + Convert LDAP syntax GeneralizedTime to seconds since epoch + """ + return timegm(time.strptime(dt_str, '%Y%m%d%H%M%SZ'))