frontends: define the constants with classes and inheritance instance of using __builtin__
This commit is contained in:
parent
b824f9c2ce
commit
f5dd3f2265
4 changed files with 169 additions and 95 deletions
|
|
@ -16,6 +16,10 @@
|
|||
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import __builtin__
|
||||
|
||||
__builtin__.__dict__['const_PRIVATE_PREFIX'] = "@PRIVATE@"
|
||||
from sat_frontends import constants
|
||||
|
||||
|
||||
class Const(constants.Const):
|
||||
|
||||
PRIVATE_PREFIX = "@PRIVATE@"
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
|
|||
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
|
||||
from optparse import OptionParser
|
||||
|
||||
import sat_frontends.quick_frontend.constants
|
||||
from sat_frontends.quick_frontend.constants import Const
|
||||
|
||||
import gettext
|
||||
gettext.install('sat_frontend', unicode=True)
|
||||
|
|
@ -283,7 +283,7 @@ class QuickApp(object):
|
|||
self.chat_wins[win.bare].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '')
|
||||
|
||||
def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@"):
|
||||
if to_jid.startswith(const_PRIVATE_PREFIX):
|
||||
if to_jid.startswith(Const.PRIVATE_PREFIX):
|
||||
to_jid = unescapePrivate(to_jid)
|
||||
mess_type = "chat"
|
||||
self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
from logging import debug, info, warning, error
|
||||
from sat.tools.jid import JID
|
||||
from sat_frontends.quick_frontend.quick_utils import unescapePrivate
|
||||
from sat_frontends.quick_frontend.constants import Const
|
||||
|
||||
|
||||
class QuickChat(object):
|
||||
|
|
@ -107,7 +108,7 @@ class QuickChat(object):
|
|||
def onHistoryError(err):
|
||||
error (_("Can't get history"))
|
||||
|
||||
if self.target.startswith(const_PRIVATE_PREFIX):
|
||||
if self.target.startswith(Const.PRIVATE_PREFIX):
|
||||
target = unescapePrivate(self.target)
|
||||
else:
|
||||
target = self.target.bare
|
||||
|
|
@ -116,9 +117,9 @@ class QuickChat(object):
|
|||
|
||||
def _get_nick(self, jid):
|
||||
"""Return nick of this jid when possible"""
|
||||
if self.target.startswith(const_PRIVATE_PREFIX):
|
||||
if self.target.startswith(Const.PRIVATE_PREFIX):
|
||||
unescaped = unescapePrivate(self.target)
|
||||
if jid.startswith(const_PRIVATE_PREFIX) or unescaped.bare == jid.bare:
|
||||
if jid.startswith(Const.PRIVATE_PREFIX) or unescaped.bare == jid.bare:
|
||||
return unescaped.resource
|
||||
return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,15 +19,16 @@
|
|||
|
||||
from sat.tools.jid import JID
|
||||
from os.path import exists, splitext
|
||||
from sat_frontends.quick_frontend.constants import Const
|
||||
|
||||
def escapePrivate(ori_jid):
|
||||
"""Escape a private jid"""
|
||||
return JID(const_PRIVATE_PREFIX + ori_jid.bare + '@' + ori_jid.resource)
|
||||
return JID(Const.PRIVATE_PREFIX + ori_jid.bare + '@' + ori_jid.resource)
|
||||
|
||||
def unescapePrivate(escaped_jid):
|
||||
if not escaped_jid.startswith(const_PRIVATE_PREFIX):
|
||||
if not escaped_jid.startswith(Const.PRIVATE_PREFIX):
|
||||
return escaped_jid
|
||||
escaped_split = tuple(escaped_jid[len(const_PRIVATE_PREFIX):].split('@'))
|
||||
escaped_split = tuple(escaped_jid[len(Const.PRIVATE_PREFIX):].split('@'))
|
||||
assert(len(escaped_split) == 3)
|
||||
return JID("%s@%s/%s" % escaped_split)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue