(self)
| 179 | raw=raw) |
| 180 | |
| 181 | def toDict(self): |
| 182 | content = { |
| 183 | "mimeType": self.headers.get("Content-Type"), |
| 184 | "text": self.content, |
| 185 | "size": len(self.content or "") |
| 186 | } |
| 187 | |
| 188 | binary = set([b'\0', b'\1']) |
| 189 | if any(c in binary for c in self.content): |
| 190 | content["encoding"] = "base64" |
| 191 | content["text"] = getText(base64.b64encode(self.content)) |
| 192 | else: |
| 193 | content["text"] = getText(content["text"]) |
| 194 | |
| 195 | return { |
| 196 | "httpVersion": self.httpVersion, |
| 197 | "status": self.status, |
| 198 | "statusText": self.statusText, |
| 199 | "headers": [dict(name=key.capitalize(), value=value) for key, value in self.headers.items() if key.lower() != "uri"], |
| 200 | "cookies": [], |
| 201 | "content": content, |
| 202 | "headersSize": -1, |
| 203 | "bodySize": -1, |
| 204 | "redirectURL": "", |
| 205 | "comment": getText(self.comment), |
| 206 | } |
| 207 | |
| 208 | class FakeSocket(object): |
| 209 | # Original source: |
nothing calls this directly
no test coverage detected