Exemple #1
0
    def __validate_time(self, t):
        _validate_argument(t, 'time', datetime.datetime)
        if not t.tzinfo:
            abbrev = time.tzname[time.daylight]
            if time.daylight:
                offset = -time.altzone
            else:
                offset = -time.timezone
            t = t.replace(tzinfo=getoffset(abbrev, offset))
        elif not t.tzname():
            offset = t.strft('%z')
            t = t.replace(tzinfo=getoffset(None, offset))

        self._time = t
Exemple #2
0
    def __validate_time(self, t):
        _validate_argument(t, 'time', datetime.datetime)
        if not t.tzinfo:
            abbrev = time.tzname[time.daylight]
            if time.daylight:
                offset = -time.altzone
            else:
                offset = -time.timezone
            t = t.replace(tzinfo=getoffset(abbrev, offset))
        elif not t.tzname():
            offset = t.strft('%z')
            t = t.replace(tzinfo=getoffset(None, offset))

        self._time = t
Exemple #3
0
    def _parse_info(self, info, conversation=None):
        s = info.get('source', '').rsplit('/', 1)
        if len(s) == 1:
            s.append('')
        info['source'], info['resource'] = s

        info['service'] = self.SERVICE_MAP[info['service']]
        if info['service'] == 'jabber':
            if info['destination'].endswith('@gmail.com') or \
                    info['source'].endswith('@gmail.com'):
                info['service'] = 'gtalk'
            if info['destination'].endswith('@chat.facebook.com') or \
                    info['source'].endswith('@chat.facebook.com'):
                info['service'] = 'facebook'


        if not conversation: # parsing a path
            timestr, offset, abbrev = \
                self.PATH_TIME_RE.match(info['time']).groups()
            t = datetime.datetime.strptime(timestr, self.STRPTIME_FMT_FILE)
            info['time'] = t.replace(tzinfo=getoffset(abbrev, offset))
        else:
            info['time'] = parse(info['time'], tzinfos=getoffset)
            if not info['time'].tzname():
                newtzinfo = conversation.time.tzinfo
                info['time'] = info['time'].replace(tzinfo=newtzinfo)

        return info
Exemple #4
0
    def _parse_info(self, info, conversation=None):
        s = info.get('source', '').rsplit('/', 1)
        if len(s) == 1:
            s.append('')
        info['source'], info['resource'] = s

        info['service'] = self.SERVICE_MAP[info['service']]
        if info['service'] == 'jabber':
            if info['destination'].endswith('@gmail.com') or \
                    info['source'].endswith('@gmail.com'):
                info['service'] = 'gtalk'
            if info['destination'].endswith('@chat.facebook.com') or \
                    info['source'].endswith('@chat.facebook.com'):
                info['service'] = 'facebook'

        if not conversation:  # parsing a path
            timestr, offset, abbrev = \
                self.PATH_TIME_RE.match(info['time']).groups()
            t = datetime.datetime.strptime(timestr, self.STRPTIME_FMT_FILE)
            info['time'] = t.replace(tzinfo=getoffset(abbrev, offset))
        else:
            info['time'] = parse(info['time'], tzinfos=getoffset)
            if not info['time'].tzname():
                newtzinfo = conversation.time.tzinfo
                info['time'] = info['time'].replace(tzinfo=newtzinfo)

        return info
Exemple #5
0
    def _parse_time(self, timestr, fmt):
        match = re.match(self.TIMESTR_RE, timestr)
        try:
            ts1, ts2 = match.groups()
            ts2 = ts2.replace(':', '')
        except:
            raise ParseError("problem parsing time string %s" % timestr)

        dt = datetime.datetime.strptime(ts1, fmt)
        return dt.replace(tzinfo=getoffset(None, ts2))
Exemple #6
0
    def _parse_time(self, timestr, fmt):
        match = re.match(self.TIMESTR_RE, timestr)
        try:
            ts1, ts2 = match.groups()
            ts2 = ts2.replace(':', '')
        except:
            raise ParseError("problem parsing time string %s" % timestr)

        dt = datetime.datetime.strptime(ts1, fmt)
        return dt.replace(tzinfo=getoffset(None, ts2))