1 # -------------------------------------------------------------------------
\r
2 # Copyright (c) 2015-2017 AT&T Intellectual Property
\r
4 # Licensed under the Apache License, Version 2.0 (the "License");
\r
5 # you may not use this file except in compliance with the License.
\r
6 # You may obtain a copy of the License at
\r
8 # http://www.apache.org/licenses/LICENSE-2.0
\r
10 # Unless required by applicable law or agreed to in writing, software
\r
11 # distributed under the License is distributed on an "AS IS" BASIS,
\r
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 # See the License for the specific language governing permissions and
\r
14 # limitations under the License.
\r
16 # -------------------------------------------------------------------------
\r
20 from pprint import pformat
\r
22 from dateutil.parser import parse
\r
23 from schematics.exceptions import ConversionError
\r
24 from schematics.models import Model
\r
25 from schematics.types import DateTimeType
\r
28 class OSDFModel(Model):
\r
29 """Extends generic model with a couple of extra methods"""
\r
31 """Return values of object's attributes -- excluding hidden or callable ones"""
\r
33 """Coerce as string for some special objects"""
\r
34 return str(x) if isinstance(x, datetime.datetime) else x
\r
36 z1 = dict((x, getattr(self, x)) for x in dir(self)
\r
37 if not x.startswith("_") and not callable(getattr(self, x)))
\r
38 z1 = dict((x, _str_format(y)) for x, y in z1.items())
\r
39 return pformat(z1, depth=4, indent=2, width=1000)
\r
42 """Return values of object's attributes -- excluding hidden or callable ones"""
\r
43 return self.__str__()
\r
46 class CustomISODateType(DateTimeType):
\r
47 """Schematics doesn't support full ISO, so we use custom one"""
\r
48 def to_native(self, value, context=None):
\r
49 if isinstance(value, datetime.datetime):
\r
54 raise ConversionError(u'Invalid timestamp {}'.format(value))
\r