mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-12 23:37:14 +03:00
protocol.py: mypy pass
* 'type: ignore' some ctypes operations on variables. * Use `c_long(<value>)` on some returns. The ctypes types do work that way as constructors. * Fix the BAseHTTPHandler.log_request() types to match superclass.
This commit is contained in:
parent
bb2bf53647
commit
0d2505ea48
22
protocol.py
22
protocol.py
@ -1,5 +1,4 @@
|
|||||||
"""protocol handler for cAPI authorisation."""
|
"""protocol handler for cAPI authorisation."""
|
||||||
|
|
||||||
# spell-checker: words ntdll GURL alloc wfile instantiatable pyright
|
# spell-checker: words ntdll GURL alloc wfile instantiatable pyright
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -35,7 +34,7 @@ class GenericProtocolHandler:
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.redirect = protocolhandler_redirect # Base redirection URL
|
self.redirect = protocolhandler_redirect # Base redirection URL
|
||||||
self.master: 'tkinter.Tk' = None # type: ignore
|
self.master: 'tkinter.Tk' = None # type: ignore
|
||||||
self.lastpayload = None
|
self.lastpayload: Optional[str] = None
|
||||||
|
|
||||||
def start(self, master: 'tkinter.Tk') -> None:
|
def start(self, master: 'tkinter.Tk') -> None:
|
||||||
"""Start Protocol Handler."""
|
"""Start Protocol Handler."""
|
||||||
@ -45,7 +44,7 @@ class GenericProtocolHandler:
|
|||||||
"""Stop / Close Protocol Handler."""
|
"""Stop / Close Protocol Handler."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def event(self, url) -> None:
|
def event(self, url: str) -> None:
|
||||||
"""Generate an auth event."""
|
"""Generate an auth event."""
|
||||||
self.lastpayload = url
|
self.lastpayload = url
|
||||||
|
|
||||||
@ -197,7 +196,7 @@ elif (config.auth_force_edmc_protocol
|
|||||||
# Windows Message handler stuff (IPC)
|
# Windows Message handler stuff (IPC)
|
||||||
# https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633573(v=vs.85)
|
# https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633573(v=vs.85)
|
||||||
@WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)
|
@WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)
|
||||||
def WndProc(hwnd: HWND, message: UINT, wParam, lParam): # noqa: N803 N802
|
def WndProc(hwnd: HWND, message: UINT, wParam: WPARAM, lParam: LPARAM) -> c_long: # noqa: N803 N802
|
||||||
"""
|
"""
|
||||||
Deal with DDE requests.
|
Deal with DDE requests.
|
||||||
|
|
||||||
@ -216,8 +215,10 @@ elif (config.auth_force_edmc_protocol
|
|||||||
topic = create_unicode_buffer(256)
|
topic = create_unicode_buffer(256)
|
||||||
# Note that lParam is 32 bits, and broken into two 16 bit words. This will break on 64bit as the math is
|
# Note that lParam is 32 bits, and broken into two 16 bit words. This will break on 64bit as the math is
|
||||||
# wrong
|
# wrong
|
||||||
lparam_low = lParam & 0xFFFF # if nonzero, the target application for which a conversation is requested
|
# if nonzero, the target application for which a conversation is requested
|
||||||
lparam_high = lParam >> 16 # if nonzero, the topic of said conversation
|
lparam_low = lParam & 0xFFFF # type: ignore
|
||||||
|
# if nonzero, the topic of said conversation
|
||||||
|
lparam_high = lParam >> 16 # type: ignore
|
||||||
|
|
||||||
# if either of the words are nonzero, they contain
|
# if either of the words are nonzero, they contain
|
||||||
# atoms https://docs.microsoft.com/en-us/windows/win32/dataxchg/about-atom-tables
|
# atoms https://docs.microsoft.com/en-us/windows/win32/dataxchg/about-atom-tables
|
||||||
@ -237,7 +238,10 @@ elif (config.auth_force_edmc_protocol
|
|||||||
wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtomW(appname), GlobalAddAtomW('System'))
|
wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtomW(appname), GlobalAddAtomW('System'))
|
||||||
)
|
)
|
||||||
|
|
||||||
return 0
|
# It works as a constructor as per <https://docs.python.org/3/library/ctypes.html#fundamental-data-types>
|
||||||
|
return c_long(0)
|
||||||
|
|
||||||
|
return c_long(1) # This is an utter guess -Ath
|
||||||
|
|
||||||
class WindowsProtocolHandler(GenericProtocolHandler):
|
class WindowsProtocolHandler(GenericProtocolHandler):
|
||||||
"""
|
"""
|
||||||
@ -350,7 +354,7 @@ else: # Linux / Run from source
|
|||||||
|
|
||||||
self.thread: Optional[threading.Thread] = None
|
self.thread: Optional[threading.Thread] = None
|
||||||
|
|
||||||
def start(self, master) -> None:
|
def start(self, master: 'tkinter.Tk') -> None:
|
||||||
"""Start the HTTP server thread."""
|
"""Start the HTTP server thread."""
|
||||||
GenericProtocolHandler.start(self, master)
|
GenericProtocolHandler.start(self, master)
|
||||||
self.thread = threading.Thread(target=self.worker, name='OAuth worker')
|
self.thread = threading.Thread(target=self.worker, name='OAuth worker')
|
||||||
@ -412,7 +416,7 @@ else: # Linux / Run from source
|
|||||||
else:
|
else:
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
||||||
def log_request(self, code, size=None):
|
def log_request(self, code: int | str = '-', size: int | str = '-') -> None:
|
||||||
"""Override to prevent logging."""
|
"""Override to prevent logging."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user