'time_str: A string with the following components:
<D> day[s] (optional)
<H> hour[s] (optional)
<M> minute[s] (optional)
<S> second[s] (optional)
Returns a datetime.timedelta parsed from the string'

def from_json(self, time_str):

    if (time_str is None):
        return None
    if isinstance(time_str, datetime.timedelta):
        return time_str
    parts = TIMEDELTA_REGEX.match(time_str)
    if (not parts):
        return
    parts = parts.groupdict()
    time_params = {}
    for (name, param) in parts.iteritems():
        if param:
            time_params[name] = int(param)
    return datetime.timedelta(**time_params)
