Exemple #1
0
    def __make_postbody(self, boundary, fields, stream, mime_type, localfile):
        """
        生成post请求内容主体

        @param boundary: string类型,post内容主体的限定字符串
        @param fields: ditc类型,键值对类型分别为string类型
        @param stream: 可读的file-like object(file object 或者BytesIO)
        @param mime_type: string类型,上传文件或数据的MIME类型
        @param localfile: string类型,上传文件或数据的本地名称
        @return 二进制数据流
        """

        binarystream = b''
        for (key, value) in fields.items():
            binarystream += b('--{0}\r\n'.format(boundary))
            binarystream += b(
                'Content-Disposition: form-data; name="{0}"\r\n'.format(key))
            binarystream += b('\r\n')
            binarystream += b('{0}\r\n'.format(value))

        binarystream += b('--{0}\r\n'.format(boundary))
        binarystream += b(
            'Content-Disposition: form-data; name="file"; filename="{0}"\r\n'.
            format(localfile))
        binarystream += b('Content-Type: {0}\r\n'.format(mime_type))
        binarystream += b('\r\n')

        binarystream += stream.read()
        binarystream += b('\r\n')
        binarystream += b('--{0}\r\n'.format(boundary))

        return binarystream
Exemple #2
0
    def __make_postbody(self, boundary, fields, stream, mime_type, localfile):
        """
        生成post请求内容主体

        @param boundary: string类型,post内容主体的限定字符串
        @param fields: ditc类型,键值对类型分别为string类型
        @param stream: 可读的file-like object(file object 或者BytesIO)
        @param mime_type: string类型,上传文件或数据的MIME类型
        @param localfile: string类型,上传文件或数据的本地名称
        @return 二进制数据流
        """

        binarystream = b""
        for (key, value) in fields.items():
            binarystream += b("--{0}\r\n".format(boundary))
            binarystream += b('Content-Disposition: form-data; name="{0}"\r\n'.format(key))
            binarystream += b("\r\n")
            binarystream += b("{0}\r\n".format(value))

        binarystream += b("--{0}\r\n".format(boundary))
        binarystream += b('Content-Disposition: form-data; name="file"; filename="{0}"\r\n'.format(localfile))
        binarystream += b("Content-Type: {0}\r\n".format(mime_type))
        binarystream += b("\r\n")

        binarystream += stream.read()
        binarystream += b("\r\n")
        binarystream += b("--{0}\r\n".format(boundary))

        return binarystream
Exemple #3
0
    def __make_boundary(self):
        """
        生成post内容主体的限定字符串

        @return: string类型
        """
        t = time.time()
        m = hashlib.md5()
        m.update(b(str(t)))
        return m.hexdigest()
Exemple #4
0
    def __make_boundary(self):
        """
        生成post内容主体的限定字符串

        @return: string类型
        """
        t = time.time()
        m = hashlib.md5()
        m.update(b(str(t)))
        return m.hexdigest()