Mercurial > ~darius > hgwebdir.cgi > pyinst
comparison vxi_11.py @ 56:91b476ebc0f2
Run through 2to3
author | Daniel O'Connor <doconnor@gsoft.com.au> |
---|---|
date | Tue, 08 Dec 2020 14:00:45 +1030 |
parents | cba1c44060f5 |
children |
comparison
equal
deleted
inserted
replaced
55:ad5942d22f78 | 56:91b476ebc0f2 |
---|---|
20 | 20 |
21 connection_dict={} | 21 connection_dict={} |
22 | 22 |
23 def close_all_connections(): | 23 def close_all_connections(): |
24 "disconnect and close out all vxi_11 connections created here, even if their object references have been lost" | 24 "disconnect and close out all vxi_11 connections created here, even if their object references have been lost" |
25 for wobj in connection_dict.keys(): | 25 for wobj in list(connection_dict.keys()): |
26 name, wconn=connection_dict[wobj] | 26 name, wconn=connection_dict[wobj] |
27 conn=wconn() #dereference weak ref | 27 conn=wconn() #dereference weak ref |
28 if conn is not None: | 28 if conn is not None: |
29 try: | 29 try: |
30 conn.disconnect() | 30 conn.disconnect() |
53 "eof": "Cut off packet received in rpc.recvfrag()", | 53 "eof": "Cut off packet received in rpc.recvfrag()", |
54 "sync":"stream sync lost", | 54 "sync":"stream sync lost", |
55 "notconnected": "Device not connected"} | 55 "notconnected": "Device not connected"} |
56 | 56 |
57 def identify_vxi_11_error(self, error): | 57 def identify_vxi_11_error(self, error): |
58 if self.vxi_11_errors.has_key(error): | 58 if error in self.vxi_11_errors: |
59 return `error`+": "+self.vxi_11_errors[error] | 59 return repr(error)+": "+self.vxi_11_errors[error] |
60 else: | 60 else: |
61 return `error`+": Unknown error code" | 61 return repr(error)+": Unknown error code" |
62 | 62 |
63 | 63 |
64 def __init__(self, code, **other_info): | 64 def __init__(self, code, **other_info): |
65 IOError.__init__(self, self.identify_vxi_11_error(code)) | 65 IOError.__init__(self, self.identify_vxi_11_error(code)) |
66 self.code=code | 66 self.code=code |
168 | 168 |
169 def simple_log_error(self, message, level=debug_error, file=None): | 169 def simple_log_error(self, message, level=debug_error, file=None): |
170 if level <= self.debug_level: | 170 if level <= self.debug_level: |
171 if file is None: | 171 if file is None: |
172 file=sys.stderr | 172 file=sys.stderr |
173 print >> file, self.device_name, message | 173 print(self.device_name, message, file=file) |
174 | 174 |
175 def fancy_log_error(self, message, level=debug_error, file=None): | 175 def fancy_log_error(self, message, level=debug_error, file=None): |
176 if level <= self.debug_level: | 176 if level <= self.debug_level: |
177 message=str(message).strip() | 177 message=str(message).strip() |
178 level_str=("**INFO*****", "**ERROR****", "**WARNING**", "**DEBUG****")[level] | 178 level_str=("**INFO*****", "**ERROR****", "**WARNING**", "**DEBUG****")[level] |
179 if file is None: | 179 if file is None: |
180 file=sys.stderr | 180 file=sys.stderr |
181 print >> file, time.asctime().strip(), '\t', level_str, '\t', self.shortname, '\t', \ | 181 print(time.asctime().strip(), '\t', level_str, '\t', self.shortname, '\t', \ |
182 message.replace('\n','\n\t** ').replace('\r','\n\t** ') | 182 message.replace('\n','\n\t** ').replace('\r','\n\t** '), file=file) |
183 | 183 |
184 def log_error(self, message, level=debug_error, file=None): | 184 def log_error(self, message, level=debug_error, file=None): |
185 "override log_error() for sending messages to special places or formatting differently" | 185 "override log_error() for sending messages to special places or formatting differently" |
186 self.fancy_log_error(message, level, file) | 186 self.fancy_log_error(message, level, file) |
187 | 187 |
271 | 271 |
272 err=result[0] | 272 err=result[0] |
273 | 273 |
274 if err and self.raise_on_err: | 274 if err and self.raise_on_err: |
275 e=_VXI_11_enumerated_exceptions #common, correctable exceptions | 275 e=_VXI_11_enumerated_exceptions #common, correctable exceptions |
276 if e.has_key(err): | 276 if err in e: |
277 raise e[err](err) #raise these exceptions explicitly | 277 raise e[err](err) #raise these exceptions explicitly |
278 else: | 278 else: |
279 raise VXI_11_Error(err) #raise generic VXI_11 exception | 279 raise VXI_11_Error(err) #raise generic VXI_11 exception |
280 | 280 |
281 return result | 281 return result |