def _reformat_timestamp(self, format, force=False):
    if (format not in ['ctime', 'ctime-pre2.4', 'iso8601-utc', 'iso8601-local']):
        raise ValueError('invalid datetime format %s, choose from ctime, ctime-pre2.4, iso8601-utc, iso8601-local.')
    if (((self.datetime_format is None) or ((self.datetime_format == format) and (self._datetime_str != ''))) and (not force)):
        return
    elif (self.datetime is None):
        return
    elif format.startswith('ctime'):
        dt_string = ((self.weekdays[self.datetime.weekday()] + ' ') + self.datetime.strftime('%b %d %H:%M:%S'))
        tokens = dt_string.split(' ')
        if tokens[2].startswith('0'):
            tokens[2] = tokens[2].replace('0', ' ', 1)
        dt_string = ' '.join(tokens)
        if (format == 'ctime'):
            dt_string += ('.' + str(int((self.datetime.microsecond / 1000))).zfill(3))
    elif (format == 'iso8601-local'):
        dt_string = self.datetime.isoformat()
        if (self.datetime.utcoffset() is None):
            dt_string += '+00:00'
        ms_str = str(int((self.datetime.microsecond / 1000))).zfill(3)[:3]
        dt_string = re.sub('(\\.\\d+)?([+-])(\\d\\d):(\\d\\d)', ('.%s\\2\\3\\4' % ms_str), dt_string, count=1)
    elif (format == 'iso8601-utc'):
        if self.datetime.utcoffset():
            dt_string = self.datetime.astimezone(tzutc()).strftime('%Y-%m-%dT%H:%M:%S')
        else:
            dt_string = self.datetime.strftime('%Y-%m-%dT%H:%M:%S')
        dt_string += (('.' + str(int((self.datetime.microsecond / 1000))).zfill(3)[:3]) + 'Z')
    self._datetime_str = dt_string
    self._datetime_format = format
def _reformat_timestamp(self, format, force=False):
    if (format not in ['ctime', 'ctime-pre2.4', 'iso8601-utc', 'iso8601-local']):
        raise ValueError('invalid datetime format %s, choose from ctime, ctime-pre2.4, iso8601-utc, iso8601-local.')
    if (((self.datetime_format is None) or ((self.datetime_format == format) and (self._datetime_str != ))) and (not force)):
        return
    elif (self.datetime is None):
        return
    elif format.startswith('ctime'):
        dt_string = ((self.weekdays[self.datetime.weekday()] + ' ') + self.datetime.strftime('%b %d %H:%M:%S'))
        tokens = dt_string.split(' ')
        if tokens[2].startswith('0'):
            tokens[2] = tokens[2].replace('0', ' ', 1)
        dt_string = ' '.join(tokens)
        if (format == 'ctime'):
            dt_string += ('.' + str(int((self.datetime.microsecond / 1000))).zfill(3))
    elif (format == 'iso8601-local'):
        dt_string = self.datetime.isoformat()
        if (self.datetime.utcoffset() is None):
            dt_string += '+00:00'
        ms_str = str(int((self.datetime.microsecond / 1000))).zfill(3)[:3]
        dt_string = re.sub('(\\.\\d+)?([+-])(\\d\\d):(\\d\\d)', ('.%s\\2\\3\\4' % ms_str), dt_string, count=1)
    elif (format == 'iso8601-utc'):
        if self.datetime.utcoffset():
            dt_string = self.datetime.astimezone(tzutc()).strftime('%Y-%m-%dT%H:%M:%S')
        else:
            dt_string = self.datetime.strftime('%Y-%m-%dT%H:%M:%S')
        dt_string += (('.' + str(int((self.datetime.microsecond / 1000))).zfill(3)[:3]) + 'Z')
    self._datetime_str = dt_string
    self._datetime_format = format