Package common :: Module helpers
[hide private]
[frames] | no frames]

Module helpers

source code

Classes [hide private]
  InvalidFormat
Functions [hide private]
 
decompose_jid(jidstring) source code
 
parse_jid(jidstring)
Perform stringprep on all JID fragments from a string and return the full jid
source code
 
idn_to_ascii(host)
Convert IDN (Internationalized Domain Names) to ACE (ASCII-compatible encoding)
source code
 
ascii_to_idn(host)
Convert ACE (ASCII-compatible encoding) to IDN (Internationalized Domain Names)
source code
 
parse_resource(resource)
Perform stringprep on resource and return it
source code
 
prep(user, server, resource)
Perform stringprep on all JID fragments and return the full jid
source code
 
windowsify(s) source code
 
temp_failure_retry(func, *args, **kwargs) source code
 
get_uf_show(show, use_mnemonic=False)
Return a userfriendly string for dnd/xa/chat and make all strings translatable
source code
 
get_uf_sub(sub) source code
 
get_uf_ask(ask) source code
 
get_uf_role(role, plural=False)
plural determines if you get Moderators or Moderator
source code
 
get_uf_affiliation(affiliation)
Get a nice and translated affilition for muc
source code
 
get_sorted_keys(adict) source code
 
to_one_line(msg) source code
 
from_one_line(msg) source code
 
get_uf_chatstate(chatstate)
Remove chatstate jargon and returns user friendly messages
source code
 
is_in_path(command, return_abs_path=False)
Return True if 'command' is found in one of the directories in the user's path.
source code
 
exec_command(command) source code
 
build_command(executable, parameter) source code
 
get_file_path_from_dnd_dropped_uri(uri) source code
 
from_xs_boolean_to_python_boolean(value) source code
 
get_xmpp_show(show) source code
 
get_output_of_command(command) source code
 
decode_string(string)
Try to decode (to make it Unicode instance) given string
source code
 
ensure_utf8_string(string)
Make sure string is in UTF-8
source code
 
get_windows_reg_env(varname, default='')
Ask for paths commonly used but not exposed as ENVs in english Windows 2003...
source code
 
get_my_pictures_path()
Windows-only atm
source code
 
get_desktop_path() source code
 
get_documents_path() source code
 
sanitize_filename(filename)
Make sure the filename we will write does contain only acceptable and latin characters, and is not too long (in that case hash it)
source code
 
reduce_chars_newlines(text, max_chars=0, max_lines=0)
Cut the chars after 'max_chars' on each line and show only the first 'max_lines'
source code
 
get_account_status(account) source code
 
get_avatar_path(prefix)
Return the filename of the avatar, distinguishes between user- and contact- provided one.
source code
 
datetime_tuple(timestamp)
Convert timestamp using strptime and the format: %Y%m%dT%H:%M:%S
source code
 
convert_bytes(string) source code
 
get_contact_dict_for_account(account)
Create a dict of jid, nick -> contact with all contacts of account.
source code
 
launch_browser_mailer(kind, uri) source code
 
launch_file_manager(path_to_open) source code
 
play_sound(event) source code
 
check_soundfile_path(file, dirs=(gajim.gajimpaths.data_root,gajim.DATA_DIR))
Check if the sound file exists
source code
 
strip_soundfile_path(file, dirs=(gajim.gajimpaths.data_root,gajim.DATA_DIR), abs=True)
Remove knowns paths from a sound file
source code
 
play_sound_file(path_to_soundfile) source code
 
get_global_show() source code
 
get_global_status() source code
 
statuses_unified()
Test if all statuses are the same
source code
 
get_icon_name_to_show(contact, account=None)
Get the icon name to show in online, away, requested, etc
source code
 
get_full_jid_from_iq(iq_obj)
Return the full jid (with resource) from an iq as unicode
source code
 
get_jid_from_iq(iq_obj)
Return the jid (without resource) from an iq as unicode
source code
 
get_auth_sha(sid, initiator, target)
Return sha of sid + initiator + target used for proxy auth
source code
 
remove_invalid_xml_chars(string) source code
 
get_random_string_16()
Create random string of length 16
source code
 
get_os_info() source code
 
allow_showing_notification(account, type_='notify_on_new_message', advanced_notif_num=None, is_first_message=True)
Is it allowed to show nofication?
source code
 
allow_popup_window(account, advanced_notif_num=None)
Is it allowed to popup windows?
source code
 
allow_sound_notification(account, sound_event, advanced_notif_num=None) source code
 
get_chat_control(account, contact) source code
 
get_notification_icon_tooltip_dict()
Return a dict of the form {acct: {'show': show, 'message': message, 'event_lines': [list of text lines to show in tooltip]}
source code
 
get_notification_icon_tooltip_text() source code
 
get_accounts_info()
Helper for notification icon tooltip
source code
 
get_iconset_path(iconset) source code
 
get_mood_iconset_path(iconset) source code
 
get_activity_iconset_path(iconset) source code
 
get_transport_path(transport) source code
 
prepare_and_validate_gpg_keyID(account, jid, keyID)
Return an eight char long keyID that can be used with for GPG encryption with this contact
source code
 
update_optional_features(account=None) source code
 
jid_is_blocked(account, jid) source code
 
group_is_blocked(account, group) source code
 
get_subscription_request_msg(account=None) source code
Variables [hide private]
  special_groups = _('Transports'), _('Not in Roster'), _('Obser...
  distro_info = {'Arch Linux': '/etc/arch-release', 'Aurox Linux...

Imports: sys, re, locale, os, subprocess, urllib, errno, select, base64, hashlib, caps_cache, punycode_encode, Template, Q_, ngettext, winsound, win32api, win32con, gajim


Function Details [hide private]

decompose_jid(jidstring)

source code 

parse_jid(jidstring)

source code 
Perform stringprep on all JID fragments from a string and return the full jid

idn_to_ascii(host)

source code 
Convert IDN (Internationalized Domain Names) to ACE (ASCII-compatible encoding)

ascii_to_idn(host)

source code 
Convert ACE (ASCII-compatible encoding) to IDN (Internationalized Domain Names)

parse_resource(resource)

source code 
Perform stringprep on resource and return it

prep(user, server, resource)

source code 
Perform stringprep on all JID fragments and return the full jid

windowsify(s)

source code 

temp_failure_retry(func, *args, **kwargs)

source code 

get_uf_show(show, use_mnemonic=False)

source code 

Return a userfriendly string for dnd/xa/chat and make all strings translatable

If use_mnemonic is True, it adds _ so GUI should call with True for accessibility issues

get_uf_sub(sub)

source code 

get_uf_ask(ask)

source code 

get_uf_role(role, plural=False)

source code 
plural determines if you get Moderators or Moderator

get_uf_affiliation(affiliation)

source code 
Get a nice and translated affilition for muc

get_sorted_keys(adict)

source code 

to_one_line(msg)

source code 

from_one_line(msg)

source code 

get_uf_chatstate(chatstate)

source code 
Remove chatstate jargon and returns user friendly messages

is_in_path(command, return_abs_path=False)

source code 
Return True if 'command' is found in one of the directories in the user's path. If 'return_abs_path' is True, return the absolute path of the first found command instead. Return False otherwise and on errors

exec_command(command)

source code 

build_command(executable, parameter)

source code 

get_file_path_from_dnd_dropped_uri(uri)

source code 

from_xs_boolean_to_python_boolean(value)

source code 

get_xmpp_show(show)

source code 

get_output_of_command(command)

source code 

decode_string(string)

source code 
Try to decode (to make it Unicode instance) given string

ensure_utf8_string(string)

source code 
Make sure string is in UTF-8

get_windows_reg_env(varname, default='')

source code 

Ask for paths commonly used but not exposed as ENVs in english Windows 2003
those are:
        'AppData' = %USERPROFILE%\Application Data (also an ENV)
        'Desktop' = %USERPROFILE%\Desktop
        'Favorites' = %USERPROFILE%\Favorites
        'NetHood' = %USERPROFILE%\NetHood
        'Personal' = D:\My Documents (PATH TO MY DOCUMENTS)
        'PrintHood' = %USERPROFILE%\PrintHood
        'Programs' = %USERPROFILE%\Start Menu\Programs
        'Recent' = %USERPROFILE%\Recent
        'SendTo' = %USERPROFILE%\SendTo
        'Start Menu' = %USERPROFILE%\Start Menu
        'Startup' = %USERPROFILE%\Start Menu\Programs\Startup
        'Templates' = %USERPROFILE%\Templates
        'My Pictures' = D:\My Documents\My Pictures
        'Local Settings' = %USERPROFILE%\Local Settings
        'Local AppData' = %USERPROFILE%\Local Settings\Application Data
        'Cache' = %USERPROFILE%\Local Settings\Temporary Internet Files
        'Cookies' = %USERPROFILE%\Cookies
        'History' = %USERPROFILE%\Local Settings\History

get_my_pictures_path()

source code 
Windows-only atm

get_desktop_path()

source code 

get_documents_path()

source code 

sanitize_filename(filename)

source code 
Make sure the filename we will write does contain only acceptable and latin characters, and is not too long (in that case hash it)

reduce_chars_newlines(text, max_chars=0, max_lines=0)

source code 

Cut the chars after 'max_chars' on each line and show only the first 'max_lines'

If any of the params is not present (None or 0) the action on it is not performed

get_account_status(account)

source code 

get_avatar_path(prefix)

source code 
Return the filename of the avatar, distinguishes between user- and contact- provided one. Return None if no avatar was found at all. prefix is the path to the requested avatar just before the ".png" or ".jpeg"

datetime_tuple(timestamp)

source code 

Convert timestamp using strptime and the format: %Y%m%dT%H:%M:%S

Because of various datetime formats are used the following exceptions
are handled:
        - Optional milliseconds appened to the string are removed
        - Optional Z (that means UTC) appened to the string are removed
        - XEP-082 datetime strings have all '-' cahrs removed to meet
          the above format.

convert_bytes(string)

source code 

get_contact_dict_for_account(account)

source code 

Create a dict of jid, nick -> contact with all contacts of account.

Can be used for completion lists

launch_browser_mailer(kind, uri)

source code 

launch_file_manager(path_to_open)

source code 

play_sound(event)

source code 

check_soundfile_path(file, dirs=(gajim.gajimpaths.data_root,gajim.DATA_DIR))

source code 

Check if the sound file exists

:return the path to file or None if it doesn't exists.

Parameters:
  • file - the file to check, absolute or relative to 'dirs' path
  • dirs - list of knows paths to fallback if the file doesn't exists (eg: ~/.gajim/sounds/, DATADIR/sounds...).

strip_soundfile_path(file, dirs=(gajim.gajimpaths.data_root,gajim.DATA_DIR), abs=True)

source code 

Remove knowns paths from a sound file

Filechooser returns absolute path. If path is a known fallback path, we remove it. So config have no hardcoded path to DATA_DIR and text in textfield is shorther. param: file: the filename to strip. param: dirs: list of knowns paths from which the filename should be stripped. param: abs: force absolute path on dirs

play_sound_file(path_to_soundfile)

source code 

get_global_show()

source code 

get_global_status()

source code 

statuses_unified()

source code 
Test if all statuses are the same

get_icon_name_to_show(contact, account=None)

source code 
Get the icon name to show in online, away, requested, etc

get_full_jid_from_iq(iq_obj)

source code 
Return the full jid (with resource) from an iq as unicode

get_jid_from_iq(iq_obj)

source code 
Return the jid (without resource) from an iq as unicode

get_auth_sha(sid, initiator, target)

source code 
Return sha of sid + initiator + target used for proxy auth

remove_invalid_xml_chars(string)

source code 

get_random_string_16()

source code 
Create random string of length 16

get_os_info()

source code 

allow_showing_notification(account, type_='notify_on_new_message', advanced_notif_num=None, is_first_message=True)

source code 

Is it allowed to show nofication?

Check OUR status and if we allow notifications for that status type is the option that need to be True e.g.: notify_on_signing is_first_message: set it to false when it's not the first message

allow_popup_window(account, advanced_notif_num=None)

source code 
Is it allowed to popup windows?

allow_sound_notification(account, sound_event, advanced_notif_num=None)

source code 

get_chat_control(account, contact)

source code 

get_notification_icon_tooltip_dict()

source code 
Return a dict of the form {acct: {'show': show, 'message': message, 'event_lines': [list of text lines to show in tooltip]}

get_notification_icon_tooltip_text()

source code 

get_accounts_info()

source code 
Helper for notification icon tooltip

get_iconset_path(iconset)

source code 

get_mood_iconset_path(iconset)

source code 

get_activity_iconset_path(iconset)

source code 

get_transport_path(transport)

source code 

prepare_and_validate_gpg_keyID(account, jid, keyID)

source code 

Return an eight char long keyID that can be used with for GPG encryption with this contact

If the given keyID is None, return UNKNOWN; if the key does not match the assigned key XXXXXXXXMISMATCH is returned. If the key is trusted and not yet assigned, assign it.

update_optional_features(account=None)

source code 

jid_is_blocked(account, jid)

source code 

group_is_blocked(account, group)

source code 

get_subscription_request_msg(account=None)

source code 

Variables Details [hide private]

special_groups

Value:
_('Transports'), _('Not in Roster'), _('Observers'), _('Groupchats')

distro_info

Value:
{'Arch Linux': '/etc/arch-release', 'Aurox Linux': '/etc/aurox-release\
', 'Conectiva Linux': '/etc/conectiva-release', 'CRUX': '/usr/bin/crux\
', 'Debian GNU/Linux': '/etc/debian_release', 'Debian GNU/Linux': '/et\
c/debian_version', 'Fedora Linux': '/etc/fedora-release', 'Gentoo Linu\
x': '/etc/gentoo-release', 'Linux from Scratch': '/etc/lfs-release', '\
Mandrake Linux': '/etc/mandrake-release', 'Slackware Linux': '/etc/sla\
ckware-release', 'Slackware Linux': '/etc/slackware-version', 'Solaris\
/Sparc': '/etc/release', 'Source Mage': '/etc/sourcemage_version', 'SU\
...