Logo Search packages:      
Sourcecode: calibre version File versions

def calibre::devices::prs500::driver::PRS500::safe (   func  ) 

Decorator that wraps a call to C{func} to ensure that
exceptions are handled correctly. It also calls L{open} to claim
the interface and initialize the Reader if needed.

As a convenience, C{safe} automatically sends the a
L{EndSession} after calling func, unless func has
a keyword argument named C{end_session} set to C{False}.

An L{ArgumentError} will cause the L{EndSession} command to
be sent to the device, unless end_session is set to C{False}.
An L{usb.USBError} will cause the library to release control of the
USB interface via a call to L{close}.

Definition at line 147 of file driver.py.

00147                   :
        """
        Decorator that wraps a call to C{func} to ensure that
        exceptions are handled correctly. It also calls L{open} to claim
        the interface and initialize the Reader if needed.

        As a convenience, C{safe} automatically sends the a
        L{EndSession} after calling func, unless func has
        a keyword argument named C{end_session} set to C{False}.

        An L{ArgumentError} will cause the L{EndSession} command to
        be sent to the device, unless end_session is set to C{False}.
        An L{usb.USBError} will cause the library to release control of the
        USB interface via a call to L{close}.
        """
        @wraps(func)
        def run_session(*args, **kwargs):
            dev = args[0]
            res = None
            try:
                if not dev.handle:
                    dev.open()
                if not dev.in_session:
                    dev.send_validated_command(BeginEndSession(end=False))
                    dev.in_session = True
                res = func(*args, **kwargs)
            except ArgumentError:
                if not kwargs.has_key("end_session") or kwargs["end_session"]:
                    dev.send_validated_command(BeginEndSession(end=True))
                    dev.in_session = False
                raise
            except USBError, err:
                if "No such device" in str(err):
                    raise DeviceError()
                elif "Connection timed out" in str(err):
                    dev.close()
                    raise TimeoutError(func.__name__)
                elif "Protocol error" in str(err):
                    dev.close()
                    raise ProtocolError("There was an unknown error in the"+\
                                                 " protocol. Contact " + __author__)
                dev.close()
                raise
            if not kwargs.has_key("end_session") or kwargs["end_session"]:
                dev.send_validated_command(BeginEndSession(end=True))
                dev.in_session = False
            return res

        return run_session

    def reset(self, key='-1', log_packets=False, report_progress=None) :


Generated by  Doxygen 1.6.0   Back to index