Commit 323558c8 authored by Antoine Millet's avatar Antoine Millet
Browse files

Implementation of reserved tags.

parent 77727c8e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ class CCServer(object):

    LISTEN_BACKLOG = 5

    # These tags are reserved and cannot be setted by an user:
    RESERVED_TAGS = ('id', 'a', 'r', 'close', 'con', 'ip')

    def __init__(self, conf_dir, certfile=None, keyfile=None,
                 address='0.0.0.0', port=1984):

+4 −0
Original line number Diff line number Diff line
@@ -20,3 +20,7 @@ class BadObjectError(Exception):

class NotConnectedAccountError(Exception):
    pass


class ReservedTagError(Exception):
    pass
+6 −2
Original line number Diff line number Diff line
@@ -5,7 +5,8 @@ import inspect
import logging
from sjrpc.utils import RpcHandler, pure
from conf import CCConf
from exceptions import AlreadyRegistered, AuthenticationError, RightError
from exceptions import (AlreadyRegistered, AuthenticationError, RightError,
                        ReservedTagError)

def listed(func):
    func.__listed__ = True
@@ -129,7 +130,8 @@ class ClientHandler(OnlineCCHandler):
        '''
        Add a tag to the account which match the specified query.
        '''
        
        if tag_name in self._server.RESERVED_TAGS:
            raise ReservedTagError('Tag %r is read-only' % tag_name)
        objects = self._server.list(query)
        for obj in objects:
            if 'a' not in obj:
@@ -142,6 +144,8 @@ class ClientHandler(OnlineCCHandler):
        '''
        Remove a tag of the account with specified login.
        '''
        if tag_name in self._server.RESERVED_TAGS:
            raise ReservedTagError('Tag %r is read-only' % tag_name)
        objects = self._server.list(query)
        for obj in objects:
            if 'a' not in obj: