mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-01 08:01:22 +03:00
Autoformatted code
This commit is contained in:
parent
64f090487e
commit
47d5dce6fe
137
protocol.py
137
protocol.py
@ -51,7 +51,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False):
|
|||||||
|
|
||||||
class ProtocolHandler(GenericProtocolHandler):
|
class ProtocolHandler(GenericProtocolHandler):
|
||||||
|
|
||||||
POLL = 100 # ms
|
POLL = 100 # ms
|
||||||
|
|
||||||
def start(self, master):
|
def start(self, master):
|
||||||
GenericProtocolHandler.start(self, master)
|
GenericProtocolHandler.start(self, master)
|
||||||
@ -68,84 +68,92 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False):
|
|||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self = objc.super(EventHandler, self).init()
|
self = objc.super(EventHandler, self).init()
|
||||||
NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_(self, 'handleEvent:withReplyEvent:', kInternetEventClass, kAEGetURL)
|
NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_(
|
||||||
|
self,
|
||||||
|
'handleEvent:withReplyEvent:',
|
||||||
|
kInternetEventClass,
|
||||||
|
kAEGetURL
|
||||||
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def handleEvent_withReplyEvent_(self, event, replyEvent):
|
def handleEvent_withReplyEvent_(self, event, replyEvent):
|
||||||
protocolhandler.lasturl = urllib.parse.unquote(event.paramDescriptorForKeyword_(keyDirectObject).stringValue()).strip()
|
protocolhandler.lasturl = urllib.parse.unquote(
|
||||||
|
event.paramDescriptorForKeyword_(keyDirectObject).stringValue()).strip()
|
||||||
protocolhandler.master.after(ProtocolHandler.POLL, protocolhandler.poll)
|
protocolhandler.master.after(ProtocolHandler.POLL, protocolhandler.poll)
|
||||||
|
|
||||||
|
|
||||||
elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver:
|
elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver:
|
||||||
|
|
||||||
class WNDCLASS(Structure):
|
class WNDCLASS(Structure):
|
||||||
_fields_ = [('style', UINT),
|
_fields_ = [
|
||||||
('lpfnWndProc', WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)),
|
('style', UINT),
|
||||||
('cbClsExtra', INT),
|
('lpfnWndProc', WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)),
|
||||||
('cbWndExtra', INT),
|
('cbClsExtra', INT),
|
||||||
('hInstance', HINSTANCE),
|
('cbWndExtra', INT),
|
||||||
('hIcon', HICON),
|
('hInstance', HINSTANCE),
|
||||||
('hCursor', c_void_p),
|
('hIcon', HICON),
|
||||||
('hbrBackground', HBRUSH),
|
('hCursor', c_void_p),
|
||||||
('lpszMenuName', LPCWSTR),
|
('hbrBackground', HBRUSH),
|
||||||
('lpszClassName', LPCWSTR)
|
('lpszMenuName', LPCWSTR),
|
||||||
|
('lpszClassName', LPCWSTR)
|
||||||
]
|
]
|
||||||
|
|
||||||
CW_USEDEFAULT = 0x80000000
|
CW_USEDEFAULT = 0x80000000
|
||||||
|
|
||||||
CreateWindowEx = windll.user32.CreateWindowExW
|
CreateWindowEx = windll.user32.CreateWindowExW
|
||||||
CreateWindowEx.argtypes = [DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID]
|
CreateWindowEx.argtypes = [DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID]
|
||||||
CreateWindowEx.restype = HWND
|
CreateWindowEx.restype = HWND
|
||||||
RegisterClass = windll.user32.RegisterClassW
|
RegisterClass = windll.user32.RegisterClassW
|
||||||
RegisterClass.argtypes = [POINTER(WNDCLASS)]
|
RegisterClass.argtypes = [POINTER(WNDCLASS)]
|
||||||
DefWindowProc = windll.user32.DefWindowProcW
|
DefWindowProc = windll.user32.DefWindowProcW
|
||||||
GetParent = windll.user32.GetParent
|
GetParent = windll.user32.GetParent
|
||||||
SetForegroundWindow = windll.user32.SetForegroundWindow
|
SetForegroundWindow = windll.user32.SetForegroundWindow
|
||||||
|
|
||||||
GetMessage = windll.user32.GetMessageW
|
GetMessage = windll.user32.GetMessageW
|
||||||
TranslateMessage = windll.user32.TranslateMessage
|
TranslateMessage = windll.user32.TranslateMessage
|
||||||
DispatchMessage = windll.user32.DispatchMessageW
|
DispatchMessage = windll.user32.DispatchMessageW
|
||||||
PostThreadMessage = windll.user32.PostThreadMessageW
|
PostThreadMessage = windll.user32.PostThreadMessageW
|
||||||
SendMessage = windll.user32.SendMessageW
|
SendMessage = windll.user32.SendMessageW
|
||||||
SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
|
SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
|
||||||
PostMessage = windll.user32.PostMessageW
|
PostMessage = windll.user32.PostMessageW
|
||||||
PostMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
|
PostMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
|
||||||
|
|
||||||
WM_QUIT = 0x0012
|
WM_QUIT = 0x0012
|
||||||
WM_DDE_INITIATE = 0x03E0
|
WM_DDE_INITIATE = 0x03E0
|
||||||
WM_DDE_TERMINATE = 0x03E1
|
WM_DDE_TERMINATE = 0x03E1
|
||||||
WM_DDE_ACK = 0x03E4
|
WM_DDE_ACK = 0x03E4
|
||||||
WM_DDE_EXECUTE = 0x03E8
|
WM_DDE_EXECUTE = 0x03E8
|
||||||
|
|
||||||
PackDDElParam = windll.user32.PackDDElParam
|
PackDDElParam = windll.user32.PackDDElParam
|
||||||
PackDDElParam.argtypes = [UINT, LPARAM, LPARAM]
|
PackDDElParam.argtypes = [UINT, LPARAM, LPARAM]
|
||||||
|
|
||||||
GlobalAddAtom = windll.kernel32.GlobalAddAtomW
|
GlobalAddAtom = windll.kernel32.GlobalAddAtomW
|
||||||
GlobalAddAtom.argtypes = [LPWSTR]
|
GlobalAddAtom.argtypes = [LPWSTR]
|
||||||
GlobalAddAtom.restype = ATOM
|
GlobalAddAtom.restype = ATOM
|
||||||
GlobalGetAtomName = windll.kernel32.GlobalGetAtomNameW
|
GlobalGetAtomName = windll.kernel32.GlobalGetAtomNameW
|
||||||
GlobalGetAtomName.argtypes = [ATOM, LPWSTR, INT]
|
GlobalGetAtomName.argtypes = [ATOM, LPWSTR, INT]
|
||||||
GlobalGetAtomName.restype = UINT
|
GlobalGetAtomName.restype = UINT
|
||||||
GlobalLock = windll.kernel32.GlobalLock
|
GlobalLock = windll.kernel32.GlobalLock
|
||||||
GlobalLock.argtypes = [HGLOBAL]
|
GlobalLock.argtypes = [HGLOBAL]
|
||||||
GlobalLock.restype = LPVOID
|
GlobalLock.restype = LPVOID
|
||||||
GlobalUnlock = windll.kernel32.GlobalUnlock
|
GlobalUnlock = windll.kernel32.GlobalUnlock
|
||||||
GlobalUnlock.argtypes = [HGLOBAL]
|
GlobalUnlock.argtypes = [HGLOBAL]
|
||||||
GlobalUnlock.restype = BOOL
|
GlobalUnlock.restype = BOOL
|
||||||
|
|
||||||
|
|
||||||
@WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)
|
@WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)
|
||||||
def WndProc(hwnd, message, wParam, lParam):
|
def WndProc(hwnd, message, wParam, lParam):
|
||||||
service = create_unicode_buffer(256)
|
service = create_unicode_buffer(256)
|
||||||
topic = create_unicode_buffer(256)
|
topic = create_unicode_buffer(256)
|
||||||
if message == WM_DDE_INITIATE:
|
if message == WM_DDE_INITIATE:
|
||||||
if ((lParam & 0xffff == 0 or (GlobalGetAtomName(lParam & 0xffff, service, 256) and service.value == appname)) and
|
if (
|
||||||
(lParam >> 16 == 0 or (GlobalGetAtomName(lParam >> 16, topic, 256) and topic.value.lower() == 'system'))):
|
(lParam & 0xffff == 0 or (GlobalGetAtomName(lParam & 0xffff, service, 256) and service.value == appname)) and
|
||||||
SendMessage(wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System')))
|
(lParam >> 16 == 0 or (GlobalGetAtomName(lParam >> 16, topic, 256) and topic.value.lower() == 'system'))
|
||||||
|
):
|
||||||
|
SendMessage(wParam, WM_DDE_ACK, hwnd, PackDDElParam(
|
||||||
|
WM_DDE_ACK, GlobalAddAtom(appname), GlobalAddAtom('System')))
|
||||||
return 0
|
return 0
|
||||||
return DefWindowProc(hwnd, message, wParam, lParam)
|
return DefWindowProc(hwnd, message, wParam, lParam)
|
||||||
|
|
||||||
|
|
||||||
class ProtocolHandler(GenericProtocolHandler):
|
class ProtocolHandler(GenericProtocolHandler):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -163,31 +171,33 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a
|
|||||||
if thread:
|
if thread:
|
||||||
self.thread = None
|
self.thread = None
|
||||||
PostThreadMessage(thread.ident, WM_QUIT, 0, 0)
|
PostThreadMessage(thread.ident, WM_QUIT, 0, 0)
|
||||||
thread.join() # Wait for it to quit
|
thread.join() # Wait for it to quit
|
||||||
|
|
||||||
def worker(self):
|
def worker(self):
|
||||||
wndclass = WNDCLASS()
|
wndclass = WNDCLASS()
|
||||||
wndclass.style = 0
|
wndclass.style = 0
|
||||||
wndclass.lpfnWndProc = WndProc
|
wndclass.lpfnWndProc = WndProc
|
||||||
wndclass.cbClsExtra = 0
|
wndclass.cbClsExtra = 0
|
||||||
wndclass.cbWndExtra = 0
|
wndclass.cbWndExtra = 0
|
||||||
wndclass.hInstance = windll.kernel32.GetModuleHandleW(0)
|
wndclass.hInstance = windll.kernel32.GetModuleHandleW(0)
|
||||||
wndclass.hIcon = None
|
wndclass.hIcon = None
|
||||||
wndclass.hCursor = None
|
wndclass.hCursor = None
|
||||||
wndclass.hbrBackground = None
|
wndclass.hbrBackground = None
|
||||||
wndclass.lpszMenuName = None
|
wndclass.lpszMenuName = None
|
||||||
wndclass.lpszClassName = 'DDEServer'
|
wndclass.lpszClassName = 'DDEServer'
|
||||||
|
|
||||||
if RegisterClass(byref(wndclass)):
|
if RegisterClass(byref(wndclass)):
|
||||||
hwnd = CreateWindowEx(0,
|
hwnd = CreateWindowEx(
|
||||||
wndclass.lpszClassName,
|
0,
|
||||||
"DDE Server",
|
wndclass.lpszClassName,
|
||||||
0,
|
"DDE Server",
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
0,
|
||||||
self.master.winfo_id(), # Don't use HWND_MESSAGE since the window won't get DDE broadcasts
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
None,
|
self.master.winfo_id(), # Don't use HWND_MESSAGE since the window won't get DDE broadcasts
|
||||||
wndclass.hInstance,
|
None,
|
||||||
None)
|
wndclass.hInstance,
|
||||||
|
None
|
||||||
|
)
|
||||||
msg = MSG()
|
msg = MSG()
|
||||||
while GetMessage(byref(msg), None, 0, 0) != 0:
|
while GetMessage(byref(msg), None, 0, 0) != 0:
|
||||||
logger.trace(f'DDE message of type: {msg.message}')
|
logger.trace(f'DDE message of type: {msg.message}')
|
||||||
@ -201,7 +211,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a
|
|||||||
if url.startswith(self.redirect):
|
if url.startswith(self.redirect):
|
||||||
logger.debug(f'Message starts with {self.redirect}')
|
logger.debug(f'Message starts with {self.redirect}')
|
||||||
self.event(url)
|
self.event(url)
|
||||||
SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window
|
SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window
|
||||||
PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam))
|
PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam))
|
||||||
else:
|
else:
|
||||||
PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam))
|
PostMessage(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam))
|
||||||
@ -213,7 +223,7 @@ elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine a
|
|||||||
else:
|
else:
|
||||||
print('Failed to register DDE for cAPI')
|
print('Failed to register DDE for cAPI')
|
||||||
|
|
||||||
else: # Linux / Run from source
|
else: # Linux / Run from source
|
||||||
|
|
||||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
|
|
||||||
@ -264,7 +274,7 @@ else: # Linux / Run from source
|
|||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
self.send_response(404) # Not found
|
self.send_response(404) # Not found
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def do_HEAD(self):
|
def do_HEAD(self):
|
||||||
@ -275,7 +285,8 @@ else: # Linux / Run from source
|
|||||||
if self.parse():
|
if self.parse():
|
||||||
self.send_header('Content-Type', 'text/html')
|
self.send_header('Content-Type', 'text/html')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write('<html><head><title>{}</title></head>'.format('Authentication successful').encode('utf-8'))
|
self.wfile.write(
|
||||||
|
'<html><head><title>{}</title></head>'.format('Authentication successful').encode('utf-8'))
|
||||||
self.wfile.write('<body><p>{}</p></body>'.format('Authentication successful').encode('utf-8'))
|
self.wfile.write('<body><p>{}</p></body>'.format('Authentication successful').encode('utf-8'))
|
||||||
else:
|
else:
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user