module lightblue.obex

Provides an OBEX client class and convenience functions for sending and
receiving files over OBEX.

This module also defines constants for response code values (without the final
bit set). For example:
    >>> import lightblue
    >>> lightblue.obex.OK
    32      # the OK/Success response 0x20 (i.e. 0xA0 without the final bit)
    >>> lightblue.obex.FORBIDDEN
    67      # the Forbidden response 0x43 (i.e. 0xC3 without the final bit)

Classes & Types

class OBEXClient

An OBEX client class.

class OBEXResponse

Contains the OBEX response received from an OBEX server.

exception OBEXError (lightblue.BluetoothError)

Generic exception raised for OBEX-related errors.

Functions

sendfile(address, channel, source)

    Sends a file to a remote device.

    Raises lightblue.obex.OBEXError if an error occurred during the request, or
    if the request was refused by the remote device.

    Arguments:
        - address: the address of the remote device
        - channel: the RFCOMM channel of the remote OBEX service
        - source: a filename or file-like object, containing the data to be
          sent. If a file object is given, it must be opened for reading.

    Note you can achieve the same thing using OBEXClient with something like
    this:
        >>> import lightblue
        >>> client = lightblue.obex.OBEXClient(address, channel)
        >>> client.connect()
        <OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
        >>> putresponse = client.put({"name": "MyFile.txt"}, file("MyFile.txt", 'rb'))
        >>> client.disconnect()
        <OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
        >>> if putresponse.code != lightblue.obex.OK:
        ...     raise lightblue.obex.OBEXError("request denied")
        >>>

recvfile(sock, dest)

    Receives a file through an OBEX service.

    Arguments:
        - sock: the server socket on which the file is to be received. Note
          this socket must *not* be listening. Also, an OBEX service should
          have been advertised on this socket.
        - dest: a filename or file-like object, to which the received data will
          be written. If a filename is given, any existing file will be
          overwritten. If a file object is given, it must be opened for writing.

    For example, to receive a file and save it as "MyFile.txt":
        >>> from lightblue import *
        >>> s = socket()
        >>> s.bind(("", 0))
        >>> advertise("My OBEX Service", s, OBEX)
        >>> obex.recvfile(s, "MyFile.txt")

Data

CONTINUE = 16

OK = 32

CREATED = 33

ACCEPTED = 34

NON_AUTHORITATIVE_INFORMATION = 35

NO_CONTENT = 36

RESET_CONTENT = 37

PARTIAL_CONTENT = 38

MULTIPLE_CHOICES = 48

MOVED_PERMANENTLY = 49

MOVED_TEMPORARILY = 50

SEE_OTHER = 51

NOT_MODIFIED = 52

USE_PROXY = 53

BAD_REQUEST = 64

UNAUTHORIZED = 65

PAYMENT_REQUIRED = 66

FORBIDDEN = 67

NOT_FOUND = 68

METHOD_NOT_ALLOWED = 69

NOT_ACCEPTABLE = 70

PROXY_AUTHENTICATION_REQUIRED = 71

REQUEST_TIME_OUT = 72

CONFLICT = 73

GONE = 74

LENGTH_REQUIRED = 75

PRECONDITION_FAILED = 76

REQUESTED_ENTITY_TOO_LARGE = 77

REQUEST_URL_TOO_LARGE = 78

UNSUPPORTED_MEDIA_TYPE = 79

INTERNAL_SERVER_ERROR = 80

NOT_IMPLEMENTED = 81

BAD_GATEWAY = 82

SERVICE_UNAVAILABLE = 83

GATEWAY_TIMEOUT = 84

HTTP_VERSION_NOT_SUPPORTED = 85

DATABASE_FULL = 96

DATABASE_LOCKED = 97