@@ -22,18 +22,19 @@ class AbortReqError(Exception): ...
2222
2323
2424class XClIdGenStore :
25- items : dict [str , XClIdGen ] = {} # username -> XClIdGen
25+ items : dict [tuple [ str , str | None ], XClIdGen ] = {} # ( username, proxy) -> XClIdGen
2626
2727 @classmethod
28- async def get (cls , username : str , fresh = False ) -> XClIdGen :
29- if username in cls .items and not fresh :
30- return cls .items [username ]
28+ async def get (cls , username : str , proxy : str | None = None , fresh = False ) -> XClIdGen :
29+ key = (username , proxy )
30+ if key in cls .items and not fresh :
31+ return cls .items [key ]
3132
3233 tries = 0
3334 while tries < 3 :
3435 try :
35- clid_gen = await XClIdGen .create ()
36- cls .items [username ] = clid_gen
36+ clid_gen = await XClIdGen .create (proxy = proxy )
37+ cls .items [key ] = clid_gen
3738 return clid_gen
3839 except Exception as e :
3940 tries += 1
@@ -48,10 +49,11 @@ async def get(cls, username: str, fresh=False) -> XClIdGen:
4849
4950
5051class Ctx :
51- def __init__ (self , acc : Account , clt : HttpClient ):
52+ def __init__ (self , acc : Account , clt : HttpClient , proxy : str | None = None ):
5253 self .req_count = 0
5354 self .acc = acc
5455 self .clt = clt
56+ self .proxy = proxy
5557
5658 async def aclose (self ):
5759 await self .clt .aclose ()
@@ -63,7 +65,7 @@ async def req(self, method: HttpMethod, url: str, params: ReqParams = None) -> R
6365
6466 tries = 0
6567 while tries < 3 :
66- gen = await XClIdGenStore .get (self .acc .username , fresh = tries > 0 )
68+ gen = await XClIdGenStore .get (self .acc .username , proxy = self . proxy , fresh = tries > 0 )
6769 hdr = {"x-client-transaction-id" : gen .calc (method , path )}
6870 rep = await self .clt .request (method , url , params = params , headers = hdr )
6971 if rep .status_code != 404 :
@@ -157,7 +159,7 @@ async def _get_ctx(self):
157159 return None
158160
159161 clt = acc .make_client (proxy = self .proxy )
160- self .ctx = Ctx (acc , clt )
162+ self .ctx = Ctx (acc , clt , proxy = acc . resolve_proxy ( self . proxy ) )
161163 return self .ctx
162164
163165 async def _check_rep (self , rep : Response ) -> None :
0 commit comments