(self, arg, default_stream, codepage)
Initialise LPTn: device.
Initialise LPTn: device.
Initialise LPTn : device .
def __init__(self, arg, default_stream, codepage):
        """Initialise LPTn: device."""
        Device.__init__(self)
        addr, val = parse_protocol_string(arg)
        self.stream = default_stream
        if addr == u'FILE':
            try:
                self.stream = io.open(val, 'wb')
            except EnvironmentError as e:
                logging.warning(u'Could not attach file %s to LPT device: %s', val, e)
        elif addr == u'PARPORT':
            # port can be e.g. /dev/parport0 on Linux or LPT1 on Windows. Just a number counting from 0 would also work.
            try:
                self.stream = ParallelStream(val)
            except EnvironmentError as e:
                logging.warning(u'Could not attach parallel port %s to LPT device: %s', val, e)
        elif addr == u'STDIO' or (not addr and val == u'STDIO'):
            crlf = (val.upper() == u'CRLF')
            self.stream = StdIOParallelStream(crlf)
        elif addr == u'PRINTER' or (val and not addr):
            # 'PRINTER' is default
            # name:parameters (LINE, PAGE, ...)
            options = val.split(u':')
            printer_name = options[0]
            flush_trigger = (options[1:] or [u''])[0]
            self.stream = PrinterStream(printer_name, flush_trigger, codepage)
        elif val:
            logging.warning(u'Could not attach %s to LPT device', arg)
        # column counter is the same across all LPT files
        self.device_settings = DeviceSettings()
        if self.stream:
            self.device_file = LPTFile(self.stream, self.device_settings)
def __init__ ( self , arg , default_stream , codepage ) : Device . __init__ ( self ) addr , val = parse_protocol_string ( arg ) self . stream = default_stream if addr == u'FILE' : try : self . stream = io . open ( val , 'wb' ) except EnvironmentError as e : logging . warning ( u'Could not attach file %s to LPT device: %s' , val , e ) elif addr == u'PARPORT' : # port can be e.g. /dev/parport0 on Linux or LPT1 on Windows. Just a number counting from 0 would also work. try : self . stream = ParallelStream ( val ) except EnvironmentError as e : logging . warning ( u'Could not attach parallel port %s to LPT device: %s' , val , e ) elif addr == u'STDIO' or ( not addr and val == u'STDIO' ) : crlf = ( val . upper ( ) == u'CRLF' ) self . stream = StdIOParallelStream ( crlf ) elif addr == u'PRINTER' or ( val and not addr ) : # 'PRINTER' is default # name:parameters (LINE, PAGE, ...) options = val . split ( u':' ) printer_name = options [ 0 ] flush_trigger = ( options [ 1 : ] or [ u'' ] ) [ 0 ] self . stream = PrinterStream ( printer_name , flush_trigger , codepage ) elif val : logging . warning ( u'Could not attach %s to LPT device' , arg ) # column counter is the same across all LPT files self . device_settings = DeviceSettings ( ) if self . stream : self . device_file = LPTFile ( self . stream , self . device_settings )