[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, debian, updated. upstream/0.9.5.5-717-g0f98819

Sebastian Krzyszkowiak seba.dos1 at gmail.com
Sat Aug 6 08:17:45 UTC 2011


The following commit has been merged in the debian branch:
commit 506df892e1584e7adb14a62b1ed80a93be419753
Author: Sebastian Krzyszkowiak <seba.dos1 at gmail.com>
Date:   Fri Aug 7 23:05:48 2009 +0200

    opimd: Contacts: get rid of SingleQueryHandler - use one from query_manager

diff --git a/framework/subsystems/opimd/pimd_contacts.py b/framework/subsystems/opimd/pimd_contacts.py
index 5d34f28..f516fa3 100644
--- a/framework/subsystems/opimd/pimd_contacts.py
+++ b/framework/subsystems/opimd/pimd_contacts.py
@@ -30,7 +30,7 @@ from domain_manager import DomainManager, Domain
 from helpers import *
 from opimd import *
 
-from query_manager import QueryMatcher
+from query_manager import QueryMatcher, SingleQueryHandler
 
 from framework.config import config, busmap
 
@@ -70,187 +70,6 @@ class Contact(GenericEntry):
 
 
 #----------------------------------------------------------------------------#
-class SingleQueryHandler(object):
-#----------------------------------------------------------------------------#
-    _contacts = None
-    query = None      # The query this handler is processing
-    entries = None
-    cursors = None    # The next entry we'll serve, depending on the client calling us
-
-    def __init__(self, query, contacts, dbus_sender):
-        """Creates a new SingleQueryHandler instance
-
-        @param query Query to evaluate
-        @param contacts Set of Contact objects to use
-        @param dbus_sender Sender's unique name on the bus"""
-
-        self.query = query
-        self.sanitize_query()
-
-        matcher = QueryMatcher(self.query)
-
-        self._contacts = contacts
-        self.entries = matcher.match(self._contacts)
-        self.cursors = {}
-
-        # TODO Register with all contacts to receive updates
-
-
-    def dispose(self):
-        """Unregisters from all contact entries to allow this instance to be eaten by GC"""
-        # TODO Unregister from all contacts
-        pass
-
-
-    def sanitize_query(self):
-        """Makes sure the query meets the criteria that related code uses to omit wasteful sanity checks"""
-
-        # For get_result_and_advance():
-        # Make sure the _result_fields list has no whitespaces, e.g. "a, b, c" should be "a,b,c"
-        # Reasoning: Contact.get_fields() has no fuzzy matching for performance reasons
-        # Also, we remove any empty list elements created by e.g. "a, b, c,"
-        try:
-            field_list = self.query['_result_fields']
-            fields = field_list.split(',')
-            new_field_list = []
-
-            for field_name in fields:
-                field_name = field_name.strip()
-                if field_name: new_field_list.append(field_name)
-
-            self.query['_result_fields'] = ','.join(new_field_list)
-        except KeyError:
-            # There's no _result_fields entry to sanitize
-            pass
-
-
-    def get_result_count(self):
-        """Determines the number of results for this query
-
-        @return Number of result entries"""
-
-        return len(self.entries)
-
-
-    def rewind(self, dbus_sender):
-        """Resets the cursor for a given d-bus sender to the first result entry
-
-        @param dbus_sender Sender's unique name on the bus"""
-
-        self.cursors[dbus_sender] = 0
-
-
-    def skip(self, dbus_sender, num_entries):
-        """Skips n result entries of the result set
-
-        @param dbus_sender Sender's unique name on the bus
-        @param num_entries Number of result entries to skip"""
-
-        if not self.cursors.has_key(dbus_sender): self.cursors[dbus_sender] = 0
-        self.cursors[dbus_sender] += num_entries
-
-
-    def get_contact_path(self, dbus_sender):
-        """Determines the Path of the next contact that the cursor points at and advances to the next result entry
-
-        @param dbus_sender Sender's unique name on the bus
-        @return Path of the contact"""
-
-        # If the sender is not in the list of cursors it just means that it is starting to iterate
-        if not self.cursors.has_key(dbus_sender): self.cursors[dbus_sender] = 0
-
-        # Check whether we've reached the end of the entry list
-        try:
-            result = self.entries[self.cursors[dbus_sender]]
-        except IndexError:
-            raise NoMoreContacts( "All results have been submitted" )
-
-        contact_id = self.entries[self.cursors[dbus_sender]]
-        contact = self._contacts[contact_id]
-        self.cursors[dbus_sender] += 1
-
-        return contact['Path']
-
-
-    def get_result(self, dbus_sender):
-        """Extracts the requested fields from the next contact entry in the result set and advances the cursor
-
-        @param dbus_sender Sender's unique name on the bus
-        @return Dict containing field_name/field_value pairs"""
-
-        # If the sender is not in the list of cursors it just means that it is starting to iterate
-        if not self.cursors.has_key(dbus_sender): self.cursors[dbus_sender] = 0
-
-        # Check whether we've reached the end of the entry list
-        try:
-            result = self.entries[self.cursors[dbus_sender]]
-        except IndexError:
-            raise NoMoreContacts( "All results have been submitted" )
-
-        contact_id = self.entries[self.cursors[dbus_sender]]
-        contact = self._contacts[contact_id]
-        self.cursors[dbus_sender] += 1
-
-        try:
-            fields = self.query['_result_fields']
-            field_list = fields.split(',')
-            result = contact.get_fields(field_list)
-        except KeyError:
-            result = contact.get_content()
-
-        return result
-
-
-    def get_multiple_results(self, dbus_sender, num_entries):
-        """Creates a list containing n dicts which represent the corresponding entries from the result set
-        @note If there are less entries than num_entries, only the available entries will be returned
-
-        @param dbus_sender Sender's unique name on the bus
-        @param num_entries Number of result set entries to return
-        @return List of dicts with field_name/field_value pairs"""
-
-        result = []
-
-        for i in range(num_entries):
-            try:
-                entry = self.get_result(dbus_sender)
-                result.append(entry)
-            except NoMoreContacts:
-                """Don't want to raise an error in that case"""
-                break
-
-        return result
-
-
-    def check_new_contact(self, contact_id):
-        """Checks whether a newly added contact matches this so it can signal clients
-
-        @param contact_id Contact ID of the contact that was added
-        @return True if contact matches this query, False otherwise
-
-        @todo Currently this messes up the order of the result set if a specific order was desired"""
-
-        result = False
-
-        matcher = QueryMatcher(self.query)
-        if matcher.single_entry_matches(self._contacts[contact_id]):
-            self.entries = matcher.match(self._contacts)
-
-            # TODO Register with the new contact to receive changes
-
-            # We *should* reset all cursors *if* the result set is ordered, however
-            # in order to prevent confusion, this is left for the client to do.
-            # Rationale: clients with unordered queries can just use get_result()
-            # and be done with it. For those, theres's no need to re-read all results.
-
-            # Let clients know that this result set changed
-            result = True
-
-        return result
-
-
-
-#----------------------------------------------------------------------------#
 class QueryManager(DBusFBObject):
 #----------------------------------------------------------------------------#
     _queries = None

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list