Skip to content

Commit

Permalink
added functions ldap.strf_secs() and ldap.strp_secs()
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder committed Jul 17, 2016
1 parent 0def217 commit ad88a80
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $
4 changes: 2 additions & 2 deletions Lib/ldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
19 changes: 17 additions & 2 deletions Lib/ldap/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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'))

0 comments on commit ad88a80

Please sign in to comment.