def __init__(self, device, timeout=<NUM_LIT:1>, debug=False):
self.debug = debug<EOL>self.device = device<EOL>self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<EOL>self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, <NUM_LIT:1>)<EOL>match = DEVICE_PATTERN.match(device)<EOL>host = match.group('<STR_LIT:host>')<EOL>port = match.group('<STR_LIT:port>') or DEFAULT_PORT<EOL>self.socket.connect((host, int(port)))<EOL>self.socket_file = self.socket.makefile('<STR_LIT:wb>')<EOL>self.num_read_bytes = <NUM_LIT:0><EOL>self.num_write_bytes = <NUM_LIT:0><EOL>if self.debug:<EOL><INDENT>sys.stderr.write("<STR_LIT>" % (<EOL>self.__class__.__name__,<EOL>self.socket<EOL>))<EOL><DEDENT>return None<EOL>
Open YHSM device.