p115client 0.0.5.11__py3-none-any.whl → 0.0.5.11.2__py3-none-any.whl

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.
p115client/_upload.py CHANGED
@@ -281,11 +281,11 @@ def oss_multipart_part_iter(
281
281
  **request_kwargs,
282
282
  )
283
283
  for el in etree.iterfind("Part"):
284
- yield Yield({sel.tag: maybe_integer(sel.text) for sel in el}, may_await=False)
284
+ yield Yield({sel.tag: maybe_integer(sel.text) for sel in el})
285
285
  if getattr(etree.find("IsTruncated"), "text") == "false":
286
286
  break
287
287
  params["part-number-marker"] = getattr(etree.find("NextPartNumberMarker"), "text")
288
- return run_gen_step_iter(gen_step, simple=True, async_=async_)
288
+ return run_gen_step_iter(gen_step, may_call=False, async_=async_)
289
289
 
290
290
 
291
291
  @overload
@@ -679,7 +679,7 @@ def oss_multipart_upload_part_iter(
679
679
  ))
680
680
  if part["Size"] < partsize:
681
681
  break
682
- return run_gen_step_iter(gen_step, simple=True, async_=async_)
682
+ return run_gen_step_iter(gen_step, may_call=False, async_=async_)
683
683
 
684
684
 
685
685
  @overload
@@ -846,7 +846,7 @@ def oss_multipart_upload(
846
846
  if part["Size"] != partsize:
847
847
  break
848
848
  add_part(part)
849
- yield async_request
849
+ yield async_request()
850
850
  else:
851
851
  for part in oss_multipart_part_iter(
852
852
  request,
@@ -926,8 +926,8 @@ def oss_multipart_upload(
926
926
  raise MultipartUploadAbort(resume_data) from e
927
927
  finally:
928
928
  if close_reporthook is not None:
929
- yield close_reporthook
930
- return run_gen_step(gen_step, simple=True, async_=async_)
929
+ yield close_reporthook()
930
+ return run_gen_step(gen_step, may_call=False, async_=async_)
931
931
 
932
932
 
933
933
  # class MultipartUploader:
p115client/client.py CHANGED
@@ -596,13 +596,34 @@ def check_response(resp: dict | Awaitable[dict], /) -> dict | Coroutine[Any, Any
596
596
  raise P115OSError(errno.EIO, resp)
597
597
 
598
598
 
599
+ @overload
599
600
  def normalize_attr_web(
600
601
  info: Mapping,
601
602
  /,
602
603
  simple: bool = False,
603
604
  keep_raw: bool = False,
604
- dict_cls: None | type[dict] = None,
605
+ *,
606
+ dict_cls: None = None,
605
607
  ) -> dict[str, Any]:
608
+ ...
609
+ @overload
610
+ def normalize_attr_web[D: dict[str, Any]](
611
+ info: Mapping,
612
+ /,
613
+ simple: bool = False,
614
+ keep_raw: bool = False,
615
+ *,
616
+ dict_cls: type[D],
617
+ ) -> D:
618
+ ...
619
+ def normalize_attr_web[D: dict[str, Any]](
620
+ info: Mapping,
621
+ /,
622
+ simple: bool = False,
623
+ keep_raw: bool = False,
624
+ *,
625
+ dict_cls: None | type[D] = None,
626
+ ) -> dict[str, Any] | D:
606
627
  """翻译 `P115Client.fs_files`、`P115Client.fs_search`、`P115Client.share_snap` 等接口响应的文件信息数据,使之便于阅读
607
628
 
608
629
  :param info: 原始数据
@@ -613,10 +634,7 @@ def normalize_attr_web(
613
634
  :return: 翻译后的 dict 类型数据
614
635
  """
615
636
  if dict_cls is None:
616
- if simple:
617
- dict_cls = dict
618
- else:
619
- dict_cls = AttrDict
637
+ dict_cls = cast(type[D], dict)
620
638
  attr: dict[str, Any] = dict_cls()
621
639
  is_directory = attr["is_dir"] = "fid" not in info
622
640
  if not simple:
@@ -720,10 +738,10 @@ def normalize_attr_web(
720
738
  attr["type"] = 0
721
739
  elif info.get("iv") or "vdi" in info:
722
740
  attr["type"] = 4
723
- elif type := CLASS_TO_TYPE.get(attr.get("class", "")):
724
- attr["type"] = type
725
- elif type := SUFFIX_TO_TYPE.get(splitext(attr["name"])[1].lower()):
726
- attr["type"] = type
741
+ elif type_ := CLASS_TO_TYPE.get(attr.get("class", "")):
742
+ attr["type"] = type_
743
+ elif type_ := SUFFIX_TO_TYPE.get(splitext(attr["name"])[1].lower()):
744
+ attr["type"] = type_
727
745
  else:
728
746
  attr["type"] = 99
729
747
  if keep_raw:
@@ -731,13 +749,33 @@ def normalize_attr_web(
731
749
  return attr
732
750
 
733
751
 
752
+ @overload
734
753
  def normalize_attr_app(
735
754
  info: Mapping,
736
755
  /,
737
756
  simple: bool = False,
738
757
  keep_raw: bool = False,
739
- dict_cls: None | type[dict] = None,
758
+ *,
759
+ dict_cls: None = None,
740
760
  ) -> dict[str, Any]:
761
+ ...
762
+ @overload
763
+ def normalize_attr_app[D: dict[str, Any]](
764
+ info: Mapping,
765
+ /,
766
+ simple: bool = False,
767
+ keep_raw: bool = False,
768
+ *,
769
+ dict_cls: None | type[D] = None,
770
+ ) -> D:
771
+ ...
772
+ def normalize_attr_app[D: dict[str, Any]](
773
+ info: Mapping,
774
+ /,
775
+ simple: bool = False,
776
+ keep_raw: bool = False,
777
+ dict_cls: None | type[D] = None,
778
+ ) -> dict[str, Any] | D:
741
779
  """翻译 `P115Client.fs_files_app` 接口响应的文件信息数据,使之便于阅读
742
780
 
743
781
  :param info: 原始数据
@@ -748,10 +786,7 @@ def normalize_attr_app(
748
786
  :return: 翻译后的 dict 类型数据
749
787
  """
750
788
  if dict_cls is None:
751
- if simple:
752
- dict_cls = dict
753
- else:
754
- dict_cls = AttrDict
789
+ dict_cls = cast(type[D], dict)
755
790
  attr: dict[str, Any] = dict_cls()
756
791
  is_directory = attr["is_dir"] = info["fc"] == "0" # fc => file_category
757
792
  if not simple:
@@ -835,8 +870,8 @@ def normalize_attr_app(
835
870
  attr["type"] = 3
836
871
  elif info.get("isv") or "def" in info or "def2" in info or "v_img" in info:
837
872
  attr["type"] = 4
838
- elif type := SUFFIX_TO_TYPE.get(splitext(attr["name"])[1].lower()):
839
- attr["type"] = type
873
+ elif type_ := SUFFIX_TO_TYPE.get(splitext(attr["name"])[1].lower()):
874
+ attr["type"] = type_
840
875
  else:
841
876
  attr["type"] = 99
842
877
  if keep_raw:
@@ -844,13 +879,33 @@ def normalize_attr_app(
844
879
  return attr
845
880
 
846
881
 
882
+ @overload
847
883
  def normalize_attr_app2(
848
884
  info: Mapping,
849
885
  /,
850
886
  simple: bool = False,
851
887
  keep_raw: bool = False,
852
- dict_cls: None | type[dict] = None,
888
+ *,
889
+ dict_cls: None = None,
853
890
  ) -> dict[str, Any]:
891
+ ...
892
+ @overload
893
+ def normalize_attr_app2[D: dict[str, Any]](
894
+ info: Mapping,
895
+ /,
896
+ simple: bool = False,
897
+ keep_raw: bool = False,
898
+ *,
899
+ dict_cls: None | type[D] = None,
900
+ ) -> D:
901
+ ...
902
+ def normalize_attr_app2[D: dict[str, Any]](
903
+ info: Mapping,
904
+ /,
905
+ simple: bool = False,
906
+ keep_raw: bool = False,
907
+ dict_cls: None | type[D] = None,
908
+ ) -> dict[str, Any] | D:
854
909
  """翻译 `P115Client.fs_files_app2` 接口响应的文件信息数据,使之便于阅读
855
910
 
856
911
  :param info: 原始数据
@@ -861,10 +916,7 @@ def normalize_attr_app2(
861
916
  :return: 翻译后的 dict 类型数据
862
917
  """
863
918
  if dict_cls is None:
864
- if simple:
865
- dict_cls = dict
866
- else:
867
- dict_cls = AttrDict
919
+ dict_cls = cast(type[D], dict)
868
920
  attr: dict[str, Any] = dict_cls()
869
921
  if "file_id" in info and "parent_id" in info:
870
922
  if "file_category" in info:
@@ -970,8 +1022,8 @@ def normalize_attr_app2(
970
1022
  attr["type"] = 3
971
1023
  elif info.get("is_video") or "definition" in info or "definition2" in info or "video_img_url" in info:
972
1024
  attr["type"] = 4
973
- elif type := SUFFIX_TO_TYPE.get(splitext(attr["name"])[1].lower()):
974
- attr["type"] = type
1025
+ elif type_ := SUFFIX_TO_TYPE.get(splitext(attr["name"])[1].lower()):
1026
+ attr["type"] = type_
975
1027
  else:
976
1028
  attr["type"] = 99
977
1029
  if keep_raw:
@@ -979,13 +1031,34 @@ def normalize_attr_app2(
979
1031
  return attr
980
1032
 
981
1033
 
1034
+ @overload
982
1035
  def normalize_attr(
983
1036
  info: Mapping,
984
1037
  /,
985
1038
  simple: bool = False,
986
1039
  keep_raw: bool = False,
987
- dict_cls: None | type[dict] = None,
1040
+ *,
1041
+ dict_cls: None,
988
1042
  ) -> dict[str, Any]:
1043
+ ...
1044
+ @overload
1045
+ def normalize_attr[D: dict[str, Any]](
1046
+ info: Mapping,
1047
+ /,
1048
+ simple: bool = False,
1049
+ keep_raw: bool = False,
1050
+ *,
1051
+ dict_cls: type[D] = AttrDict, # type: ignore
1052
+ ) -> D:
1053
+ ...
1054
+ def normalize_attr[D: dict[str, Any]](
1055
+ info: Mapping,
1056
+ /,
1057
+ simple: bool = False,
1058
+ keep_raw: bool = False,
1059
+ *,
1060
+ dict_cls: None | type[D] = AttrDict, # type: ignore
1061
+ ) -> dict[str, Any] | D:
989
1062
  """翻译获取自罗列目录、搜索、获取文件信息等接口的数据,使之便于阅读
990
1063
 
991
1064
  :param info: 原始数据
@@ -1003,12 +1076,32 @@ def normalize_attr(
1003
1076
  return normalize_attr_web(info, simple=simple, keep_raw=keep_raw, dict_cls=dict_cls)
1004
1077
 
1005
1078
 
1079
+ @overload
1006
1080
  def normalize_attr_simple(
1007
1081
  info: Mapping,
1008
1082
  /,
1009
1083
  keep_raw: bool = False,
1084
+ *,
1085
+ dict_cls: None = None,
1010
1086
  ) -> dict[str, Any]:
1011
- return normalize_attr(info, simple=True, keep_raw=keep_raw)
1087
+ ...
1088
+ @overload
1089
+ def normalize_attr_simple[D: dict[str, Any]](
1090
+ info: Mapping,
1091
+ /,
1092
+ keep_raw: bool = False,
1093
+ *,
1094
+ dict_cls: type[D],
1095
+ ) -> D:
1096
+ ...
1097
+ def normalize_attr_simple[D: dict[str, Any]](
1098
+ info: Mapping,
1099
+ /,
1100
+ keep_raw: bool = False,
1101
+ *,
1102
+ dict_cls: None | type[D] = None,
1103
+ ) -> dict[str, Any] | D:
1104
+ return normalize_attr(info, may_call=False, keep_raw=keep_raw, dict_cls=dict_cls)
1012
1105
 
1013
1106
 
1014
1107
  class IgnoreCaseDict[V](dict[str, V]):
@@ -2224,7 +2317,7 @@ class ClientRequestMixin:
2224
2317
  )
2225
2318
  else:
2226
2319
  return qrcode_token
2227
- return run_gen_step(gen_step, simple=True, async_=async_)
2320
+ return run_gen_step(gen_step, may_call=False, async_=async_)
2228
2321
 
2229
2322
  @overload
2230
2323
  @classmethod
@@ -2324,7 +2417,7 @@ class ClientRequestMixin:
2324
2417
  async_=async_,
2325
2418
  **request_kwargs,
2326
2419
  )
2327
- return run_gen_step(gen_step, simple=True, async_=async_)
2420
+ return run_gen_step(gen_step, may_call=False, async_=async_)
2328
2421
 
2329
2422
  ########## Upload API ##########
2330
2423
 
@@ -2707,7 +2800,7 @@ class ClientRequestMixin:
2707
2800
  async_=async_,
2708
2801
  **request_kwargs,
2709
2802
  )
2710
- return run_gen_step(gen_step, simple=True, async_=async_)
2803
+ return run_gen_step(gen_step, may_call=False, async_=async_)
2711
2804
 
2712
2805
  @overload
2713
2806
  def read_bytes_range(
@@ -2822,7 +2915,7 @@ class ClientRequestMixin:
2822
2915
  async_=async_,
2823
2916
  **request_kwargs,
2824
2917
  )
2825
- return run_gen_step(gen_step, simple=True, async_=async_)
2918
+ return run_gen_step(gen_step, may_call=False, async_=async_)
2826
2919
 
2827
2920
 
2828
2921
  class P115OpenClient(ClientRequestMixin):
@@ -2918,7 +3011,7 @@ class P115OpenClient(ClientRequestMixin):
2918
3011
  self.refresh_token = data["refresh_token"]
2919
3012
  self.access_token = data["access_token"]
2920
3013
  return self
2921
- return run_gen_step(gen_step, simple=True, async_=async_)
3014
+ return run_gen_step(gen_step, may_call=False, async_=async_)
2922
3015
 
2923
3016
  @classmethod
2924
3017
  def from_token(cls, /, access_token: str, refresh_token: str) -> P115OpenClient:
@@ -2985,7 +3078,7 @@ class P115OpenClient(ClientRequestMixin):
2985
3078
  self.refresh_token = data["refresh_token"]
2986
3079
  access_token = self.access_token = data["access_token"]
2987
3080
  return access_token
2988
- return run_gen_step(gen_step, simple=True, async_=async_)
3081
+ return run_gen_step(gen_step, may_call=False, async_=async_)
2989
3082
 
2990
3083
  @overload
2991
3084
  def download_url(
@@ -4711,7 +4804,7 @@ class P115OpenClient(ClientRequestMixin):
4711
4804
  check_response(resp)
4712
4805
  resp["data"] = {**payload, **resp["data"], "sha1": filesha1, "cid": pid}
4713
4806
  return resp
4714
- return run_gen_step(gen_step, simple=True, async_=async_)
4807
+ return run_gen_step(gen_step, may_call=False, async_=async_)
4715
4808
 
4716
4809
  @overload
4717
4810
  def upload_file(
@@ -5055,7 +5148,7 @@ class P115OpenClient(ClientRequestMixin):
5055
5148
  async_=async_, # type: ignore
5056
5149
  **request_kwargs,
5057
5150
  )
5058
- return run_gen_step(gen_step, simple=True, async_=async_)
5151
+ return run_gen_step(gen_step, may_call=False, async_=async_)
5059
5152
 
5060
5153
  @overload
5061
5154
  def user_info(
@@ -5436,7 +5529,7 @@ class P115Client(P115OpenClient):
5436
5529
  )
5437
5530
  setattr(self, "check_for_relogin", check_for_relogin)
5438
5531
  return self
5439
- return run_gen_step(gen_step, simple=True, async_=async_)
5532
+ return run_gen_step(gen_step, may_call=False, async_=async_)
5440
5533
 
5441
5534
  @locked_cacheproperty
5442
5535
  def request_lock(self, /) -> Lock:
@@ -5608,7 +5701,7 @@ class P115Client(P115OpenClient):
5608
5701
  check_response(resp)
5609
5702
  setattr(self, "cookies", resp["data"]["cookie"])
5610
5703
  return self
5611
- return run_gen_step(gen_step, simple=True, async_=async_)
5704
+ return run_gen_step(gen_step, may_call=False, async_=async_)
5612
5705
 
5613
5706
  @overload
5614
5707
  def login_with_app(
@@ -5740,7 +5833,7 @@ class P115Client(P115OpenClient):
5740
5833
  async_=async_,
5741
5834
  **request_kwargs,
5742
5835
  )
5743
- return run_gen_step(gen_step, simple=True, async_=async_)
5836
+ return run_gen_step(gen_step, may_call=False, async_=async_)
5744
5837
 
5745
5838
  @overload
5746
5839
  def login_without_app(
@@ -5798,7 +5891,7 @@ class P115Client(P115OpenClient):
5798
5891
  )
5799
5892
  check_response(resp)
5800
5893
  return uid
5801
- return run_gen_step(gen_step, simple=True, async_=async_)
5894
+ return run_gen_step(gen_step, may_call=False, async_=async_)
5802
5895
 
5803
5896
  @overload
5804
5897
  def login_with_open(
@@ -5850,7 +5943,7 @@ class P115Client(P115OpenClient):
5850
5943
  resp = yield self.login_qrcode_scan_confirm(login_uid, async_=async_, **request_kwargs)
5851
5944
  check_response(resp)
5852
5945
  return self.login_qrcode_access_token_open(login_uid, async_=async_, **request_kwargs)
5853
- return run_gen_step(gen_step, simple=True, async_=async_)
5946
+ return run_gen_step(gen_step, may_call=False, async_=async_)
5854
5947
 
5855
5948
  @overload
5856
5949
  def login_another_app(
@@ -5994,7 +6087,7 @@ class P115Client(P115OpenClient):
5994
6087
  if self is not inst and ssoent == inst.login_ssoent:
5995
6088
  warn(f"login with the same ssoent {ssoent!r}, {self!r} will expire within 60 seconds", category=P115Warning)
5996
6089
  return inst
5997
- return run_gen_step(gen_step, simple=True, async_=async_)
6090
+ return run_gen_step(gen_step, may_call=False, async_=async_)
5998
6091
 
5999
6092
  @overload
6000
6093
  def login_another_open(
@@ -6088,7 +6181,7 @@ class P115Client(P115OpenClient):
6088
6181
  inst.access_token = data["access_token"]
6089
6182
  inst.app_id = app_id
6090
6183
  return inst
6091
- return run_gen_step(gen_step, simple=True, async_=async_)
6184
+ return run_gen_step(gen_step, may_call=False, async_=async_)
6092
6185
 
6093
6186
  @overload
6094
6187
  @classmethod
@@ -6207,7 +6300,7 @@ class P115Client(P115OpenClient):
6207
6300
  resp = yield cls.login_qrcode_scan_result(uid, app, async_=async_, **request_kwargs)
6208
6301
  cookies = check_response(resp)["data"]["cookie"]
6209
6302
  return cls(cookies, check_for_relogin=check_for_relogin)
6210
- return run_gen_step(gen_step, simple=True, async_=async_)
6303
+ return run_gen_step(gen_step, may_call=False, async_=async_)
6211
6304
 
6212
6305
  @overload
6213
6306
  def logout(
@@ -6389,7 +6482,7 @@ class P115Client(P115OpenClient):
6389
6482
  def gen_step():
6390
6483
  cert_headers: None | Mapping = None
6391
6484
  if need_fetch_cert_first:
6392
- cert_headers = yield fetch_cert_headers
6485
+ cert_headers = yield cast(Callable, fetch_cert_headers)()
6393
6486
  headers.update(cert_headers)
6394
6487
  if async_:
6395
6488
  lock: Lock | AsyncLock = self.request_alock
@@ -6433,7 +6526,7 @@ class P115Client(P115OpenClient):
6433
6526
  if not res if isinstance(res, bool) else res != 405:
6434
6527
  raise
6435
6528
  if fetch_cert_headers is not None:
6436
- cert_headers = yield fetch_cert_headers
6529
+ cert_headers = yield fetch_cert_headers()
6437
6530
  headers.update(cert_headers)
6438
6531
  elif is_open_api:
6439
6532
  yield lock.acquire
@@ -6482,7 +6575,7 @@ class P115Client(P115OpenClient):
6482
6575
  if check and isinstance(resp, dict):
6483
6576
  check_response(resp)
6484
6577
  return resp
6485
- return run_gen_step(gen_step, simple=True, async_=async_)
6578
+ return run_gen_step(gen_step, may_call=False, async_=async_)
6486
6579
 
6487
6580
  def request(
6488
6581
  self,
@@ -7341,7 +7434,7 @@ class P115Client(P115OpenClient):
7341
7434
  async_=async_,
7342
7435
  **request_kwargs,
7343
7436
  )
7344
- return run_gen_step(gen_step, simple=True, async_=async_)
7437
+ return run_gen_step(gen_step, may_call=False, async_=async_)
7345
7438
 
7346
7439
  ########## Download API ##########
7347
7440
 
@@ -15916,7 +16009,7 @@ class P115Client(P115OpenClient):
15916
16009
  if device is None:
15917
16010
  return None
15918
16011
  return device["icon"]
15919
- return run_gen_step(gen_step, simple=True, async_=async_)
16012
+ return run_gen_step(gen_step, may_call=False, async_=async_)
15920
16013
 
15921
16014
  @overload
15922
16015
  def login_open_auth_detail(
@@ -16440,7 +16533,7 @@ class P115Client(P115OpenClient):
16440
16533
  return get_default_request()(url=api, async_=async_, **request_kwargs)
16441
16534
  else:
16442
16535
  return request(url=api, **request_kwargs)
16443
- return run_gen_step(gen_step, simple=True, async_=async_)
16536
+ return run_gen_step(gen_step, may_call=False, async_=async_)
16444
16537
 
16445
16538
  @overload
16446
16539
  def logout_by_ssoent(
@@ -20334,7 +20427,7 @@ class P115Client(P115OpenClient):
20334
20427
  if resp["state"]:
20335
20428
  self.user_key = resp["data"]["userkey"]
20336
20429
  return resp
20337
- return run_gen_step(gen_step, simple=True, async_=async_)
20430
+ return run_gen_step(gen_step, may_call=False, async_=async_)
20338
20431
 
20339
20432
  @overload
20340
20433
  def upload_resume(
@@ -20701,7 +20794,7 @@ class P115Client(P115OpenClient):
20701
20794
  "pickcode": resp["pickcode"],
20702
20795
  }
20703
20796
  return resp
20704
- return run_gen_step(gen_step, simple=True, async_=async_)
20797
+ return run_gen_step(gen_step, may_call=False, async_=async_)
20705
20798
 
20706
20799
  @overload
20707
20800
  def upload_file_sample(
@@ -20837,7 +20930,7 @@ class P115Client(P115OpenClient):
20837
20930
  async_=async_,
20838
20931
  **request_kwargs,
20839
20932
  )
20840
- return run_gen_step(gen_step, simple=True, async_=async_)
20933
+ return run_gen_step(gen_step, may_call=False, async_=async_)
20841
20934
 
20842
20935
  @overload # type: ignore
20843
20936
  def upload_file(
@@ -21196,7 +21289,7 @@ class P115Client(P115OpenClient):
21196
21289
  async_=async_, # type: ignore
21197
21290
  **request_kwargs,
21198
21291
  )
21199
- return run_gen_step(gen_step, simple=True, async_=async_)
21292
+ return run_gen_step(gen_step, may_call=False, async_=async_)
21200
21293
 
21201
21294
  ########## User API ##########
21202
21295
 
p115client/tool/attr.py CHANGED
@@ -72,7 +72,7 @@ def get_attr(
72
72
  resp = yield client.fs_file(id, async_=async_, **request_kwargs)
73
73
  check_response(resp)
74
74
  return normalize_attr_web(resp["data"][0])
75
- return run_gen_step(gen_step, simple=True, async_=async_)
75
+ return run_gen_step(gen_step, may_call=False, async_=async_)
76
76
 
77
77
 
78
78
  def type_of_attr(attr: Mapping, /) -> int: