def __call__(self, host, uri="/", method="GET", body=None, timeout=0, ssl=False, sslVerify=True, parseBody=False): if not uri: uri = "/" if not timeout: timeout = None host = eg.ParseString(host) uri = eg.ParseString(uri) if isinstance(method, Number): method = self.methods[method] if method not in self.methods: raise ValueError("Invalid request method") if method not in self.body_methods: body = None if body is not None and parseBody: body = eg.ParseString(body) ret_val = requests.request(method, "{}://{}{}".format("https" if ssl else "http", host, uri), verify=sslVerify, timeout=timeout, data=body, stream=False) ret_val.close() return ret_val
def __call__(self, title="", body="", alias="", payload="", blocking=False, options=0, mbType=0, autoClose=0): title = eg.ParseString(title) body = eg.ParseString(body) alias = eg.ParseString(alias) payload = eg.ParseString(payload) if not isinstance(autoClose, int): try: autoClose = int(eg.ParseString(autoClose)) except: autoClose = 0 if mbType: event = CreateEvent(None, 0, 0, None) if blocking else None wx.CallAfter(self.showTweakedBox, None, title, body, alias, payload, options, autoClose, event) if blocking: #print "Waiting ..." eg.actionThread.WaitOnEvent(event, 999999999999) return self.retCode else: if blocking: return self.showMessageBox(title, body, alias, payload, options) else: Thread(target=self.showMessageBox, args=(title, body, alias, payload, options)).start() return None
def __call__(self, destIP, destPort, passwd, data): if destIP == "": eg.PrintError("Destination address field is blank") self.host = eg.ParseString(destIP) self.port = destPort self.password = eg.ParseString(passwd) self.data = data return self.Send()
def bcastSend(self, eventString, payload=""): addr = (self.plugin.zone, self.plugin.port) UDPSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Create socket UDPSock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) if (payload==None): UDPSock.sendto(eg.ParseString(eventString),addr) else: UDPSock.sendto(eg.ParseString(eventString)+self.plugin.payDelim+eg.ParseString(payload),addr) UDPSock.close()
def __call__(self, button, host=False, port=False, pswd=False): for CommandGroup in ACTION: for Command in CommandGroup[4]: if button == Command[4][0]: return self.plugin.Send(eg.ParseString("EG+BtnSnd"), eg.ParseString(Command[4][0]), eg.ParseString(""), Command[4][1], eg.ParseString(""), host, port, pswd)
def __call__(self, name="", file=""): id = self.plugin.GetId(eg.ParseString(name)) file = eg.ParseString(file) if self.plugin.GetConnection(): try: req = "/?action=playlist_add_file&playlist=%s" % id req += '&file=%s' % quote(file) self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return True except: raise
def __call__(self, header, firstline, secondline, timeout, imagelocation, host=False, port=False, pswd=False): return self.plugin.Send(eg.ParseString(header), eg.ParseString(firstline), eg.ParseString(secondline), timeout, eg.ParseString(imagelocation), host, port, pswd)
def __call__(self, name="", pos=1): self.plugin.GetId("Chuck") id = self.plugin.GetId(eg.ParseString(name)) pos = pos if isinstance(pos, int) else int(eg.ParseString(pos)) pos = str(pos - 1) if self.plugin.GetConnection(): try: req = "/?action=%s&playlist=%s" % (self.__class__.__name__, id) req += "&%s=%s" % (self.value, pos) self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return True except: raise
def __call__(self, data=""): data = eg.ParseString(data) data = data.decode("string_escape") global_serial_thread.Write(str(data)) return global_serial_thread
def __call__(self, key, subkey, valueName, action, keyType, newValue, disableParsing=False): if not disableParsing: newValue = eg.ParseString(newValue) if not key: self.PrintError(self.text2.noKeyError) return 0 if not subkey: self.PrintError(self.text2.noSubkeyError) return 0 if not valueName: self.PrintError(self.text2.noValueNameError) return 0 #try to get handle try: if action == 0: regHandle = _winreg.CreateKey(key, subkey) else: regHandle = _winreg.OpenKey( key, subkey, 0, _winreg.KEY_WRITE | _winreg.KEY_READ) except EnvironmentError, exc: if action != 1: eg.PrintError(self.text2.keyOpenError + ": " + str(exc)) return 0
def parseArgument(self, arg): if not arg: return 0 if isinstance(arg, int): return arg else: return eg.ParseString(arg)
def __call__(self, Command): Command = eg.ParseString(Command) message = '!' + str(self.plugin.unittype) + Command + '\x0d' # unlike specified the datasize needs to include the headersize # to make it work for some models (Integra DHC-9.9) # while others (Onkyo PR-SC5507) work fine without it # both work when the headersize is included datasize = self.plugin.headersize + len(message) line = pack('!4sIIBxxx', self.plugin.header, self.plugin.headersize, datasize, self.plugin.version ) + message try: self.plugin.socket.sendall(line) sleep(0.1) except socket.error, msg: self.PrintError("OnkyoISCP: Error sending command, retrying: " + str(msg)) # try to reopen the socket on error # happens if no commands are sent for a long time # and the tcp connection got closed because # e.g. the receiver was switched off and on again self.plugin.Connect() try: self.plugin.socket.sendall(line) except socket.error, msg: self.PrintError("OnkyoISCP: Error sending command: " + str(msg))
def __call__(self, data): data = eg.ParseString(data) data = data.upper() print(self.cmd + str(data)) self.plugin.serialThread.SuspendReadEvents() self.plugin.serialThread.Write(self.cmd + chr(13)) self.plugin.serialThread.ResumeReadEvents()
def __call__(self, voice, rate, voiceText, suffix, volume, audio=None): def filterFunc(s): formatString = '</context><context ID = "%s">%s</context><context>' if s == "DATE": return formatString % ('date_mdy', strftime("%m/%d/%Y")) elif s == "DATE1": return formatString % ('date_mdy', strftime("%m/%d/%y")) elif s == "TIME": return formatString % ('time', strftime("%H:%M:%S")) elif s == "TIME1": return formatString % ('time', strftime("%H:%M")) else: return None voiceText = eg.ParseString(voiceText, filterFunc) voiceText = "<context>%s</context>" % voiceText if voiceText.startswith('<context></context>'): voiceText = voiceText[19:] voiceText = voiceText.replace( '</context><context></context>', '</context>' ) self.plugin.AddThread(voice, rate, voiceText, suffix, volume, audio)
def __call__( self, osdText="", fontInfo=None, foregroundColour=(255, 255, 255), backgroundColour=(0, 0, 0), alignment=0, offset=(0, 0), displayNumber=0, timeout=3.0, skin=None ): if isinstance(skin, bool): skin = SKINS[0] if skin else None self.osdFrame.timer.cancel() osdText = eg.ParseString(osdText) event = CreateEvent(None, 0, 0, None) wx.CallAfter( self.osdFrame.ShowOSD, osdText, fontInfo, foregroundColour, backgroundColour, alignment, offset, displayNumber, timeout, event, skin ) eg.actionThread.WaitOnEvent(event)
def __call__(self, line=1, txt=""): line = self.plugin.parseArgument(line) - 1 txt = eg.ParseString(txt) if line < self.plugin.rows: return self.plugin.PrintCommand(line, txt[:64]) else: eg.PrintError( "XXXXXXXXXXXXXXXXXXX BAD LINE XXXXXXXXXXXXXXXXXXXXXXXXXX")
def __call__(self, name="", old=1, new=1): id = self.plugin.GetId(eg.ParseString(name)) old = old if isinstance(old, int) else int(eg.ParseString(old)) old = str(old - 1) new = new if isinstance(new, int) else int(eg.ParseString(new)) new = str(new - 1) if self.plugin.GetConnection(): try: req = "/?action=set_song_position&playlist=%s" % id req += "&song=%s" % old req += "&position=%s" % new self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return True except: raise
def __call__(self, destIP, destPort, passwd, dataName, dataToEval, data): if destIP == "": eg.PrintError("Destination address field is blank") self.host = eg.ParseString(destIP) self.port = destPort self.password = eg.ParseString(passwd) self.dataName = eg.ParseString(dataName) if (dataToEval is not None) and (dataToEval != ""): try: self.data = eval(dataToEval) except: eg.PrintError("Error evaluating " + str(dataToEval) + ". Sending None to the server.") self.data = None else: self.data = data return self.Send()
def __call__(self, name="", offs=0, size=0): id = self.plugin.GetId(eg.ParseString(name)) offs = str(offs) if isinstance(offs, int) else eg.ParseString(offs) size = str(size) if isinstance(size, int) else eg.ParseString(size) if self.plugin.GetConnection(): try: req = "/?action=get_playlist_songs&id=%s" % id if offs != "0": req += "&offset=%s" % offs if size != "0": req += "&size=%s" % size self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return loads(res.read()) except: raise
def __call__(self, data): data = eg.ParseString(data) data = data.upper() ChannelNo = hex(int(data))[2:].zfill(4) self.plugin.serialThread.SuspendReadEvents() print(elf.cmd + ' ' + ChannelNo[0:2] + ' ' + ChannelNo[2:4] + ' 10') self.plugin.serialThread.Write(self.cmd + ' ' + ChannelNo[0:2] + ' ' + ChannelNo[2:4] + ' 10' + chr(13)) self.plugin.serialThread.ResumeReadEvents()
def bcastSend(self, eventString, payload="", port=0): if (port==None): sendToPort=self.plugin.port else: sendToPort=int(port) addr = (self.plugin.zone, sendToPort) UDPSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Create socket UDPSock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) if (payload==None): UDPSock.sendto(eg.ParseString(eventString).encode(eg.systemEncoding),addr) else: bits = payload.split(self.plugin.payDelim); bits = [eg.ParseString(bit) for bit in bits]; payload = self.plugin.payDelim.join(bits).encode(eg.systemEncoding); UDPSock.sendto(eg.ParseString(eventString).encode(eg.systemEncoding) + self.plugin.payDelim.encode(eg.systemEncoding) + payload,addr) UDPSock.close()
def __call__(self, vol=0): vol = str(vol) if isinstance(vol, int) else eg.ParseString(vol) if self.plugin.GetConnection(): try: req = "/?action=set_volume&volume=%s" % vol self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return True except: raise
def on_data_change(event): try: temp = eg.ParseString(data_ctrl.GetValue()) temp = temp.strip() result_preview_ctrl.SetLabel(temp) panel.EnableButtons(True) except BaseException: result_preview_ctrl.SetLabel(text.parse_string_error) panel.EnableButtons(False) event.Skip()
def __call__(self, destIP, destPort, passwd, evtPref, evtSuf, evtPayloadStr, evtPayload): if destIP == "": eg.PrintError("Destination address field left blank.") self.host = eg.ParseString(destIP) self.port = destPort self.password = eg.ParseString(passwd) self.eventPrefix = eg.ParseString(evtPref) self.eventSuffix = eg.ParseString(evtSuf) if (evtPayloadStr is not None) and (evtPayloadStr != ""): try: self.eventPayload = eval(evtPayloadStr) except: eg.PrintError( "Unable to evaluate the payload. Payload must be a valid python expression(example: \"some\\\"Text\\\"\"). Your string will be sent unevaluated." ) self.eventPayload = evtPayloadStr else: self.eventPayload = evtPayload return self.Send()
def __call__(self, pos=0): pos = str(pos) if isinstance(pos, int) else eg.ParseString(pos) if self.plugin.GetConnection(): try: req = "/?action=set_track_position&position=%s" % pos self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return True except: raise
def __call__(self, name=""): id = self.plugin.GetId(eg.ParseString(name)) if self.plugin.GetConnection(): try: req = "/?action=get_playlist_crc&id=%s" % id self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return res.read() except: raise
def parse(value): if value is None: return None parsed_value = eg.ParseString(value) if value == parsed_value: try: value = eval(value) except (SyntaxError, NameError): pass else: value = parsed_value return value
def __call__(self, name="", typ=0): tps = ( "title", "filename", "duration", "artist", "inverse", "randomize", ) id = self.plugin.GetId(eg.ParseString(name)) typ = typ if isinstance(typ, int) else int(eg.ParseString(typ)) if self.plugin.GetConnection(): try: req = "/?action=playlist_sort&playlist=%s" % id req += "&sort=%s" % str(tps[typ]) self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return True except: raise
def bcastSend(self, eventString, payload=None): #log("bcastSend: " + self.plugin.zone + ":" + self.plugin.udpport,eventString) addr = (self.plugin.zone, self.plugin.udpport) UDPSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Create socket UDPSock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) #if (payload==None): UDPSock.sendto(eg.ParseString(eventString), addr) #else: # UDPSock.sendto(eg.ParseString(eventString)+self.plugin.payDelim+eg.ParseString(payload),addr) log("sent") UDPSock.close()
def __call__(self, stat="", value=0): value = str(value) if isinstance(value, int) else eg.ParseString(value) if self.plugin.GetConnection(): try: stat = str(STATUSES[stat]) req = "/?action=set_custom_status&status=%s" % stat req += "&value=%s" % value self.plugin.con.request("GET", req) res = self.plugin.con.getresponse() if res.status == 200: return True except: raise