sugar3.presence.filetransfer module

The filetransfer module provides a high level API accepting and sending file transfers to/from either memory of real files.

Note

This module provides options that activities should not use as they will trigger functions in the shell. Activities should use the file transfer APIs in the sugar3.presence.wrapper.CollabWrapper.

class sugar3.presence.filetransfer.BaseFileTransfer

Bases: gi.overrides.GObject.Object

The base file transfer should not be used directly. It is used as a base class for the incoming and outgoing file transfers.

buddy = None

(sugar3.presence.buddy.Buddy): other party in the transfer

cancel()

Request that telepathy close the file transfer channel

Spec: http://telepathy.freedesktop.org/spec/Channel.html#Method:Close

description = None

(str): metadata provided by the buddy

do_get_property(pspec)
do_set_property(pspec, value)
file_size = None

(int): size of the file being sent/received, in bytes

filename = None

(str): metadata provided by the buddy

mime_type = None

(str): metadata provided by the buddy

reason_last_change = 0

(FT_REASON_*): reason for the last state change

set_channel(channel)

Setup the file transfer to use a given telepathy channel. This should only be used by direct subclasses of the base file transfer.

state

(GObject Prop) (FT_STATE_*): current state of the transfer

transferred_bytes

(GObject Prop) (int): number of bytes transfered so far

class sugar3.presence.filetransfer.BaseOutgoingTransfer(buddy, conn, filename, description, mime)

Bases: sugar3.presence.filetransfer.BaseFileTransfer

This class provides the base of an outgoing file transfer.

You can override the _get_input_stream method to return any type of Gio input stream. This will then be used to provide the file if requested by the application. You also need to call _create_channel with the length of the file in bytes during your __init__.

Parameters:
  • buddy (sugar3.presence.buddy.Buddy) – who to send the transfer to
  • conn (telepathy.client.conn.Connection) – telepathy connection to use to send the transfer. Eg. shared_activity.telepathy_conn
  • filename (str) – metadata sent to the receiver
  • description (str) – metadata sent to the receiver
  • mime (str) – metadata sent to the receiver
class sugar3.presence.filetransfer.IncomingFileTransfer(connection, object_path, props)

Bases: sugar3.presence.filetransfer.BaseFileTransfer

An incoming file transfer from another buddy. You need to first accept the transfer (either to memory or to a file). Then you need to listen to the state and wait until the transfer is completed. Then you can read the file that it was saved to, or access the Gio.MemoryOutputStream from the output property.

The output property is different depending on how the file was accepted. If the file was accepted to a file on the file system, it is a string representing the path to the file. If the file was accepted to memory, it is a Gio.MemoryOutputStream.

accept_to_file(destination_path)

Accept the file transfer and write it to a new file. The file must already exist.

Parameters:destination_path (str) – the path where a new file will be created and saved to
accept_to_memory()

Accept the file transfer. Once the state is FT_STATE_OPEN, a Gio.MemoryOutputStream accessible via the output prop.

do_get_property(pspec)
do_set_property(pspec, value)
output
class sugar3.presence.filetransfer.OutgoingBlobTransfer(buddy, conn, blob, filename, description, mime)

Bases: sugar3.presence.filetransfer.BaseOutgoingTransfer

An outgoing file transfer to send from a string in memory.

Parameters:blob (str) – data to send
class sugar3.presence.filetransfer.OutgoingFileTransfer(buddy, conn, path, filename, description, mime)

Bases: sugar3.presence.filetransfer.BaseOutgoingTransfer

An outgoing file transfer to send from a file (on the computer’s file system).

Note that the path argument is the path for the file that will be sent, whereas the filename argument is only for metadata.

Parameters:path (str) – path of the file to send