Пример #1
0
    def roster_updated(self, item=None):
        with traceguard:
            roster = self.roster
            from util.primitives.structures import oset
            with self.root_group.frozen():
                jcontact = self.contact_class
                buddies = self.buddies
                root_group = self.root_group

                del root_group[:]

                groups = odict({None: self.root_group})
                #
                for item in roster:
                    #roster groups
                    i_groups = oset(filter(None, item.groups))
                    #profile group
                    p_groups = oset(
                        filter(None, (profile.get_contact_info(
                            self.buddies[item.jid], 'group'), )))
                    #plus default group
                    group = (p_groups | i_groups | oset([None]))[0]
                    #CAS: optimize this to not create a group every time.
                    g = groups.setdefault(group, Group(group, self, group))
                    contact = jcontact(self.buddies[item.jid](item), group)
                    g.append(contact)

                for _gid, g in groups.iteritems():
                    if not self.filter_group(g):
                        if g is not root_group:
                            root_group.append(g)
                    g[:] = [c for c in g if not self.filter_contact(c)]
Пример #2
0
    def __init__(cls, name, bases, dict):
        global _actioncalls
        super(ActionMeta, cls).__init__(name, bases, dict)

        # Inherit actions from base classes.
        superactions = mapping.odict()

        if 'inherited_actions' in dict:
            bases = bases + tuple(dict['inherited_actions'])

        funcs.do(
            superactions.update(c._actions) for c in bases
            if hasattr(c, '_actions'))
        setattr(cls, ActionMeta.class_action_attr, superactions)

        actions = getattr(cls, ActionMeta.class_action_attr)
        prefix = ActionMeta.action_prefix

        for v in dict.itervalues():
            # for each method in the classdict:
            # if it's a function and it starts with our magic action prefix,
            # remove the prefix and add it to our list of actions, along with
            # the callable "predicate" determining the action's validity at any
            # point in time
            if isinstance(v, function) and v.__name__.startswith(prefix):
                v.__name__ = v.__name__[len(prefix):]
                val = _actioncalls.pop(v)
                actions[v.__name__] = val
Пример #3
0
    def roster_updated(self, item=None):
        with traceguard:
            roster = self.roster
            from util.primitives.structures import oset
            with self.root_group.frozen():
                jcontact   = self.contact_class
                buddies    = self.buddies
                root_group = self.root_group

                del root_group[:]

                groups = odict({None: self.root_group})
    #
                for item in roster:
                    #roster groups
                    i_groups = oset(filter(None, item.groups))
                    #profile group
                    p_groups = oset(filter(None, (profile.get_contact_info(self.buddies[item.jid], 'group'),)))
                    #plus default group
                    group = (p_groups | i_groups | oset([None]))[0]
                    #CAS: optimize this to not create a group every time.
                    g = groups.setdefault(group, Group(group, self, group))
                    contact = jcontact(self.buddies[item.jid](item), group)
                    g.append(contact)

                for _gid, g in groups.iteritems():
                    if not self.filter_group(g):
                        if g is not root_group:
                            root_group.append(g)
                    g[:] = [c for c in g if not self.filter_contact(c)]
Пример #4
0
    def __init__(cls, name, bases, dict):
        global _actioncalls
        super(ActionMeta, cls).__init__(name, bases, dict)

        # Inherit actions from base classes.
        superactions = mapping.odict()

        if 'inherited_actions' in dict:
            bases = bases + tuple(dict['inherited_actions'])

        funcs.do(superactions.update(c._actions) for c in bases if hasattr(c, '_actions'))
        setattr(cls, ActionMeta.class_action_attr, superactions)

        actions = getattr(cls, ActionMeta.class_action_attr)
        prefix = ActionMeta.action_prefix

        for v in dict.itervalues():
            # for each method in the classdict:
            # if it's a function and it starts with our magic action prefix,
            # remove the prefix and add it to our list of actions, along with
            # the callable "predicate" determining the action's validity at any
            # point in time
            if isinstance(v, function) and v.__name__.startswith(prefix):
                v.__name__ = v.__name__[len(prefix):]
                val = _actioncalls.pop(v)
                actions[v.__name__] = val
Пример #5
0
def GetLocationFromIP(contact):
    import urllib2
    import lxml
    from util.primitives.mapping import odict
    from common import pref
    info = odict()

    if pref('digsby.guest.geoiplookup', default = False, type = bool):
        if getattr(contact, 'ip', False):
            url  = 'http://www.iplocationtools.com/ip_query.php?output=xml&ip=%s' % contact.ip
            try:
                resp = urllib2.urlopen(url).read()
            except Exception:
                import traceback
                traceback.print_exc()
                return info

            try:
                doc = lxml.etree.fromstring(resp)
            except Exception:
                import traceback
                traceback.print_exc()
                return info

            divs = [
                    ('City', 'City'),
                    ('RegionName', 'State'),
                    ('CountryCode', 'Country'),
                   ]
            for tag, key in divs:
                val = doc.find(tag)
                if tag:
                    info[key] = val.text

    return info
Пример #6
0
def create_graph(chains, incidence):
    graph = odict()
    for chain in chains:
        if not len(chain):
            continue
        add_node(graph, incidence, chain[0])
#        for i in range(len(chain)-1):
#            add_node(graph, incidence, chain[i+1])
#            add_arc(graph, incidence, chain[i], chain[i+1])
        for i in range(len(chain)):
            add_node(graph, incidence, chain[i])
            for j in range(i, len(chain)):
                add_arc(graph, incidence, chain[i], chain[j])
    return graph
Пример #7
0
def write_pot(f, cat, version=False):
    cat.header_comment = header_comment
    cat.fuzzy = False
    cat.project = 'digsby'
    cat.version = '$Rev$'
    cat.msgid_bugs_address = 'https://translations.launchpad.net/digsby'
    cat.copyright_holder = 'dotSyntax, LLC'

    for m in cat:
        m.locations = sorted(m.locations)
    cat._messages = odict(sorted(cat._messages.iteritems(), key = lambda x: x[1].locations))
    if version:
        cat.add('__version__', auto_comments=['$Rev$'], context='__metadata__')
    return write_po(open(f, 'w'), cat, width=None)
Пример #8
0
def write_pot(f, cat, version=False):
    cat.header_comment = header_comment
    cat.fuzzy = False
    cat.project = 'digsby'
    cat.version = '$Rev$'
    cat.msgid_bugs_address = 'https://translations.launchpad.net/digsby'
    cat.copyright_holder = 'dotSyntax, LLC'

    for m in cat:
        m.locations = sorted(m.locations)
    cat._messages = odict(
        sorted(cat._messages.iteritems(), key=lambda x: x[1].locations))
    if version:
        cat.add('__version__', auto_comments=['$Rev$'], context='__metadata__')
    return write_po(open(f, 'w'), cat, width=None)
Пример #9
0
def get_acct_properties(href):
    s_text  = get_accts_text('social')
    im_text = get_accts_text('')
    e_text  = get_accts_text('email')
    props = odict()

    if s_text:
        props['Social Networks'] = {'text': s_text,
                                    'href': clicksrc(href, 'SOCIAL')}
    if im_text:
        props['IM Accounts']     = {'text': im_text,
                                    'href': clicksrc(href, 'IM')}
    if e_text:
        props['Email Accounts']  = {'text': e_text,
                                    'href': clicksrc(href, 'EMAIL')}
    assert props
    return props
Пример #10
0
    def test_odict(self):
        d = odict()
        d['foo'] = 'bar'
        d['meep'] = 'baz'
        d[321] = 123
        d[None] = None

        self.assert_equal(['foo', 'meep', 321, None], d.keys())
        self.assert_equal(['bar', 'baz', 123, None], d.values())
        self.assert_equal([('foo', 'bar'), ('meep', 'baz'), (321, 123), (None, None)],
                          d.items())

        d.pop(321)

        self.assert_equal(['foo', 'meep', None], d.keys())
        self.assert_equal(['bar', 'baz', None], d.values())
        self.assert_equal([('foo', 'bar'), ('meep', 'baz'), (None, None)],
                          d.items())

        self.assert_raises(KeyError, lambda: d.pop(456))
Пример #11
0
def get_acct_properties(href):
    s_text = get_accts_text('social')
    im_text = get_accts_text('')
    e_text = get_accts_text('email')
    props = odict()

    if s_text:
        props['Social Networks'] = {
            'text': s_text,
            'href': clicksrc(href, 'SOCIAL')
        }
    if im_text:
        props['IM Accounts'] = {'text': im_text, 'href': clicksrc(href, 'IM')}
    if e_text:
        props['Email Accounts'] = {
            'text': e_text,
            'href': clicksrc(href, 'EMAIL')
        }
    assert props
    return props
Пример #12
0
    def test_odict(self):
        d = odict()
        d['foo'] = 'bar'
        d['meep'] = 'baz'
        d[321] = 123
        d[None] = None

        self.assert_equal(['foo', 'meep', 321, None], d.keys())
        self.assert_equal(['bar', 'baz', 123, None], d.values())
        self.assert_equal([('foo', 'bar'), ('meep', 'baz'), (321, 123),
                           (None, None)], d.items())

        d.pop(321)

        self.assert_equal(['foo', 'meep', None], d.keys())
        self.assert_equal(['bar', 'baz', None], d.values())
        self.assert_equal([('foo', 'bar'), ('meep', 'baz'), (None, None)],
                          d.items())

        self.assert_raises(KeyError, lambda: d.pop(456))
Пример #13
0
def protos_of_type(s):
    return odict((k,v) for (k,v) in protocols.items() if v.get('component_type', v.get('type', None)) == s)
Пример #14
0
            compat = protocols[p1].setdefault('compatible', set())
            compat.add(p2)

def protos_of_type(s):
    return odict((k,v) for (k,v) in protocols.items() if v.get('component_type', v.get('type', None)) == s)

def is_compatible(one, theother):
    '''
    returns True iff one is compatible with theother. this is not necessarily commutative
    '''
    return theother in protocols[one].compatible

def proto_init(proto_name):
    return import_function(protocols[proto_name].path)

improtocols = odict()
emailprotocols = odict()
socialprotocols = odict()

def proto_update_types():
    global protocols
    global improtocols
    global emailprotocols
    global socialprotocols
    improtocols.update(     protos_of_type('im')     )
    emailprotocols.update(  protos_of_type('email')  )
    socialprotocols.update( protos_of_type('social') )

    improtocols.pop('digsby', None) #incase updates do something funny.

    popularity_key = lambda d: d.get('popularity') #default None
Пример #15
0
import hooks
import jabber
import random
import string
import sys
from common.Protocol import StateMixin

callbacks      = lazyModule('util.callbacks')
mapping        = lazyModule('util.primitives.mapping')
funcs          = lazyModule('util.primitives.funcs')
error_handling = lazyModule('util.primitives.error_handling')
hook_util      = lazyModule('util.hook_util')
util_threads   = lazyModule('util.threads')

log = getLogger('jabber.protocol')
methods_dict = odict(dict(digsby_login="******"))

log = getLogger('digsbyImportProtocol')

LOAD_BALANCE_ADDRS = [
                      ('login1.digsby.org', 80),
                      ('login2.digsby.org', 80)
                     ]

JABBER_SRVS_FALLBACK = [
                        'api1.digsby.org',
                        'api2.digsby.org',
                        ]

class DigsbyProtocol(JabberClient, StateMixin):