python-urlopen 0.1.4__tar.gz → 0.1.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-urlopen
3
- Version: 0.1.4
3
+ Version: 0.1.5.1
4
4
  Summary: Python urlopen wrapper.
5
5
  Home-page: https://github.com/ChenyangGao/python-modules/tree/main/python-urlopen
6
6
  License: MIT
@@ -20,12 +20,12 @@ Classifier: Programming Language :: Python :: 3 :: Only
20
20
  Classifier: Topic :: Software Development
21
21
  Classifier: Topic :: Software Development :: Libraries
22
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
- Requires-Dist: http_response (>=0.0.8)
23
+ Requires-Dist: http_response (>=0.0.9)
24
24
  Requires-Dist: python-argtools (>=0.0.2)
25
- Requires-Dist: python-cookietools (>=0.0.11)
26
- Requires-Dist: python-dicttools (>=0.0.2)
25
+ Requires-Dist: python-cookietools (>=0.1.2)
26
+ Requires-Dist: python-dicttools (>=0.0.4)
27
27
  Requires-Dist: python-filewrap (>=0.2.8)
28
- Requires-Dist: python-http_request (>=0.1.3)
28
+ Requires-Dist: python-http_request (>=0.1.4)
29
29
  Requires-Dist: python-undefined (>=0.0.3)
30
30
  Requires-Dist: yarl
31
31
  Project-URL: Repository, https://github.com/ChenyangGao/python-modules/tree/main/python-urlopen
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-urlopen"
3
- version = "0.1.4"
3
+ version = "0.1.5.1"
4
4
  description = "Python urlopen wrapper."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
@@ -27,12 +27,12 @@ include = [
27
27
 
28
28
  [tool.poetry.dependencies]
29
29
  python = "^3.12"
30
- http_response = ">=0.0.8"
30
+ http_response = ">=0.0.9"
31
31
  python-argtools = ">=0.0.2"
32
- python-cookietools = ">=0.0.11"
33
- python-dicttools = ">=0.0.2"
32
+ python-cookietools = ">=0.1.2"
33
+ python-dicttools = ">=0.0.4"
34
34
  python-filewrap = ">=0.2.8"
35
- python-http_request = ">=0.1.3"
35
+ python-http_request = ">=0.1.4"
36
36
  python-undefined = ">=0.0.3"
37
37
  yarl = "*"
38
38
 
@@ -2,7 +2,7 @@
2
2
  # coding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 1, 4)
5
+ __version__ = (0, 1, 5)
6
6
  __all__ = ["urlopen", "request", "download"]
7
7
 
8
8
  from collections import defaultdict, deque, UserString
@@ -10,7 +10,7 @@ from collections.abc import Buffer, Callable, Generator, Iterable, Mapping
10
10
  from copy import copy
11
11
  from http.client import HTTPConnection, HTTPSConnection, HTTPResponse
12
12
  from http.cookiejar import CookieJar
13
- from http.cookies import SimpleCookie
13
+ from http.cookies import BaseCookie
14
14
  from inspect import isgenerator
15
15
  from os import fsdecode, fstat, makedirs, PathLike
16
16
  from os.path import abspath, dirname, isdir, join as joinpath
@@ -29,7 +29,7 @@ from urllib.request import (
29
29
  from argtools import argcount
30
30
  from cookietools import cookies_to_str, extract_cookies, update_cookies
31
31
  from dicttools import iter_items
32
- from filewrap import bio_skip_iter, bio_chunk_iter, SupportsRead, SupportsWrite
32
+ from filewrap import bio_skip_iter, SupportsRead, SupportsWrite
33
33
  from http_request import normalize_request_args, SupportsGeturl
34
34
  from http_response import (
35
35
  decompress_response, get_filename, get_length, is_chunked, is_range_request,
@@ -81,7 +81,7 @@ class HTTPCookieProcessor(BaseHandler):
81
81
  def __init__(
82
82
  self,
83
83
  /,
84
- cookies: None | CookieJar | SimpleCookie = None,
84
+ cookies: None | CookieJar | BaseCookie = None,
85
85
  ):
86
86
  if cookies is None:
87
87
  cookies = CookieJar()
@@ -90,7 +90,7 @@ class HTTPCookieProcessor(BaseHandler):
90
90
  def http_request(self, request):
91
91
  cookies = self.cookies
92
92
  if cookies:
93
- if isinstance(cookies, SimpleCookie):
93
+ if isinstance(cookies, BaseCookie):
94
94
  cookies = update_cookies(CookieJar(), cookies)
95
95
  cookies.add_cookie_header(request)
96
96
  return request
@@ -264,7 +264,7 @@ def urlopen(
264
264
  follow_redirects: bool = True,
265
265
  proxies: None | Mapping[str, str] | Iterable[tuple[str, str]] = None,
266
266
  context: None | SSLContext = None,
267
- cookies: None | CookieJar | SimpleCookie = None,
267
+ cookies: None | CookieJar | BaseCookie = None,
268
268
  timeout: None | Undefined | float = undefined,
269
269
  opener: None | OpenerDirector = _opener,
270
270
  **_,
@@ -273,19 +273,28 @@ def urlopen(
273
273
  request = url
274
274
  else:
275
275
  if isinstance(data, PathLike):
276
- data = bio_chunk_iter(open(data, "rb"))
277
- elif isinstance(data, SupportsRead):
278
- data = bio_chunk_iter(data)
279
- request = Request(**normalize_request_args( # type: ignore
280
- method=method,
281
- url=url,
282
- params=params,
283
- data=data,
284
- json=json,
285
- files=files,
286
- headers=headers,
287
- ensure_ascii=True,
288
- ))
276
+ data = open(data, "rb")
277
+ if isinstance(data, SupportsRead):
278
+ request_args = normalize_request_args(
279
+ method=method,
280
+ url=url,
281
+ params=params,
282
+ headers=headers,
283
+ ensure_ascii=True,
284
+ )
285
+ request_args["data"] = data # type: ignore
286
+ else:
287
+ request_args = normalize_request_args(
288
+ method=method,
289
+ url=url,
290
+ params=params,
291
+ data=data,
292
+ json=json,
293
+ files=files,
294
+ headers=headers,
295
+ ensure_ascii=True,
296
+ )
297
+ request = Request(**request_args) # type: ignore
289
298
  if proxies:
290
299
  for host, type in iter_items(proxies):
291
300
  request.set_proxy(host, type)
@@ -374,7 +383,7 @@ def request(
374
383
  headers: None | Mapping[string, string] | Iterable[tuple[string, string]] = None,
375
384
  follow_redirects: bool = True,
376
385
  raise_for_status: bool = True,
377
- cookies: None | CookieJar | SimpleCookie = None,
386
+ cookies: None | CookieJar | BaseCookie = None,
378
387
  *,
379
388
  parse: None | EllipsisType = None,
380
389
  **request_kwargs,
@@ -391,7 +400,7 @@ def request(
391
400
  headers: None | Mapping[string, string] | Iterable[tuple[string, string]] = None,
392
401
  follow_redirects: bool = True,
393
402
  raise_for_status: bool = True,
394
- cookies: None | CookieJar | SimpleCookie = None,
403
+ cookies: None | CookieJar | BaseCookie = None,
395
404
  *,
396
405
  parse: Literal[False],
397
406
  **request_kwargs,
@@ -408,7 +417,7 @@ def request(
408
417
  headers: None | Mapping[string, string] | Iterable[tuple[string, string]] = None,
409
418
  follow_redirects: bool = True,
410
419
  raise_for_status: bool = True,
411
- cookies: None | CookieJar | SimpleCookie = None,
420
+ cookies: None | CookieJar | BaseCookie = None,
412
421
  *,
413
422
  parse: Literal[True],
414
423
  **request_kwargs,
@@ -425,7 +434,7 @@ def request[T](
425
434
  headers: None | Mapping[string, string] | Iterable[tuple[string, string]] = None,
426
435
  follow_redirects: bool = True,
427
436
  raise_for_status: bool = True,
428
- cookies: None | CookieJar | SimpleCookie = None,
437
+ cookies: None | CookieJar | BaseCookie = None,
429
438
  *,
430
439
  parse: Callable[[HTTPResponse, bytes], T] | Callable[[HTTPResponse], T],
431
440
  **request_kwargs,
@@ -441,7 +450,7 @@ def request[T](
441
450
  headers: None | Mapping[string, string] | Iterable[tuple[string, string]] = None,
442
451
  follow_redirects: bool = True,
443
452
  raise_for_status: bool = True,
444
- cookies: None | CookieJar | SimpleCookie = None,
453
+ cookies: None | CookieJar | BaseCookie = None,
445
454
  *,
446
455
  parse: None | EllipsisType| bool | Callable[[HTTPResponse, bytes], T] | Callable[[HTTPResponse], T] = None,
447
456
  **request_kwargs,
File without changes