From 1df696f5432a673a24ff5cb273fe068a7d88d6ea Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Thu, 9 Jan 2014 11:14:56 +0100 Subject: ipalib: Add DateTime parameter Adds a parameter that represents a DateTime format using datetime.datetime object from python's native datetime library. In the CLI, accepts one of the following formats: Accepts LDAP Generalized time without in the following format: '%Y%m%d%H%M%SZ' Accepts subset of values defined by ISO 8601: '%Y-%m-%dT%H:%M:%SZ' '%Y-%m-%dT%H:%MZ' '%Y-%m-%dZ' Also accepts above formats using ' ' (space) as a separator instead of 'T'. As a simplification, it does not deal with timezone info and ISO 8601 values with timezone info (+-hhmm) are rejected. Values are expected to be in the UTC timezone. Values are saved to LDAP as LDAP Generalized time values in the format '%Y%m%d%H%SZ' (no time fractions and UTC timezone is assumed). To avoid confusion, in addition to subset of ISO 8601 values, the LDAP generalized time in the format '%Y%m%d%H%M%SZ' is also accepted as an input (as this is the format user will see on the output). Part of: https://fedorahosted.org/freeipa/ticket/3306 Reviewed-By: Jan Cholasta --- ipapython/ipaldap.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ipapython') diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index 56e7d1384..12450e8f2 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -21,6 +21,7 @@ import string import time +import datetime import shutil from decimal import Decimal from copy import deepcopy @@ -35,6 +36,7 @@ from ldap.controls import SimplePagedResultsControl import ldapurl from ipalib import errors, _ +from ipalib.constants import LDAP_GENERALIZED_TIME_FORMAT from ipapython import ipautil from ipapython.ipautil import ( format_netloc, wait_for_open_socket, wait_for_open_ports, CIDict) @@ -239,6 +241,7 @@ class IPASimpleLDAPObject(object): '2.16.840.1.113719.1.301.4.41.1' : DN, # krbSubTrees '2.16.840.1.113719.1.301.4.52.1' : DN, # krbObjectReferences '2.16.840.1.113719.1.301.4.53.1' : DN, # krbPrincContainerRef + '1.3.6.1.4.1.1466.115.121.1.24' : datetime.datetime, } # In most cases we lookup the syntax from the schema returned by @@ -408,6 +411,8 @@ class IPASimpleLDAPObject(object): elif isinstance(val, dict): dct = dict((self.encode(k), self.encode(v)) for k, v in val.iteritems()) return dct + elif isinstance(val, datetime.datetime): + return val.strftime(LDAP_GENERALIZED_TIME_FORMAT) elif val is None: return None else: @@ -426,6 +431,8 @@ class IPASimpleLDAPObject(object): return val elif target_type is unicode: return val.decode('utf-8') + elif target_type is datetime.datetime: + return datetime.datetime.strptime(val, LDAP_GENERALIZED_TIME_FORMAT) else: return target_type(val) except Exception, e: -- cgit