MCPcopy
hub / github.com/RUB-NDS/PRET / cmd

Method cmd

pjl.py:19–56  ·  view source on GitHub ↗
(self, str_send, wait=True, crop=True, binary=False)

Source from the content-addressed store, hash-verified

17 # --------------------------------------------------------------------
18 # send PJL command to printer, optionally receive response
19 def cmd(self, str_send, wait=True, crop=True, binary=False):
20 str_recv = "" # response buffer
21 str_stat = "" # status buffer
22 token = c.DELIMITER + str(random.randrange(2**16)) # unique delimiter
23 status = "@PJL INFO STATUS" + c.EOL if self.status and wait else ""
24 footer = "@PJL ECHO " + token + c.EOL + c.EOL if wait else ""
25 # send command to printer device
26 try:
27 cmd_send = c.UEL + str_send + c.EOL + status + footer + c.UEL
28 # write to logfile
29 log().write(self.logfile, str_send + os.linesep)
30 # sent to printer
31 self.send(cmd_send)
32 # for commands that expect a response
33 if wait:
34 # use random token as delimiter PJL responses
35 str_recv = self.recv(
36 "(@PJL ECHO\s+)?" + token + ".*$", wait, True, binary
37 )
38 if self.status:
39 # get status messages and remove them from received buffer
40 str_stat = item(
41 re.findall("@PJL INFO STATUS.*", str_recv, re.DOTALL)
42 )
43 str_recv = re.compile("\x0c?@PJL INFO STATUS.*", re.DOTALL).sub(
44 "", str_recv
45 )
46 if crop:
47 # crop very first PJL line which is echoed by most interpreters
48 str_recv = re.sub(
49 r"^\x04?(\x00+)?@PJL.*" + c.EOL, "", str_recv)
50 return self.pjl_err(str_recv, str_stat)
51
52 # handle CTRL+C and exceptions
53 except (KeyboardInterrupt, Exception) as e:
54 if not self.fuzz or not str(e):
55 self.reconnect(str(e))
56 return ""
57
58 # handle error messages from PJL interpreter
59 def pjl_err(self, str_recv, str_stat):

Callers 15

on_connectMethod · 0.95
vol_existsMethod · 0.95
dir_existsMethod · 0.95
file_existsMethod · 0.95
dirlistMethod · 0.95
do_mkdirMethod · 0.95
getMethod · 0.95
putMethod · 0.95
appendMethod · 0.95
deleteMethod · 0.95
do_infoMethod · 0.95
do_printenvMethod · 0.95

Calls 7

pjl_errMethod · 0.95
logClass · 0.90
itemFunction · 0.90
reconnectMethod · 0.80
writeMethod · 0.45
sendMethod · 0.45
recvMethod · 0.45

Tested by

no test coverage detected