Пример #1
0
class RPC(pb.Referenceable, resource.Resource):
    isLeaf = True

    def __init__(self):
        ibid.rpc[self.features[0]] = self
        self.form = templates.get_template('plugin_form.html')
        self.list = templates.get_template('plugin_functions.html')

    def get_function(self, request):
        method = request.postpath[0]

        if hasattr(self, 'remote_%s' % method):
            return getattr(self, 'remote_%s' % method)

        return None

    def render_POST(self, request):
        args = []
        for arg in request.postpath[1:]:
            try:
                arg = json.loads(arg)
            except ValueError, e:
                pass
            args.append(arg)

        kwargs = {}
        for key, value in request.args.items():
            try:
                value = json.loads(value[0])
            except ValueError, e:
                value = value[0]
            kwargs[key] = value
Пример #2
0
    def _event(self, data):
        "Handle a JSON stream event, data is the JSON"
        d = json.loads(data)

        if d['user_id'] == self.my_id:
            return

        type = d['type']
        if type.endswith('Message'):
            type = type[:-7]
        if type == 'Enter':
            self.get_room_info(d['room_id'])
        if hasattr(self, 'handle_' + type):
            params = {}
            params['room_id'] = d['room_id']
            params['room_name'] = self._rooms[d['room_id']]['name']
            if d.get('user_id') is not None:
                if d['user_id'] not in self._users:
                    # User list not loaded yet, stick it on a queue:
                    self._room_info_queue.append((d['room_id'], data))
                    return
                params['user_id'] = d['user_id']
                params['user_name'] = self._users[d['user_id']]['name']
            if d.get('body', None) is not None:
                params['body'] = d['body']

            getattr(self, 'handle_' + type)(**params)
Пример #3
0
    def _event(self, data):
        "Handle a JSON stream event, data is the JSON"
        d = json.loads(data)

        if d['user_id'] == self.my_id:
            return

        type = d['type']
        if type.endswith('Message'):
            type = type[:-7]
        if type == 'Enter':
            self.get_room_info(d['room_id'])
        if hasattr(self, 'handle_' + type):
            params = {}
            params['room_id'] = d['room_id']
            params['room_name'] = self._rooms[d['room_id']]['name']
            if d.get('user_id') is not None:
                if d['user_id'] not in self._users:
                    # User list not loaded yet, stick it on a queue:
                    self._room_info_queue.append((d['room_id'], data))
                    return
                params['user_id'] = d['user_id']
                params['user_name'] = self._users[d['user_id']]['name']
            if d.get('body', None) is not None:
                params['body'] = d['body']

            getattr(self, 'handle_' + type)(**params)
Пример #4
0
def json_webservice(url, params={}, headers={}):
    "Request data from a JSON webservice, and deserialise"

    data = generic_webservice(url, params, headers)
    try:
        return json.loads(data)
    except ValueError, e:
        raise JSONException(e)
Пример #5
0
def json_webservice(url, params={}, headers={}):
    "Request data from a JSON webservice, and deserialise"

    data = generic_webservice(url, params, headers)
    try:
        return json.loads(data)
    except ValueError, e:
        raise JSONException(e)
Пример #6
0
 def render_POST(self, request):
     args = []
     for arg in request.postpath[1:]:
         try:
             arg = json.loads(arg)
         except ValueError, e:
             pass
         args.append(arg)
Пример #7
0
    def _do_room_list(self, data):
        log.debug(u'Parsing room list')
        roommeta = json.loads(data)['rooms']

        for room in roommeta:
            # We want this present before we get to room metadata
            self._rooms[room['id']] = {'name': room['name']}

            if room['name'] in self.rooms:
                logging.debug(u'Connecting to: %s', room['name'])

                self.join_room(room['id'])
Пример #8
0
    def _do_room_list(self, data):
        log.debug(u'Parsing room list')
        roommeta = json.loads(data)['rooms']

        for room in roommeta:
            # We want this present before we get to room metadata
            self._rooms[room['id']] = {'name': room['name']}

            if room['name'] in self.rooms:
                logging.debug(u'Connecting to: %s', room['name'])

                self.join_room(room['id'])
Пример #9
0
    def _do_room_info(self, data, join):
        d = json.loads(data)['room']
        r = self._rooms[d['id']]
        for k, v in d.iteritems():
            if k != 'users':
                r[k] = v

        r['users'] = set()
        for user in d['users']:
            self._users[user['id']] = u = user
            r['users'].add(user['id'])
        if join:
            self.joined_room(r)

        queue, self._room_info_queue = self._room_info_queue, []
        for room_id, item in queue:
            if room_id == d['id']:
                self._event(item)
            else:
                self._room_info_queue.append((room_id, item))
Пример #10
0
    def _do_room_info(self, data, join):
        d = json.loads(data)['room']
        r = self._rooms[d['id']]
        for k, v in d.iteritems():
            if k != 'users':
                r[k] = v

        r['users'] = set()
        for user in d['users']:
            self._users[user['id']] = u = user
            r['users'].add(user['id'])
        if join:
            self.joined_room(r)

        queue, self._room_info_queue = self._room_info_queue, []
        for room_id, item in queue:
            if room_id == d['id']:
                self._event(item)
            else:
                self._room_info_queue.append((room_id, item))
Пример #11
0
 def _do_get_id(self, data):
     log.debug(u'Parsing my info')
     meta = json.loads(data)['user']
     self.my_id = meta['id']
     self.my_name = meta['name']
     self.get_room_list()
Пример #12
0
 def _do_get_id(self, data):
     log.debug(u'Parsing my info')
     meta = json.loads(data)['user']
     self.my_id = meta['id']
     self.my_name = meta['name']
     self.get_room_list()