lodgeitlib – programmatic access to the lodgeit

Platforms: Unix, Windows

A convenient client library for the Lodgeit pastebin software.

Paste retrival and creation

lodgeitlib.pocoo_pastebin

An instance of Lodgeit for http://paste.pocoo.org.

lodgeitlib.bpaste_pastebin

An instance of Lodgeit for http://bpaste.net

lodgeitlib.lodgeit

Deprecated alias for pocoo_pastebin

lodgeitlib.PASTEBINS

a list of Lodgeit objects for all known lodgeit pastebins

class lodgeitlib.Lodgeit(pastebin_url, service_url=None, caching=True)

Client access to Lodgeit pastebins.

This class uses the JSON RPC service to retrieve or create pastes in pastebins, which are based on the Lodgeit software.

It performs internal caching, if caching is True. If caching is enabled, pastes, which are fetched by id, are first looked up in an internal cache.

Note

get_last_paste() and get_recent_pastes() are not cached, because there is no way to determine the age of a paste from the cache.

The list of available languages (see languages) is fetched, when it’s first needed, and cached for any later access, even if caching is False. You may however use reset_languages() to reset this cache.

This class is not thread-safe, at least not if caching is enabled. Multiple threads should not access this pastebin without proper synchronisation.

url

The url of the pastebin web interface. Used as base url to create paste urls. Consider this read only.

service_url

The url of the JSON-RPC service of this pastebin. Consider this read only.

hostname

The hostname of this paste as string.

caching

Whether paste caching is enabled or not.

new_paste(code, language, parent=None, filename='', mimetype='', private=False)

Create a new paste.

code is a unicode string with the code to be pasted. language is a string with the programming or markup language, the code is written in (used for server-side highlighting). parent is the parent paste, either a string or integer with a paste ID or URL, or as Paste object. filename and mimetype a strings providing the name of the file, the paste contents were read from, and the mimetype of the paste contents. private is a boolean inidicating, whether the paste should be private or not.

Pastes can have a parent paste. This is part of the “paste reply” functionality of the Lodgeit, which is described in detail under Advanced features.

Private pastes (private is True) do not get a nummeric id, but only a random hash, and do not appear in the list of all pastes.

Return the id of the created paste as integer (public pastes) or as string (private pastes). Raise UnsupportedLanguageError, if language is not supported (e.g. not contained in languages).

get_paste_by_id(id_or_url)

Retrieve the paste with the given ID or URL.

id_or_url is a string or integer containing a paste ID or a paste URL.

The retrieved paste is cached, if caching is True.

Return the Paste object for id or None, if there is no such paste.

get_last_paste()

Retrieve the last paste and return it as Paste object.

The return value of this method is never cached.

get_recent_pastes(amount=5)

Retrieve the most recent pastes.

amount is an integer specifying how many of the most recent pastes should be retrieved. This method is never cached.

Return a list of Paste objects.

id_from_url(url)

Extract a paste id from the given url.

url is a string containing the url of a paste.

Return the paste id as string, or raise ValueError, if a valid id could not be found in the given url.

languages

The languages supported by the paste bin as a mapping from the language identifier to a descriptive name of this language.

has_languages

True, if the internal language cache is filled, False otherwise.

reset_languages()

Clear the internal language cache.

exception lodgeitlib.UnsupportedLanguageError

Inidicate an unsupported language.

Paste data

class lodgeitlib.Paste

A namedtuple for a single paste.

lodgeit

The lodgeit instance, by which this paste was fetched.

id

The id of this paste as integer.

code

The pasted code as unicode string.

datetime

The datetime of publication of the paste.

language

The programming language, the paste was written in, as unicode string.

parent_id

The id of the parent paste as integer, or None, if this paste has no parent.

relative_url

The relative url of this paste. This url is relative to the url of the lodgeit, that fetched this paste.

url

The complete url of this paste as string.

language_desc

The descriptive name of the language of this paste as string.

get_parent()

Fetch the parent paste of this paste.

Return the parent paste as Paste instance, or None, if this paste has no parent.

Usage example

>>> from lodgeitlib import pocoo_pastebin
>>> code = u'print "Hello „World“"'
>>> paste_id = pocoo_pastebin.new_paste(code, 'python', private=True)
>>> paste_id
'C76X4sCbP3FEUCDBbFGa'
>>> paste = pocoo_pastebin.get_paste_by_id(paste_id)
>>> print paste.code
print "Hello „World“"
>>> paste.language_desc
'Python'
>>> paste.parent_id
>>> paste.get_parent()
>>> paste.url
'http://paste.pocoo.org/show/C76X4sCbP3FEUCDBbFGa/'
>>> pocoo_pastebin.id_from_url(paste.url)
'C76X4sCbP3FEUCDBbFGa'

Table Of Contents

Previous topic

lodgeitlib – Easy pastebin access

Next topic

lodgeit

This Page