|
28 | 28 |
|
29 | 29 | from lib.core.compat import choose_boundary |
30 | 30 | from lib.core.convert import getBytes |
| 31 | +from lib.core.convert import getText |
31 | 32 | from lib.core.exception import SqlmapDataException |
32 | 33 | from thirdparty.six.moves import urllib as _urllib |
33 | 34 |
|
34 | | -class Callable: |
35 | | - def __init__(self, anycallable): |
36 | | - self.__call__ = anycallable |
37 | | - |
38 | 35 | # Controls how sequences are uncoded. If true, elements may be given |
39 | 36 | # multiple values by assigning a sequence. |
40 | 37 | doseq = 1 |
@@ -72,40 +69,38 @@ def http_request(self, request): |
72 | 69 | request.data = data |
73 | 70 | return request |
74 | 71 |
|
75 | | - def multipart_encode(vars, files, boundary=None, buf=None): |
| 72 | + def multipart_encode(self, vars, files, boundary=None, buf=None): |
76 | 73 | if boundary is None: |
77 | 74 | boundary = choose_boundary() |
78 | 75 |
|
79 | 76 | if buf is None: |
80 | | - buf = "" |
| 77 | + buf = b"" |
81 | 78 |
|
82 | 79 | for (key, value) in vars: |
83 | 80 | if key is not None and value is not None: |
84 | | - buf += "--%s\r\n" % boundary |
85 | | - buf += "Content-Disposition: form-data; name=\"%s\"" % key |
86 | | - buf += "\r\n\r\n" + value + "\r\n" |
| 81 | + buf += b"--%s\r\n" % getBytes(boundary) |
| 82 | + buf += b"Content-Disposition: form-data; name=\"%s\"" % getBytes(key) |
| 83 | + buf += b"\r\n\r\n" + getBytes(value) + b"\r\n" |
87 | 84 |
|
88 | 85 | for (key, fd) in files: |
89 | | - file_size = os.fstat(fd.fileno())[stat.ST_SIZE] if hasattr(fd, "fileno") else fd.len |
| 86 | + file_size = fd.len if hasattr(fd, "len") else os.fstat(fd.fileno())[stat.ST_SIZE] |
90 | 87 | filename = fd.name.split("/")[-1] if "/" in fd.name else fd.name.split("\\")[-1] |
91 | 88 | try: |
92 | | - contenttype = mimetypes.guess_type(filename)[0] or "application/octet-stream" |
| 89 | + contenttype = mimetypes.guess_type(filename)[0] or b"application/octet-stream" |
93 | 90 | except: |
94 | 91 | # Reference: http://bugs.python.org/issue9291 |
95 | | - contenttype = "application/octet-stream" |
96 | | - buf += "--%s\r\n" % boundary |
97 | | - buf += "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n" % (key, filename) |
98 | | - buf += "Content-Type: %s\r\n" % contenttype |
99 | | - # buf += "Content-Length: %s\r\n" % file_size |
| 92 | + contenttype = b"application/octet-stream" |
| 93 | + buf += b"--%s\r\n" % getBytes(boundary) |
| 94 | + buf += b"Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n" % (getBytes(key), getBytes(filename)) |
| 95 | + buf += b"Content-Type: %s\r\n" % getBytes(contenttype) |
| 96 | + # buf += b"Content-Length: %s\r\n" % file_size |
100 | 97 | fd.seek(0) |
101 | 98 |
|
102 | | - buf = getBytes(buf) |
103 | 99 | buf += b"\r\n%s\r\n" % fd.read() |
104 | 100 |
|
105 | | - buf += "--%s--\r\n\r\n" % boundary |
| 101 | + buf += b"--%s--\r\n\r\n" % getBytes(boundary) |
| 102 | + buf = getBytes(buf) |
106 | 103 |
|
107 | 104 | return boundary, buf |
108 | 105 |
|
109 | | - multipart_encode = Callable(multipart_encode) |
110 | | - |
111 | 106 | https_request = http_request |
0 commit comments