Python rfc822.formatdate() Examples

The following are 9 code examples of rfc822.formatdate(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rfc822 , or try the search function .
Example #1
Source File: urllib2.py    From jawfish with MIT License 6 votes vote down vote up
def open_local_file(self, req):
        host = req.get_host()
        file = req.get_selector()
        localfile = url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = rfc822.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        stats = os.stat(localfile)
        headers = mimetools.Message(StringIO(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        if host:
            host, port = splitport(host)
        if not host or \
           (not port and socket.gethostbyname(host) in self.get_names()):
            return addinfourl(open(localfile, 'rb'),
                              headers, 'file:'+file)
        raise URLError('file not on local host') 
Example #2
Source File: httpheaders.py    From mishkal with GNU General Public License v3.0 5 votes vote down vote up
def compose(self, time=None, delta=None):
        time = time or now()
        if delta:
            assert type(delta) == int
            time += delta
        return (formatdate(time),) 
Example #3
Source File: visionclient.py    From galaxy-sdk-python with Apache License 2.0 5 votes vote down vote up
def __set_headers(self):
    headers = dict()
    headers[configs.CONTENT_TYPE] = "application/json; charset=UTF-8"
    headers[configs.DATE] = rfc822.formatdate(time.time())
    headers[configs.REQUEST_ID] = utils.request_id()
    headers[configs.CONTENT_MD5] = ""
    return headers 
Example #4
Source File: sdsthttpclient.py    From galaxy-sdk-python with Apache License 2.0 5 votes vote down vote up
def __set_headers(self, body):
    headers = dict()
    headers[HK_HOST] = self.host
    headers['content-length'] = str(len(body))
    headers[HK_TIMESTAMP] = str(int(time.time() + self.__clock_offset))
    headers[HK_CONTENT_MD5] = hashlib.md5(body).hexdigest()
    headers['content-type'] = THRIFT_HEADER_MAP[self.__protocol]
    headers[MI_DATE] = rfc822.formatdate(time.time())
    return headers 
Example #5
Source File: thttpclient.py    From galaxy-sdk-python with Apache License 2.0 5 votes vote down vote up
def __set_headers(self, body):
    headers = dict()
    headers[HOST] = self.host
    headers[CONTENT_LENGTH] = str(len(body))
    headers[TIMESTAMP] = str(int(time.time() + self.__clock_offset))
    headers[CONTENT_MD5] = hashlib.md5(body).hexdigest()
    headers[CONTENT_TYPE] = THRIFT_HEADER_MAP[self.__protocol]
    headers[MI_DATE] = rfc822.formatdate(time.time())
    return headers 
Example #6
Source File: _cpcompat.py    From opsbro with MIT License 5 votes vote down vote up
def HTTPDate(timeval=None):
        return formatdate(timeval, usegmt=True) 
Example #7
Source File: byterange.py    From root-2015-tasks with GNU General Public License v3.0 5 votes vote down vote up
def open_local_file(self, req):
        import mimetypes
        import mimetools
        host = req.get_host()
        file = req.get_selector()
        localfile = urllib.url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = rfc822.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        if host:
            host, port = urllib.splitport(host)
            if port or socket.gethostbyname(host) not in self.get_names():
                raise urllib2.URLError('file not on local host')
        fo = open(localfile,'rb')
        brange = req.headers.get('Range',None)
        brange = range_header_to_tuple(brange)
        assert brange != ()
        if brange:
            (fb,lb) = brange
            if lb == '': lb = size
            if fb < 0 or fb > size or lb > size:
                raise RangeError(9, 'Requested Range Not Satisfiable')
            size = (lb - fb)
            fo = RangeableFileObject(fo, (fb,lb))
        headers = mimetools.Message(StringIO(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        return urllib.addinfourl(fo, headers, 'file:'+file)


# FTP Range Support 
# Unfortunately, a large amount of base FTP code had to be copied
# from urllib and urllib2 in order to insert the FTP REST command.
# Code modifications for range support have been commented as 
# follows:
# -- range support modifications start/end here 
Example #8
Source File: _cpcompat.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
def HTTPDate(timeval=None):
        return formatdate(timeval, usegmt=True) 
Example #9
Source File: visionclient.py    From cloud-ml-sdk with Apache License 2.0 5 votes vote down vote up
def __set_headers(self):
    headers = dict()
    headers[configs.CONTENT_TYPE] = "application/json; charset=UTF-8"
    headers[configs.DATE] = rfc822.formatdate(time.time())
    headers[configs.REQUEST_ID] = utils.request_id()
    headers[configs.CONTENT_MD5] = ""
    return headers