本文整理汇总了Python中rfc822.mktime_tz函数的典型用法代码示例。如果您正苦于以下问题:Python mktime_tz函数的具体用法?Python mktime_tz怎么用?Python mktime_tz使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mktime_tz函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_delivery_time
def get_delivery_time (msg):
# Figure out the delivery time.
dtime = None
if msg.has_key("Delivery-date"):
# eg. "Thu, 12 Jul 2001 08:47:20 -0400" to 994942040 (seconds
# since epoch in UTC)
dtime = mktime_tz(parsedate_tz(msg["Delivery-date"]))
elif msg.unixfrom:
# Parse eg.
# "From [email protected] Thu Jul 12 08:47:20 2001"
# -- this is the "From " line format used by Exim; hopefully other
# MTAs do the same!
m = re.match(r'^From (\S+) +(\w{3} \w{3}\s+\d\d? \d\d:\d\d:\d\d \d{4})$',
msg.unixfrom)
if not m:
warn("warning: could not parse \"From \" line: %s" % msg.unixfrom)
else:
(return_path, dtime_str) = m.groups()
# Eg. "Thu Jul 12 08:47:20 2001" -> 994945640 -- note that
# this might be different from what we get parsing the same
# date string above, because this one doesn't include the
# timezone. Sigh.
dtime = mktime(strptime(dtime_str, "%c"))
# Attempt to detect and correct for DST differences.
# (This works if we parsed a summer time during the winter;
# what about the inverse?)
dtime_str_curtz = ctime(dtime)
if dtime_str_curtz != dtime_str:
dtime_curtz = mktime(strptime(dtime_str_curtz, "%c"))
diff = dtime_curtz - dtime
dtime -= diff
return dtime
开发者ID:krt16s,项目名称:deponie,代码行数:34,代码来源:addtomaildir.py
示例2: _parse_sibling
def _parse_sibling(self, sibling, headers, data):
"""
Parses a single sibling out of a response.
"""
sibling.exists = True
# Parse the headers...
for header, value in headers:
header = header.lower()
if header == "content-type":
sibling.content_type, sibling.charset = self._parse_content_type(value)
elif header == "etag":
sibling.etag = value
elif header == "link":
sibling.links = self._parse_links(value)
elif header == "last-modified":
sibling.last_modified = mktime_tz(parsedate_tz(value))
elif header.startswith("x-riak-meta-"):
metakey = header.replace("x-riak-meta-", "")
sibling.usermeta[metakey] = value
elif header.startswith("x-riak-index-"):
field = header.replace("x-riak-index-", "")
reader = csv.reader([value], skipinitialspace=True)
for line in reader:
for token in line:
token = decode_index_value(field, token)
sibling.add_index(field, token)
elif header == "x-riak-deleted":
sibling.exists = False
sibling.encoded_data = data
return sibling
开发者ID:ThoughtLeadr,项目名称:riak-python-client,代码行数:34,代码来源:codec.py
示例3: was_modified_since
def was_modified_since(header=None, mtime=0, size=0):
"""
Was something modified since the user last downloaded it?
header
This is the value of the If-Modified-Since header. If this is None,
I'll just return True.
mtime
This is the modification time of the item we're talking about.
size
This is the size of the item we're talking about.
"""
try:
if header is None:
raise ValueError
matches = re.match(r"^([^;]+)(; length=([0-9]+))?$", header,
re.IGNORECASE)
header_mtime = rfc822.mktime_tz(rfc822.parsedate_tz(
matches.group(1)))
header_len = matches.group(3)
if header_len and int(header_len) != size:
raise ValueError
if mtime > header_mtime:
raise ValueError
except (AttributeError, ValueError):
return True
return False
开发者ID:alatteri,项目名称:informer,代码行数:29,代码来源:static.py
示例4: matches_value
def matches_value( self, v ):
t0 = time.time()
then = rfc822.parsedate_tz( v )
t1 = rfc822.mktime_tz(then)
return (t0 - t1) > self.age
开发者ID:brightbyte,项目名称:MailMux,代码行数:7,代码来源:mailfilter.py
示例5: _parse_midmo_date
def _parse_midmo_date(datestring):
"""
returns a local datetime corresponding to
the datestring given.
"""
# these appear to be rfc822/2822, not documented.
return datetime.fromtimestamp(rfc822.mktime_tz(rfc822.parsedate_tz(datestring)))
开发者ID:columbia-daily-tribune,项目名称:obcolumbia,代码行数:7,代码来源:business.py
示例6: loadfrommessage
def loadfrommessage(self, msg):
self.tofield = msg.getaddrlist("To")
f = msg.getaddr("From")
self.fromfield = f[1]
self.realfromfield = f[0]
if not self.realfromfield:
self.realfromfield = self.fromfield
self.ccfield = msg.getaddrlist("Cc")
if not self.ccfield:
self.ccfield = ()
self.subjectfield = msg.getheader("Subject")
if not self.subjectfield:
self.subjectfield = ""
self.annotation = msg.getheader("X-SQmaiL-Annotation")
if not self.annotation:
self.annotation = ""
self.readstatus = "Unread"
# Work out the date the message arrived.
r = ""
for i in msg.getallmatchingheaders("Received"):
r = r + i
p = string.find(r, ";")
if (p == -1):
self.date = 0
else:
r = r[p+1:]
r = rfc822.parsedate_tz(r)
r = rfc822.mktime_tz(r)
self.date = r
self.headers = string.join(msg.headers, "")
self.body = msg.fp.read()
开发者ID:davidgiven,项目名称:sqmail,代码行数:34,代码来源:message.py
示例7: get_contents_to_filename
def get_contents_to_filename(self, filename, headers=None,
cb=None, num_cb=10,
torrent=False,
version_id=None,
res_download_handler=None,
response_headers=None):
"""
Retrieve an object from S3 using the name of the Key object as the
key in S3. Store contents of the object to a file named by 'filename'.
See get_contents_to_file method for details about the
parameters.
:type filename: string
:param filename: The filename of where to put the file contents
:type headers: dict
:param headers: Any additional headers to send in the request
:type cb: function
:param cb: a callback function that will be called to report
progress on the upload. The callback should accept
two integer parameters, the first representing the
number of bytes that have been successfully
transmitted to S3 and the second representing the
size of the to be transmitted object.
:type cb: int
:param num_cb: (optional) If a callback is specified with
the cb parameter this parameter determines the
granularity of the callback by defining
the maximum number of times the callback will
be called during the file transfer.
:type torrent: bool
:param torrent: If True, returns the contents of a torrent file
as a string.
:type res_upload_handler: ResumableDownloadHandler
:param res_download_handler: If provided, this handler will
perform the download.
:type response_headers: dict
:param response_headers: A dictionary containing HTTP headers/values
that will override any headers associated with
the stored object in the response.
See http://goo.gl/EWOPb for details.
"""
fp = open(filename, 'wb')
self.get_contents_to_file(fp, headers, cb, num_cb, torrent=torrent,
version_id=version_id,
res_download_handler=res_download_handler,
response_headers=response_headers)
fp.close()
# if last_modified date was sent from s3, try to set file's timestamp
if self.last_modified != None:
try:
modified_tuple = rfc822.parsedate_tz(self.last_modified)
modified_stamp = int(rfc822.mktime_tz(modified_tuple))
os.utime(fp.name, (modified_stamp, modified_stamp))
except Exception: pass
开发者ID:FinalDoom,项目名称:boto,代码行数:60,代码来源:key.py
示例8: populate
def populate(self, sub):
file = open(os.path.join(self.archdir, str(sub), 'index'))
linepair = file.readline() + file.readline()
prev_timestamp = 0
while linepair:
match = _rx_index.match(linepair.rstrip())
if match:
g = match.groups()
msgnum = int(g[0])
try:
timestamp = rfc822.mktime_tz(rfc822.parsedate_tz(g[3]))
except:
timestamp = prev_timestamp + 1
prev_timestamp = timestamp
localtime = time.localtime(timestamp)
self.msgs[msgnum] = {
MSGNUM: msgnum,
THREADID: g[1],
SUBJECT: g[2],
DATE: g[3],
TIMESTAMP: timestamp,
AUTHORID: g[4],
AUTHOR: g[5],
MONTH: localtime[0] * 100 + localtime[1],
}
linepair = file.readline() + file.readline()
file.close()
开发者ID:bruceg,项目名称:ezmlm-browse,代码行数:27,代码来源:ezmlm.py
示例9: _readdate
def _readdate(txt):
"""Interpret the string as a date value."""
import rfc822
date = rfc822.parsedate_tz(txt.strip())
if date is not None:
return rfc822.mktime_tz(date)
return None
开发者ID:BackupTheBerlios,项目名称:rheinaufcms-svn,代码行数:7,代码来源:serialize.py
示例10: createEvent
def createEvent(evType, tstamp, name = None, contextList = [],
entityList = []):
"""
Create an XML element representing an event. Returns the XML object
It expects:
evType: Enum
tstamp: datetime object
name : string
contextList: List of context elements
entityList: List of entity elements
"""
result = etree.Element('event')
result.attrib['type'] = eventName(evType)
if tstamp == None:
tstamp = datetime.datetime.now()
result.attrib['datetime'] = rfc822.formatdate(rfc822.mktime_tz(rfc822.parsedate_tz(tstamp.strftime("%a, %d %b %Y %H:%M:%S"))))
if name != None:
result.attrib['name'] = name
for el in entityList + contextList:
result.append(el)
# Create the ID
m = hashlib.sha1()
m.update(etree.tostring(result))
result.attrib['id'] = m.hexdigest()
return result
开发者ID:dleony,项目名称:PLA,代码行数:31,代码来源:camoutput.py
示例11: get_pubdate
def get_pubdate(entry):
"""Try to determine the real pubDate of a feedparser entry
This basically takes the updated_parsed value, but also uses some more
advanced techniques to work around various issues with ugly feeds.
"published" now also takes precedence over "updated" (with updated used as
a fallback if published is not set/available). RSS' "pubDate" element is
"updated", and will only be used if published_parsed is not available.
"""
pubdate = entry.get('published_parsed', None)
if pubdate is None:
pubdate = entry.get('updated_parsed', None)
if pubdate is None:
# See http://code.google.com/p/feedparser/issues/detail?id=327
updated = entry.get('published', entry.get('updated', None))
if updated is not None:
# FIXME: This is kludgy. We should write our own date handler
# and register it with feedparser.registerDateHandler() and/or
# wait for feedparser to add support for this bogus date format.
pubdate = feedparser._parse_date(updated.replace(',', ''))
if pubdate is None:
# Cannot determine pubdate - party like it's 1970!
return 0
return mktime_tz(pubdate + (0,))
开发者ID:Dragontek,项目名称:gpodder,代码行数:30,代码来源:feedcore.py
示例12: _parse_date_rfc822
def _parse_date_rfc822(dateString):
'''Parse an RFC822, RFC1123, RFC2822, or asctime-style date'''
data = dateString.split()
if not data:
return None
if data[0][-1] in (',', '.') or data[0].lower() in rfc822._daynames:
del data[0]
if len(data) == 4:
s = data[3]
i = s.find('+')
if i > 0:
data[3:] = [s[:i], s[i+1:]]
else:
data.append('')
dateString = " ".join(data)
# Account for the Etc/GMT timezone by stripping 'Etc/'
elif len(data) == 5 and data[4].lower().startswith('etc/'):
data[4] = data[4][4:]
dateString = " ".join(data)
if len(data) < 5:
dateString += ' 00:00:00 GMT'
tm = rfc822.parsedate_tz(dateString)
if tm:
# Jython doesn't adjust for 2-digit years like CPython does,
# so account for it by shifting the year so that it's in the
# range 1970-2069 (1970 being the year of the Unix epoch).
if tm[0] < 100:
tm = (tm[0] + (1900, 2000)[tm[0] < 70],) + tm[1:]
return time.gmtime(rfc822.mktime_tz(tm))
开发者ID:BinaryBlob,项目名称:speedparser,代码行数:29,代码来源:feedparsercompat.py
示例13: parse_pubdate
def parse_pubdate(text):
"""Parse a date string into a Unix timestamp
>>> parse_pubdate('Fri, 21 Nov 1997 09:55:06 -0600')
880127706
>>> parse_pubdate('')
0
>>> parse_pubdate('unknown')
0
"""
if not text:
return 0
parsed = parsedate_tz(text)
if parsed is not None:
return int(mktime_tz(parsed))
# TODO: Fully RFC 3339-compliant parsing (w/ timezone)
try:
parsed = time.strptime(text[:19], '%Y-%m-%dT%H:%M:%S')
if parsed is not None:
return int(time.mktime(parsed))
except Exception:
pass
logger.error('Cannot parse date: %s', repr(text))
return 0
开发者ID:coreyfloyd,项目名称:podcastparser,代码行数:29,代码来源:podcastparser.py
示例14: execute
def execute(self, observation):
station_id = observation['station_id']
raw_time = observation['observation_time_rfc822']
parsed_time = datetime.datetime.fromtimestamp(rfc822.mktime_tz(rfc822.parsedate_tz(raw_time)))
epoch = datetime.datetime.utcfromtimestamp(0)
delta = int((parsed_time - epoch).total_seconds())
observation['ObservationTime'] = delta
observation['StationId'] = station_id
composite_key = "%s_%d" % (station_id, delta)
observation['CompositeKey'] = composite_key
region = os.environ['AWS_DEFAULT_REGION']
accessKey = os.environ['AWS_ACCESS_KEY']
secretKey = os.environ['AWS_SECRET_KEY']
try:
connx = boto.dynamodb2.connect_to_region(region, aws_access_key_id=accessKey, aws_secret_access_key=secretKey)
obs_table = Table('VocalPelicanObservation', connection = connx)
test_row = obs_table.get_item(CompositeKey=composite_key)
except JSONResponseError as responseError:
# authentication problem
print responseError
except boto.dynamodb2.exceptions.ItemNotFound as responseError:
# not found implies safe to add
return obs_table.put_item(observation)
return False
开发者ID:guycole,项目名称:vocal-pelican-aws,代码行数:31,代码来源:WxLoader.py
示例15: get_pubdate
def get_pubdate(entry):
"""Try to determine the real pubDate of a feedparser entry
This basically takes the updated_parsed value, but also uses some more
advanced techniques to work around various issues with ugly feeds.
"published" now also takes precedence over "updated" (with updated used as
a fallback if published is not set/available). RSS' "pubDate" element is
"updated", and will only be used if published_parsed is not available.
If parsing the date into seconds since epoch returns an error (date is
before epoch or after the end of time), epoch is used as fallback.
This fixes https://bugs.gpodder.org/show_bug.cgi?id=2023
"""
pubdate = entry.get('published_parsed', None)
if pubdate is None:
pubdate = entry.get('updated_parsed', None)
if pubdate is None:
# Cannot determine pubdate - party like it's 1970!
return 0
try:
pubtimeseconds = mktime_tz(pubdate + (0,))
return pubtimeseconds
except(OverflowError,ValueError):
logger.warn('bad pubdate %s is before epoch or after end of time (2038)',pubdate)
return 0
开发者ID:Mortal,项目名称:gpodder,代码行数:30,代码来源:feedcore.py
示例16: log
def log(self, parent=None, limit=100):
# TODO(dcramer): we should make this streaming
cmd = ['log', '--template=%s' % (LOG_FORMAT,)]
if parent:
cmd.append('-r %s' % (parent,))
if limit:
cmd.append('--limit=%d' % (limit,))
result = self.run(cmd)
for chunk in BufferParser(result, '\x02'):
(sha, author, author_date, parents, branches, message) = chunk.split('\x01')
branches = filter(bool, branches.split(' ')) or ['default']
parents = filter(lambda x: x and x != '0' * 40, parents.split(' '))
author_date = datetime.utcfromtimestamp(
mktime_tz(parsedate_tz(author_date)))
yield RevisionResult(
id=sha,
author=author,
author_date=author_date,
message=message,
parents=parents,
branches=branches,
)
开发者ID:amitdash,项目名称:changes,代码行数:26,代码来源:hg.py
示例17: _onsuccess
def _onsuccess(response):
if response.status == 200:
checksum = response.headers['Etag'].strip('"')
last_modified = response.headers['Last-Modified']
modified_tuple = rfc822.parsedate_tz(last_modified)
modified_stamp = int(rfc822.mktime_tz(modified_tuple))
return {'checksum': checksum, 'last_modified': modified_stamp}
开发者ID:serkanh,项目名称:scrapy,代码行数:7,代码来源:images.py
示例18: copy_uri
def copy_uri(self, uri, filename):
"""
Copies the contents of the resource given by 'uri' to 'filename'.
"""
source = Uri.UrlOpen(uri)
try:
source_mtime = source.headers.getdate_tz('last-modified')
source_mtime = rfc822.mktime_tz(source_mtime)
try:
target_mtime = os.path.getmtime(filename)
except OSError:
target_mtime = -1
if not (self.force or source_mtime > target_mtime):
self.announce("not copying %s (output up-to-date)" % uri, 1)
return filename, False
self.announce("copying %s -> %s" % (uri, filename), 2)
if not self.dry_run:
f = open(filename, 'wb')
try:
f.write(source.read())
finally:
f.close()
finally:
source.close()
return filename, True
开发者ID:onetera,项目名称:scandatatransfer,代码行数:26,代码来源:InstallDocs.py
示例19: open
def open(self):
# XXX in future add support for compression
headers = {'Accept-Encoding': ''}
if _requests_version == '0':
self._data_response = self._session.get(self._url('data'),
prefetch=False,
headers=headers)
else:
self._data_response = self._session.get(self._url('data'),
stream=True,
headers=headers)
self._validate_response(self._data_response)
size = self._data_response.headers.get('Content-Length', None)
if size is not None:
size = int(size)
self._size = size
modified = self._data_response.headers.get('Last-Modified', None)
if modified is not None:
modified = rfc822.mktime_tz(rfc822.parsedate_tz(modified))
self._modified = modified
mimetype = self._data_response.headers.get('Content-Type',
'application/octet-stream')
self._mimetype = mimetype
return self._data_response.raw
开发者ID:mindw,项目名称:encore,代码行数:28,代码来源:dynamic_url_store.py
示例20: _normalize_rfc822_date
def _normalize_rfc822_date( self, date_string ):
return datetime.fromtimestamp(
rfc822.mktime_tz(
rfc822.parsedate_tz(
date_string
)
)
)
开发者ID:mikewest,项目名称:appengine-thingsyoushouldread,代码行数:8,代码来源:feeds.py
注:本文中的rfc822.mktime_tz函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论