Exemplo n.º 1
0
 def test_orderedDict(self):
     d = util.OrderedDict()
     d['a'] = 'b'
     d['b'] = 'a'
     d[3] = 12
     d[1234] = 4321
     self.assertEqual(repr(d), "{'a': 'b', 'b': 'a', 3: 12, 1234: 4321}")
     self.assertEqual(d.values(), ['b', 'a', 12, 4321])
     del d[3]
     self.assertEqual(repr(d), "{'a': 'b', 'b': 'a', 1234: 4321}")
     self.assertEqual(d, {'a': 'b', 'b': 'a', 1234: 4321})
     self.assertEqual(d.keys(), ['a', 'b', 1234])
     self.assertEqual(list(d.iteritems()), [('a', 'b'), ('b', 'a'),
                                            (1234, 4321)])
     item = d.popitem()
     self.assertEqual(item, (1234, 4321))
Exemplo n.º 2
0
    def __init__(self, id, parent_id, name, store=None, children_callback=None, container_class=DIDLLite.Container):
        BackendItem.__init__(self)
        self.id = id
        self.parent_id = parent_id
        self.name = name
        self.mimetype = 'directory'
        self.item = container_class(id, parent_id, self.name)
        self.item.childCount = 0
        self.update_id = 0
        if children_callback != None:
            self.children = children_callback
        else:
            self.children = util.OrderedDict()

        if store != None:
            self.get_url = lambda: store.urlbase + str(self.id)
Exemplo n.º 3
0
    def __init__(self, state, admin):
        """
        @param state: state of component this is a UI for
        @type  state: L{flumotion.common.planet.AdminComponentState}
        @type  admin: L{flumotion.admin.admin.AdminModel}
        @param admin: the admin model that interfaces with the manager for us
        """
        self._debugEnabled = False
        self.state = state
        self.name = state.get('name')
        self.admin = admin
        self.debug('creating admin gtk for state %r' % state)
        self.uiState = None
        self.nodes = util.OrderedDict()

        d = admin.componentCallRemote(state, 'getUIState')
        d.addCallback(self.setUIState)
        d.addErrback(lambda failure: failure.trap(SleepingComponentError))
Exemplo n.º 4
0
    def test_maintainedOrder(self):
        """
        Entries added to the dict have a maintained order.
        """
        d = util.OrderedDict()
        d['a'] = 'b'
        d['b'] = 'a'
        d[3] = 12
        d[1234] = 4321

        self.assertEqual(list(d.values()), ['b', 'a', 12, 4321])
        del d[3]
        self.assertEqual(d, {'a': 'b', 'b': 'a', 1234: 4321})
        self.assertEqual(list(d.keys()), ['a', 'b', 1234])
        self.assertEqual(list(d.items()), [('a', 'b'), ('b', 'a'),
                                           (1234, 4321)])
        item = d.popitem()
        self.assertEqual(item, (1234, 4321))
Exemplo n.º 5
0
 def __init__(self, state, admin, title=None):
     """
     @param state: state of component this is a UI node for
     @type  state: L{flumotion.common.planet.AdminComponentState}
     @param admin: the admin model that interfaces with the manager for us
     @type  admin: L{flumotion.admin.admin.AdminModel}
     @param title: the (translated) title to show this node with
     @type  title: str
     """
     self._debugEnabled = False
     self.state = state
     self.admin = admin
     self.statusbar = None
     self.title = title
     self.nodes = util.OrderedDict()
     self.wtree = None  # glade.XML instance (optionally set)
     self.widget = None  # the top level widget that will be visible
     self.uiState = None  # set if we are listening
     self._pendingUIState = None  # set if we are waiting for the ui
     # to load
     ## Absolute path to the glade file.
     ##   e.g. "/home/flu/.flumotion/cache/test/80...df7/flumotion/ui.glade
     self._gladefilepath = None
    def testInitialization(self):
        d = util.OrderedDict({'monkey': 'ook', 'apple': 'red'})
        self.failUnless(d._order)

        d = util.OrderedDict(((1, 1), (3, 3), (2, 2), (0, 0)))
        self.assertEqual(repr(d), "{1: 1, 3: 3, 2: 2, 0: 0}")
Exemplo n.º 7
0
 def remove_children(self):
     if not callable(self.children):
         self.children = util.OrderedDict()
         self.item.childCount = 0
Exemplo n.º 8
0
 def __init__(self):
     self.headers = util.OrderedDict()  # map name to list of values
     self.body = ""
     self.finished = 0
Exemplo n.º 9
0
 def _populateFramerates(self, size):
     values = util.OrderedDict()
     for d in self._sizes[size]:
         num, denom = d['framerate']
         values['%.2f fps' % (1.0 * num / denom)] = d
     self.framerate.prefill(values.items())
Exemplo n.º 10
0
 def __init__(self):
     self._objects = util.OrderedDict()
Exemplo n.º 11
0
 def __init__(self, name):
     self._signals = util.OrderedDict()
     self._args = util.OrderedDict()
     self.name = name
Exemplo n.º 12
0
    def start(self, component):
        self.watchable_keycards = watched.WatchedDict(
        )  # keycard id -> Keycard
        self.contexts = {}  # keycard id -> {algorithm name -> result}
        self.algorithms = util.OrderedDict()  # name -> algorithm

        def add_entry(entry, algorithm):
            name = entry['type']
            if name in self.algorithms:
                suffix = 1
                while ('%s-%d' % (name, suffix)) in self.algorithms:
                    suffix += 1
                name = '%s-%d' % (name, suffix)

            assert name not in self.algorithms
            self.algorithms[name] = algorithm
            return name

        # get all algorithm plugs this component has, put them into
        # self.algorithms with unique names
        entries = component.config['plugs'].get(base.BOUNCER_ALGORITHM_SOCKET,
                                                [])
        algorithms = component.plugs.get(base.BOUNCER_ALGORITHM_SOCKET, [])

        if not algorithms:
            m = messages.Error(T_(
                N_("The multibouncerplug requires at least one bouncer "
                   "algorithm plug to be present")),
                               mid='no-algorithm')
            component.addMessage(m)
            raise errors.ComponentSetupHandledError()

        for entry, algorithm in zip(entries, algorithms):
            # add the algorithm to the algorithms dictionary
            name = add_entry(entry, algorithm)
            # provide the algorithm with the keycard store
            algorithm.set_keycard_store(self.watchable_keycards)
            # provide the algorithm with an expiry function crafted especially
            # for it (containing its unique name)
            expire = lambda ids: self.algorithm_expire_keycard_ids(ids, name)
            algorithm.set_expire_function(expire)

        self.debug("configured with algorithms %r", self.algorithms.keys())

        # create the algorithm combinator
        props = self.args['properties']
        self.combinator = combinator.AlgorithmCombinator(self.algorithms)

        if 'combination' in props and combinator.pyparsing is None:
            m = messages.Error(T_(
                N_("To use the 'combination' property you need to "
                   "have the 'pyparsing' module installed.\n")),
                               mid='missing-pyparsing')
            documentation.messageAddPythonInstall(m, 'pyparsing')
            component.addMessage(m)
            raise errors.ComponentSetupHandledError()

        # get the combination specification, defaulting to implicit AND
        spec = props.get('combination', ' and '.join(self.algorithms.keys()))
        self.debug("using combination %s", spec)
        try:
            self.combinator.create_combination(spec)
        except combinator.ParseException, e:
            m = messages.Error(T_(N_("Invalid algorithms combination: %s"),
                                  str(e)),
                               mid='wrong-combination')

            component.addMessage(m)
            raise errors.ComponentSetupHandledError()
Exemplo n.º 13
0
 def remove_children(self):
     if not isinstance(self.children, collections.Callable):
         self.children = util.OrderedDict()
         self.item.childCount = 0
Exemplo n.º 14
0
 def init(self):
     self.watchable_keycards = watched.WatchedDict(
     )  # keycard id -> Keycard
     self.contexts = {}  # keycard id -> {algorithm name -> bool result}
     self.algorithms = util.OrderedDict()  # name -> algorithm instance
     self.combinator = None