10 import json |
10 import json |
11 |
11 |
12 from PyQt6.QtCore import pyqtSignal, pyqtSlot |
12 from PyQt6.QtCore import pyqtSignal, pyqtSlot |
13 from PyQt6.QtNetwork import QHostAddress, QTcpServer |
13 from PyQt6.QtNetwork import QHostAddress, QTcpServer |
14 |
14 |
15 from eric7 import Preferences, Utilities |
15 from eric7 import EricUtilities |
16 from eric7.EricWidgets import EricMessageBox |
16 from eric7.EricWidgets import EricMessageBox |
17 |
17 |
18 |
18 |
19 class EricJsonReader(QTcpServer): |
19 class EricJsonReader(QTcpServer): |
20 """ |
20 """ |
26 @signal dataReceived(object) emitted after a data object was received |
26 @signal dataReceived(object) emitted after a data object was received |
27 """ |
27 """ |
28 |
28 |
29 dataReceived = pyqtSignal(object) |
29 dataReceived = pyqtSignal(object) |
30 |
30 |
31 def __init__(self, name="", ip=None, parent=None): |
31 def __init__(self, name="", interface="127.0.0.1", parent=None): |
32 """ |
32 """ |
33 Constructor |
33 Constructor |
34 |
34 |
35 @param name name of the server (used for output only) |
35 @param name name of the server (used for output only) (defaults to "") |
36 @type str |
36 @type str (optional) |
37 @param ip IP address to listen at |
37 @param interface network interface to be used (IP address or one of "all", |
38 @type str |
38 "allv4", "allv6", "localv4" or "localv6") (defaults to "127.0.0.1") |
39 @param parent parent object |
39 @type str (optional) |
40 @type QObject |
40 @param parent reference to the parent object (defaults to None) |
|
41 @type QObject (optional) |
41 """ |
42 """ |
42 super().__init__(parent) |
43 super().__init__(parent) |
43 |
44 |
44 self.__name = name |
45 self.__name = name |
45 self.__connection = None |
46 self.__connection = None |
46 |
47 |
47 # setup the network interface |
48 # setup the network interface |
48 if ip is None: |
49 if interface in ("allv4", "localv4") or "." in interface: |
49 networkInterface = Preferences.getDebugger("NetworkInterface") |
50 # IPv4 |
50 if networkInterface in ("allv4", "localv4") or "." in networkInterface: |
51 self.__hostAddress = "127.0.0.1" |
51 # IPv4 |
52 elif interface in ("all", "allv6", "localv6"): |
52 self.__hostAddress = "127.0.0.1" |
53 # IPv6 |
53 elif networkInterface in ("all", "allv6", "localv6"): |
54 self.__hostAddress = "::1" |
54 # IPv6 |
|
55 self.__hostAddress = "::1" |
|
56 else: |
|
57 self.__hostAddress = networkInterface |
|
58 else: |
55 else: |
59 self.__hostAddress = ip |
56 self.__hostAddress = interface |
60 self.listen(QHostAddress(self.__hostAddress)) |
57 self.listen(QHostAddress(self.__hostAddress)) |
61 |
58 |
62 self.newConnection.connect(self.handleNewConnection) |
59 self.newConnection.connect(self.handleNewConnection) |
63 |
60 |
64 ## Note: Need the address and port if client is started external in debugger. |
61 ## Note: Need the address and port if client is started external in debugger. |
142 """ could not be decoded. Please report""" |
139 """ could not be decoded. Please report""" |
143 """ this issue with the received data to the""" |
140 """ this issue with the received data to the""" |
144 """ eric bugs email address.</p>""" |
141 """ eric bugs email address.</p>""" |
145 """<p>Error: {0}</p>""" |
142 """<p>Error: {0}</p>""" |
146 """<p>Data:<br/>{1}</p>""" |
143 """<p>Data:<br/>{1}</p>""" |
147 ).format(str(err), Utilities.html_encode(jsonLine.strip())), |
144 ).format(str(err), EricUtilities.html_encode(jsonLine.strip())), |
148 EricMessageBox.Ok, |
145 EricMessageBox.Ok, |
149 ) |
146 ) |
150 return |
147 return |
151 |
148 |
152 self.dataReceived.emit(data) |
149 self.dataReceived.emit(data) |