115
115
@todo: investigate possible security issues
118
def __init__(self, app, key):
118
def __init__(self, app, key, port=EDPORT):
119
119
"""Create the server thread
120
120
@param app: Application object the server belongs to
121
121
@param key: Unique user authentication key (string)
122
@keyword port: TCP port to attempt to connect to
124
threading.Thread.__init__(self)
125
super(EdIpcServer, self).__init__()
127
128
self._exit = False
172
174
# If message key is correct and the message is ended, process
173
175
# the input and dispatch to the app.
174
176
if recieved.startswith(self.__key) and recieved.endswith(MSGEND):
175
recieved = recieved.replace(self.__key, u'', 1)
178
recieved = recieved.replace(self.__key, '', 1)
179
# Strip the end token
180
xmlstr = recieved.rstrip(MSGEND).strip(";")
178
183
exml = IPCCommand()
180
xmlstr = recieved.rstrip(MSGEND).strip(u";")
181
exml.LoadFromString(xmlstr)
185
# Well formed xml must be utf-8 string not unicode
186
xmlstr = xmlstr.encode('utf-8')
187
exml = IPCCommand.parse(xmlstr)
182
188
except Exception, msg:
183
# ignore parsing errors
189
# Log and ignore parsing errors
190
logmsg = "[ed_ipc][err] Parsing failed: %s\n" % msg
191
xmlstr = xmlstr.replace('\n', '').strip()
192
logmsg += "Bad xml was: %s" % repr(xmlstr)
186
196
evt = IpcServerEvent(edEVT_COMMAND_RECV, wx.ID_ANY, exml)
232
242
#-----------------------------------------------------------------------------#
233
243
# Command Serialization
235
class IPCCommand(syntax.EditraXml):
236
"""Xml packet used for sending data to remote process through ipc"""
238
syntax.EditraXml.__init__(self)
241
self._files = IPCFileList()
242
self._args = IPCArgList()
245
self.SetName(EDXML_IPC)
246
self.RegisterHandler(self._files)
247
self.RegisterHandler(self._args)
249
#---- Public Api ----#
252
"""Get the list of paths
253
@return: list of tuples
256
return self._args.GetArgs()
258
def SetArgs(self, args):
260
@param flist: list of strings
263
self._args.SetArgs(args)
266
"""Get the list of paths
267
@return: list of strings
270
return self._files.GetFiles()
272
def SetFiles(self, flist):
274
@param flist: list of strings
277
self._files.SetFiles(flist)
279
class IPCFileList(syntax.EditraXml):
245
class IPCFile(ed_xml.EdXml):
280
246
"""Xml object for holding the list of files
283
<file value="/path/to/file"/>
247
<file value="/path/to/file"/>
288
syntax.EditraXml.__init__(self)
294
self.SetName(EDXML_FILELIST)
296
#---- Xml Implementation ----#
298
def startElement(self, name, attrs):
299
"""Collect all the file elements"""
300
if name == EDXML_FILE:
301
fname = attrs.get(syntax.EXML_VALUE, None)
302
if fname is not None:
303
self._files.append(fname)
305
def GetSubElements(self):
306
"""Get the objects subelements"""
308
tmp = u"<%s %s=\"" % (EDXML_FILE, syntax.EXML_VALUE)
310
for fname in self._files:
311
if not ebmlib.IsUnicode(fname):
312
fname = fname.decode(sys.getfilesystemencoding())
313
xmlstr += tmp % fname
316
#--- public api ----#
319
"""Get the list of paths
320
@return: list of strings
325
def SetFiles(self, flist):
326
"""Set the list of files
327
@param flist: list of strings
332
class IPCArgList(syntax.EditraXml):
252
value = ed_xml.String(required=True)
254
class IPCArg(ed_xml.EdXml):
333
255
"""Xml object for holding the list of args
336
256
<arg name="test" value="x"/>
341
syntax.EditraXml.__init__(self)
347
self.SetName(EDXML_ARGLIST)
349
#---- Xml Implementation ----#
351
def startElement(self, name, attrs):
352
"""Collect all the file elements"""
353
if name == EDXML_ARG:
354
arg = attrs.get(syntax.EXML_NAME, None)
355
val = attrs.get(syntax.EXML_VALUE, u'')
356
if not val.isdigit():
361
self._args.append((arg, val))
363
def GetSubElements(self):
364
"""Get the objects sub-elements"""
366
tmp = u"<%s %s=\"" % (EDXML_ARG, syntax.EXML_NAME)
368
tmp += "%s=\"" % syntax.EXML_VALUE
370
for argval in self._args:
371
xmlstr += tmp % argval
374
#--- public api ----#
377
"""Get the list of arguments (command line switches)
378
@return: list of tuples
383
def SetArgs(self, args):
384
"""Set the list of files
385
@param flist: list of tuples
b'\\ No newline at end of file'
261
name = ed_xml.String(required=True)
262
value = ed_xml.String(required=True)
264
class IPCCommand(ed_xml.EdXml):
265
"""IPC XML Command"""
268
filelist = ed_xml.List(ed_xml.Model(IPCFile))
269
arglist = ed_xml.List(ed_xml.Model(IPCArg))