Uploads a file at url and returns response content :param url: :param get: :param ref: :param cookies: :param just_header: If True only the header will be retrieved and returned as dict :param decode: Wether to decode the output according to
(self, path, url, get={}, ref=True, cookies=True, just_header=False, decode=True, redirect=True, req=None)
| 254 | return html |
| 255 | |
| 256 | def upload(self, path, url, get={}, ref=True, cookies=True, just_header=False, decode=True, redirect=True, req=None): |
| 257 | # @TODO: This should really go to HTTPRequest.py |
| 258 | |
| 259 | """ |
| 260 | Uploads a file at url and returns response content |
| 261 | |
| 262 | :param url: |
| 263 | :param get: |
| 264 | :param ref: |
| 265 | :param cookies: |
| 266 | :param just_header: If True only the header will be retrieved and returned as dict |
| 267 | :param decode: Wether to decode the output according to http header, should be True in most cases |
| 268 | :return: Response content |
| 269 | """ |
| 270 | if self.pyload.debug: |
| 271 | self.log_debug("UPLOAD URL " + url, |
| 272 | *["%s=%s" % (key, value) for key, value in locals().items() |
| 273 | if key not in ("self", "url", "_[1]")]) |
| 274 | |
| 275 | with open(fs_encode(path), 'rb') as f: |
| 276 | url = fixurl(url, unquote=True) #: Recheck in 0.4.10 |
| 277 | |
| 278 | if req is False: |
| 279 | req = get_request() |
| 280 | req.setOption("timeout", 60) # @TODO: Remove in 0.4.10 |
| 281 | |
| 282 | elif not req: |
| 283 | req = self.req |
| 284 | |
| 285 | if isinstance(cookies, list): |
| 286 | set_cookies(req.cj, cookies) |
| 287 | |
| 288 | http_req = self.req.http if hasattr(self.req, "http") else self.req |
| 289 | |
| 290 | if not redirect: |
| 291 | # @NOTE: req can be a HTTPRequest or a Browser object |
| 292 | http_req.c.setopt(pycurl.FOLLOWLOCATION, 0) |
| 293 | |
| 294 | elif type(redirect) is int: |
| 295 | # @NOTE: req can be a HTTPRequest or a Browser object |
| 296 | http_req.c.setopt(pycurl.MAXREDIRS, redirect) |
| 297 | |
| 298 | if isinstance(ref, basestring): |
| 299 | http_req.lastURL = ref |
| 300 | |
| 301 | http_req.setRequestContext(url, get, {}, bool(ref), bool(cookies), False) |
| 302 | http_req.header = "" |
| 303 | http_req.c.setopt(pycurl.HTTPHEADER, http_req.headers) |
| 304 | |
| 305 | http_req.c.setopt(pycurl.UPLOAD, 1) |
| 306 | http_req.c.setopt(pycurl.READFUNCTION, f.read) |
| 307 | http_req.c.setopt(pycurl.INFILESIZE, os.path.getsize(path)) |
| 308 | |
| 309 | if just_header: |
| 310 | http_req.c.setopt(pycurl.FOLLOWLOCATION, 0) |
| 311 | http_req.c.setopt(pycurl.NOBODY, 1) |
| 312 | http_req.c.perform() |
| 313 | html = http_req.header |
no test coverage detected