p115client 0.0.5.11.9__tar.gz → 0.0.5.11.9.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.
Files changed (26) hide show
  1. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/PKG-INFO +1 -1
  2. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/client.py +1 -0
  3. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/upload.py +57 -22
  4. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/pyproject.toml +1 -1
  5. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/LICENSE +0 -0
  6. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/__init__.py +0 -0
  7. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/_upload.py +0 -0
  8. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/const.py +0 -0
  9. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/exception.py +0 -0
  10. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/py.typed +0 -0
  11. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/__init__.py +0 -0
  12. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/attr.py +0 -0
  13. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/auth.py +0 -0
  14. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/download.py +0 -0
  15. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/edit.py +0 -0
  16. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/export_dir.py +0 -0
  17. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/fs_files.py +0 -0
  18. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/history.py +0 -0
  19. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/iterdir.py +0 -0
  20. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/life.py +0 -0
  21. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/pool.py +0 -0
  22. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/request.py +0 -0
  23. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/util.py +0 -0
  24. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/tool/xys.py +0 -0
  25. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/p115client/type.py +0 -0
  26. {p115client-0.0.5.11.9 → p115client-0.0.5.11.9.1}/readme.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p115client
3
- Version: 0.0.5.11.9
3
+ Version: 0.0.5.11.9.1
4
4
  Summary: Python 115 webdisk client.
5
5
  Home-page: https://github.com/ChenyangGao/p115client
6
6
  License: MIT
@@ -5187,6 +5187,7 @@ class P115OpenClient(ClientRequestMixin):
5187
5187
  async_=async_, # type: ignore
5188
5188
  **request_kwargs,
5189
5189
  )
5190
+ check_response(resp)
5190
5191
  data = resp["data"]
5191
5192
  match data["status"]:
5192
5193
  case 2:
@@ -28,7 +28,7 @@ from iterutils import (
28
28
  with_iter_next, YieldFrom,
29
29
  )
30
30
  from orjson import loads
31
- from p115client import check_response, normalize_attr_simple, P115Client
31
+ from p115client import check_response, normalize_attr_simple, P115Client, P115OpenClient
32
32
  from p115client.exception import OperationalError
33
33
  from p115client._upload import (
34
34
  oss_multipart_part_iter, oss_multipart_upload_init,
@@ -461,7 +461,7 @@ def iter_115_to_115_resume(
461
461
 
462
462
  @overload
463
463
  def multipart_upload_init(
464
- client: str | P115Client,
464
+ client: str | P115Client | P115OpenClient,
465
465
  path: str | PathLike | URL | SupportsGeturl,
466
466
  pid: int = 0,
467
467
  filename: str = "",
@@ -470,6 +470,7 @@ def multipart_upload_init(
470
470
  partsize: int = -1,
471
471
  upload_data: None | dict = None,
472
472
  domain: str = ALIYUN_DOMAIN,
473
+ use_open_api: bool = False,
473
474
  *,
474
475
  async_: Literal[False] = False,
475
476
  **request_kwargs,
@@ -477,7 +478,7 @@ def multipart_upload_init(
477
478
  ...
478
479
  @overload
479
480
  def multipart_upload_init(
480
- client: str | P115Client,
481
+ client: str | P115Client | P115OpenClient,
481
482
  path: str | PathLike | URL | SupportsGeturl,
482
483
  pid: int = 0,
483
484
  filename: str = "",
@@ -486,13 +487,14 @@ def multipart_upload_init(
486
487
  partsize: int = -1,
487
488
  upload_data: None | dict = None,
488
489
  domain: str = ALIYUN_DOMAIN,
490
+ use_open_api: bool = False,
489
491
  *,
490
492
  async_: Literal[True],
491
493
  **request_kwargs,
492
494
  ) -> Coroutine[Any, Any, dict]:
493
495
  ...
494
496
  def multipart_upload_init(
495
- client: str | P115Client,
497
+ client: str | P115Client | P115OpenClient,
496
498
  path: str | PathLike | URL | SupportsGeturl,
497
499
  pid: int = 0,
498
500
  filename: str = "",
@@ -501,6 +503,7 @@ def multipart_upload_init(
501
503
  partsize: int = -1,
502
504
  upload_data: None | dict = None,
503
505
  domain: str = ALIYUN_DOMAIN,
506
+ use_open_api: bool = False,
504
507
  *,
505
508
  async_: Literal[False, True] = False,
506
509
  **request_kwargs,
@@ -516,13 +519,24 @@ def multipart_upload_init(
516
519
  :param partsize: 分块大小,若不为正数则自动确定
517
520
  :param upload_data: 上传相关信息,可用于以后的断点续传
518
521
  :param domain: 上传到指定的阿里云集群的网址(netloc)
522
+ :param use_open_api: 是否使用 open 接口,如果本身就是 P115OpenClient (而不是其子类)的实例,此值强制为 True
519
523
  :param async_: 是否异步
520
524
  :param request_kwargs: 其它请求参数
521
525
 
522
526
  :return: 如果秒传成功,则返回响应信息(有 "status" 字段),否则返回上传配置信息(可用于断点续传)
523
527
  """
528
+ if not domain:
529
+ domain = ALIYUN_DOMAIN
524
530
  if isinstance(client, str):
525
531
  client = P115Client(client, check_for_relogin=True)
532
+ if type(client) is P115OpenClient:
533
+ use_open_api = True
534
+ if use_open_api:
535
+ upload_file_init = client.upload_file_init_open
536
+ upload_resume = client.upload_resume_open
537
+ else:
538
+ upload_file_init = client.upload_file_init
539
+ upload_resume = client.upload_resume
526
540
  def gen_step():
527
541
  nonlocal upload_data, path, filename, filesha1, filesize, partsize
528
542
  if upload_data is None:
@@ -618,7 +632,7 @@ def multipart_upload_init(
618
632
  else:
619
633
  with urlopen(path, headers={"Range": "bytes="+sign_check}) as file:
620
634
  return file.read()
621
- resp = yield client.upload_file_init(
635
+ resp = yield upload_file_init(
622
636
  filename=filename,
623
637
  filesize=filesize,
624
638
  filesha1=filesha1,
@@ -627,14 +641,25 @@ def multipart_upload_init(
627
641
  async_=async_, # type: ignore
628
642
  **request_kwargs,
629
643
  )
630
- status = resp["status"]
631
- statuscode = resp.get("statuscode", 0)
632
- if status == 2 and statuscode == 0:
633
- return resp
634
- elif status == 1 and statuscode == 0:
635
- bucket, object, callback = resp["bucket"], resp["object"], resp["callback"]
644
+ if use_open_api:
645
+ check_response(resp)
646
+ data = resp["data"]
647
+ match data["status"]:
648
+ case 2:
649
+ return resp
650
+ case 1:
651
+ bucket, object, callback = data["bucket"], data["object"], data["callback"]
652
+ case _:
653
+ raise OperationalError(errno.EINVAL, resp)
636
654
  else:
637
- raise OperationalError(errno.EINVAL, resp)
655
+ status = resp["status"]
656
+ statuscode = resp.get("statuscode", 0)
657
+ if status == 2 and statuscode == 0:
658
+ return resp
659
+ elif status == 1 and statuscode == 0:
660
+ bucket, object, callback = resp["bucket"], resp["object"], resp["callback"]
661
+ else:
662
+ raise OperationalError(errno.EINVAL, resp)
638
663
  upload_data["bucket"] = bucket
639
664
  upload_data["object"] = object
640
665
  upload_data["callback"] = callback
@@ -648,7 +673,7 @@ def multipart_upload_init(
648
673
  bucket = upload_data["bucket"]
649
674
  object = upload_data["object"]
650
675
  callback_var = loads(upload_data["callback"]["callback_var"])
651
- resp = yield client.upload_resume(
676
+ resp = yield upload_resume(
652
677
  {
653
678
  "fileid": object,
654
679
  "file_size": upload_data["filesize"],
@@ -676,6 +701,7 @@ def multipart_upload_init(
676
701
  upload_data["part_number_next"] = len(parts) + (int(parts[-1]["Size"]) == upload_data["partsize"])
677
702
  else:
678
703
  upload_data["part_number_next"] = 1
704
+ upload_data["parts"] = parts
679
705
  else:
680
706
  upload_data["upload_id"] = yield oss_multipart_upload_init(
681
707
  client.request,
@@ -687,12 +713,14 @@ def multipart_upload_init(
687
713
  **request_kwargs,
688
714
  )
689
715
  upload_data["part_number_next"] = 1
716
+ upload_data["parts"] = []
717
+ upload_data["_upload_"] = None
690
718
  return upload_data
691
719
  return run_gen_step(gen_step, async_=async_)
692
720
 
693
721
 
694
722
  def multipart_upload_url(
695
- client: str | P115Client | dict,
723
+ client: str | P115Client | P115OpenClient | dict,
696
724
  upload_data: dict,
697
725
  part_number: int = 1,
698
726
  domain: str = ALIYUN_DOMAIN,
@@ -706,6 +734,8 @@ def multipart_upload_url(
706
734
 
707
735
  :return: 上传链接 和 请求头 的 2 元组
708
736
  """
737
+ if not domain:
738
+ domain = ALIYUN_DOMAIN
709
739
  if isinstance(client, dict):
710
740
  token = client
711
741
  else:
@@ -724,7 +754,7 @@ def multipart_upload_url(
724
754
 
725
755
  @overload
726
756
  def multipart_upload_complete(
727
- client: str | P115Client,
757
+ client: str | P115Client | P115OpenClient,
728
758
  upload_data: dict,
729
759
  domain: str = ALIYUN_DOMAIN,
730
760
  *,
@@ -734,7 +764,7 @@ def multipart_upload_complete(
734
764
  ...
735
765
  @overload
736
766
  def multipart_upload_complete(
737
- client: str | P115Client,
767
+ client: str | P115Client | P115OpenClient,
738
768
  upload_data: dict,
739
769
  domain: str = ALIYUN_DOMAIN,
740
770
  *,
@@ -743,7 +773,7 @@ def multipart_upload_complete(
743
773
  ) -> Coroutine[Any, Any, dict]:
744
774
  ...
745
775
  def multipart_upload_complete(
746
- client: str | P115Client,
776
+ client: str | P115Client | P115OpenClient,
747
777
  upload_data: dict,
748
778
  domain: str = ALIYUN_DOMAIN,
749
779
  *,
@@ -764,6 +794,7 @@ def multipart_upload_complete(
764
794
  你可以构建自己的分块上传逻辑,下面是一个例子
765
795
 
766
796
  .. code:: python
797
+
767
798
  from pathlib import Path
768
799
  from p115client import *
769
800
  from p115client.tool import *
@@ -773,6 +804,7 @@ def multipart_upload_complete(
773
804
 
774
805
  # TODO: 这里填一个文件的路径
775
806
  path = "test.txt"
807
+
776
808
  upload_data = multipart_upload_init(
777
809
  client,
778
810
  path,
@@ -780,9 +812,7 @@ def multipart_upload_complete(
780
812
  filename = "",
781
813
  upload_data = None,
782
814
  )
783
- if "status" in upload_data:
784
- resp = upload_data
785
- else:
815
+ if "_upload_" in upload_data:
786
816
  partsize = upload_data["partsize"]
787
817
  part_number_next = upload_data["part_number_next"]
788
818
  with open(path, "rb") as file:
@@ -797,18 +827,22 @@ def multipart_upload_complete(
797
827
  ## NOTE: 使用 requests
798
828
  # from requests import request
799
829
  # request("PUT", url, data=file.read(partsize), headers=headers)
800
- client.request(url=url, method="PUT", data=file.read(partsize), headers=headers, parse=False
830
+ client.request(url=url, method="PUT", data=file.read(partsize), headers=headers, parse=False)
801
831
  resp = multipart_upload_complete(client, upload_data)
832
+ else:
833
+ resp = upload_data
802
834
  print(resp)
803
835
  """
836
+ if not domain:
837
+ domain = ALIYUN_DOMAIN
804
838
  bucket = upload_data["bucket"]
805
839
  object = upload_data["object"]
806
840
  upload_id = upload_data["upload_id"]
807
841
  url = f"http://{bucket}.{domain}/{object}"
808
842
  if isinstance(client, str):
809
843
  client = P115Client(client, check_for_relogin=True)
810
- token = client.upload_token
811
844
  def gen_step():
845
+ token = client.upload_token
812
846
  parts = yield collect(oss_multipart_part_iter(
813
847
  client.request,
814
848
  url,
@@ -833,3 +867,4 @@ def multipart_upload_complete(
833
867
  )
834
868
  return run_gen_step(gen_step, async_=async_)
835
869
 
870
+ # TODO: 分块上传支持使用开放接口
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "p115client"
3
- version = "0.0.5.11.9"
3
+ version = "0.0.5.11.9.1"
4
4
  description = "Python 115 webdisk client."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"