class Service(StaffRoom): def __init__(self, num_employees: int = DEEFAULT_NUM_EMPLOYEES): self.__available_employees = Semaphore(num_employees) async def start_task(self) -> None: await self.__available_employees.acquire() async def stop_task(self) -> None: self.__available_employees.release()
def __init__(self, reporter, waiter, outdir, useragent) -> None: super(Keiba, self).__init__() self.reporter: Reporter = reporter self.waiter = waiter self.outdir = outdir self.useragent = useragent self.cacher = Cacher(self.outdir) self.semaphore = Semaphore(2)
def __init__(self, reporter: Reporter = None, waiter: Waiter = None, fetcher: Fetcher = None): self.reporter = reporter self.waiter = waiter self.fetcher = fetcher self.semaphore = Semaphore(10) self.title = 'wear'
def __init__(self, reporter: Reporter = None, waiter: Waiter = None, fetcher: Fetcher = None, **others): self.reporter = reporter self.waiter = waiter self.fetcher = fetcher self.semaphore = Semaphore(10) self.title = 'unsplash'
def __init__(self, reporter: Reporter, waiter: Waiter, outdir: str, useragent: str = ''): super(WearCollector, self).__init__() self.reporter: Reporter = reporter self.waiter = waiter self.outdir = outdir self.useragent = useragent self.cacher = Cacher(self.outdir) # 非同期処理の同時接続数制御 self.semaphore = Semaphore(2) # ファイルダウンローダ self.downloader = Downloader(self.waiter, self.semaphore, self.reporter)
if IS_BUNDLED: STATIC_ROOT = os.path.dirname(sys.modules['pyportify'].__file__) else: STATIC_ROOT = os.path.join(BASE_DIR, "static") class UserScope(object): def __init__(self): self.google_token = None self.spotify_token = None user_scope = UserScope() semaphore = Semaphore(20) @asyncio.coroutine def google_login(request): data = yield from request.json() email = data.get("email") password = data.get("password") with ClientSession() as session: g = Mobileclient(session) token = yield from g.login(email, password) if not token: return json_response(dict(
def __init__(self, num_employees: int = DEEFAULT_NUM_EMPLOYEES): self.__available_employees = Semaphore(num_employees)
def __init__(self): self.semaphore = Semaphore()
def __init__(self): self.session = CachedApiSession() self.login_semaphore = Semaphore() self.logged_in = False
class ApiSessionWithDialogs(): def __init__(self): self.session = CachedApiSession() self.login_semaphore = Semaphore() self.logged_in = False '''async def device_login(self): if not self.device_logged_in: localsecret = self.session_cache.get("localsecret") if localsecret is None: localsecret = await self.get("/user/device_login")["localsecret"] self.session_cache.set("localsecret", localsecret) else: await self.session.get("/user/device_login", {"localsecret" : localsecret}) self.device_logged_in = True''' async def get_with_login(self, method, params={}): try: result = await self.session.get(method, params) except LoginRequired: await self.login_semaphore.acquire() if not self.logged_in: await self.DoLogin() self.login_semaphore.release() return await self.session.get(method, params) return result async def get(self, method, params={}): try: result = await self.get_with_login(method, params) except Require2FA: async def On2FA(otp): result = await self.session.get("/user/otp", {"otp": otp}) print(result) dlg = Dialog2FA(Handle2FACoroutine=On2FA) await AsyncShowDialog(dlg) #otp = dlg.GetValue() result = await self.get_with_login(method, params) return result async def DoLogin(self): login_completed = Event() async def HandleLogin(username, password): result = await self.session.get("/user/login", { "email": username, "password": password }) login_completed.set() async def HandleCreateAccountStep1(username): await self.get("/user/register", {"email": username}) async def HandleCreateAccountStep2(confirmation_code, username, password, otp_secret): await self.get( "/user/register_confirm", { "confirmation_code": confirmation_code, "password": password, "otp_secret": otp_secret }) await self.session.get("/user/login", { "email": username, "password": password }) login_completed.set() login_dialog = LoginDialog( None, HandleLogin=HandleLogin, HandleCreateAccountStep1=HandleCreateAccountStep1, HandleCreateAccountStep2=HandleCreateAccountStep2) login_dialog.Show() await login_completed.wait() login_dialog.Hide()