Rest.Param

Fields

None

Methods

class

new_full (name, use, data, content_type, filename)

class

new_string (name, use, string)

class

new_with_owner (name, data, content_type, filename, owner, owner_dnotify)

get_content ()

get_content_length ()

get_content_type ()

get_file_name ()

get_name ()

is_string ()

ref ()

unref ()

Details

class Rest.Param
classmethod new_full(name, use, data, content_type, filename)
Parameters:
  • name (str) – the parameter name

  • use (Rest.MemoryUse) – the Rest.MemoryUse describing how the memory can be used

  • data (bytes) – a pointer to the start of the data

  • content_type (str) – the content type of the data

  • filename (str or None) – the original filename, or None

Returns:

a new Rest.Param.

Return type:

Rest.Param

Create a new Rest.Param called name with length bytes of data as the value. content_type is the type of the data as a MIME type, for example “text/plain” for simple string parameters.

If the parameter is a file upload it can be passed as filename.

classmethod new_string(name, use, string)
Parameters:
Returns:

a new Rest.Param.

Return type:

Rest.Param

A convience constructor to create a Rest.Param from a given UTF-8 string. The resulting Rest.Param will have a content type of “text/plain”.

classmethod new_with_owner(name, data, content_type, filename, owner, owner_dnotify)
Parameters:
  • name (str) – the parameter name

  • data (bytes) – a pointer to the start of the data

  • content_type (str) – the content type of the data

  • filename (str or None) – the original filename, or None

  • owner (object or None) – pointer to an object that owns data

  • owner_dnotify (GLib.DestroyNotify or None) – a function to free/unref owner when the buffer is freed

Returns:

a new Rest.Param.

Return type:

Rest.Param

Create a new Rest.Param called name with length bytes of data as the value. content_type is the type of the data as a MIME type, for example “text/plain” for simple string parameters.

If the parameter is a file upload it can be passed as filename.

When the Rest.Param is freed, it will call owner_dnotify, passing owner to it. This allows you to do something like this:

GMappedFile *map = g_mapped_file_new (filename, FALSE, &error);
RestParam *param = rest_param_new_with_owner ("media",
                                              g_mapped_file_get_contents (map),
                                              g_mapped_file_get_length (map),
                                              "image/jpeg",
                                              filename,
                                              map,
                                              (GDestroyNotify)g_mapped_file_unref);
get_content()
Returns:

the content.

Return type:

object or None

Get the content of self. The content should be treated as read-only and not modified in any way.

get_content_length()
Returns:

the length of the content

Return type:

int

Get the length of the content of self.

get_content_type()
Returns:

the MIME type

Return type:

str

Get the MIME type of the parameter. For example, basic strings have the MIME type “text/plain”.

get_file_name()
Returns:

the filename if set, or None.

Return type:

str

Get the original file name of the parameter, if one is available.

get_name()
Returns:

the parameter name.

Return type:

str

Get the name of the parameter.

is_string()
Returns:

True if the parameter is a string, False otherwise.

Return type:

bool

Determine if the parameter is a string value, i.e. the content type is “text/plain”.

ref()
Returns:

the Rest.Param

Return type:

Rest.Param

Increase the reference count on self.

unref()

Decrease the reference count on self, destroying it if the reference count reaches 0.