poezio/src/bookmark.py

59 lines
1.6 KiB
Python
Raw Normal View History

2011-11-26 22:05:09 +00:00
import os
2011-11-26 14:47:41 +00:00
from sleekxmpp.plugins.xep_0048 import *
2011-11-26 22:05:09 +00:00
from core import JID
from config import config
preferred = config.get('use_bookmarks_method', 'pep').lower()
if preferred not in ('pep', 'privatexml'):
preferred = 'pep'
not_preferred = 'pep' if preferred is 'privatexml' else 'privatexml'
methods = ('local', preferred, not_preferred)
2011-11-26 14:47:41 +00:00
class Bookmark(object):
2011-11-26 22:05:09 +00:00
possible_methods = methods
2011-11-26 14:47:41 +00:00
def __init__(self, jid, name=None, autojoin=False, nick=None, password=None, method=None):
self.jid = jid
self.name = name or jid
self.autojoin = autojoin
2011-11-26 22:05:09 +00:00
if not nick:
default = os.environ.get('USER') if os.environ.get('USER') else 'poezio'
nick = config.get('default_nick', '') or default
2011-11-26 14:47:41 +00:00
self.nick = nick
self.password = password
self._method = method
@property
def method(self):
return self._method
@method.setter
def method(self, value):
if value not in self.possible_methods:
return
self._method = value
2011-11-26 22:05:09 +00:00
def __repr__(self):
return '<%s>' % self.jid
2011-11-26 14:47:41 +00:00
def stanza(self):
"""
Generate a <conference/> stanza from the instance
"""
el = Conference()
el['name'] = self.name
el['jid'] = self.jid
el['autojoin'] = 'true' if self.autojoin else 'false'
if self.nick:
n = Nick().xml
n.text = self.nick
el.append(n)
if self.password:
p = Password().xml
p.text = self.password
el.append(p)
return el