473,506 Members | 9,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dispatching operations to user-defined methods

I'm wondering how to design this:

An API to let a request/response LDAP server be configured so a
user-defined Python module can handle and/or modify some or all
incoming operations, and later the outgoing responses (which are
generated by the server). Operations have some common elements,
and some which are distinct to the operation type (search, modify,
compare, etc). So do responses.

There are also some "operations" used internally by the server -
like checking if the current session has access to perform the
operation it requested.

The server will have various internal classes for operations and
data in operations, and methods for the user to access them.

One obvious implementation would be to provide a class Operation,
let the user define a single subclass of this, and have the server
call request_search(), response_search(), request_modify(),
check_access() etc in that subclass.

Then I suppose the server would turn individual operations into
instance of internal subclasses of the user's subclass - class
SearchOperation(<user's class>), ModifyOperation(<user's class>)
etc. Begins to look a bit messy now.

And I'd like to try several methods - first try if the user defined
response_search_entry() (one type of Search operation response),
then response_search(), then response(), and after that give up.
For that one, the Pythonic approach seems to be to define a class
hierarchy for these, let the user subclass the subclasses and define
request() and response() methods for them, and let Python handle the
search for which request() method to use for which operation. And
the server must keep track of which subclasses the user defined.
This too feels a bit messy to me.

Also there are plenty of operation parameters the user might wish to
dispatch on, e.g. maybe he can handle Entry but not Referral search
responses. I imagine it's more efficient to dispatch in a Python C
module than to leave that to the user. But I may be getting too
ambitious now.

Anyway, ideas? Am I overlooking something obvious?

--
Hallvard
May 2 '06 #1
3 1775
I wrote:
I'm wondering how to design this:
(...)
One obvious implementation would be to provide a class Operation,
let the user define a single subclass of this, and have the server
call request_search(), response_search(), request_modify(),
check_access() etc in that subclass.

Then I suppose the server would turn individual operations into
instance of internal subclasses of the user's subclass - class
SearchOperation(<user's class>), ModifyOperation(<user's class>)
etc. Begins to look a bit messy now.
(...)


<Slap head> Or two classes - one operation class and one class
subclassed by the user.

Still need some way to let the user provide both general and more
specialized methods though.

--
Hallvard
May 3 '06 #2
Apparently Guido fell in love with generic functions, so (possibly) in
future Python
versions you will be able to solve dispatching problems in in an
industrial strenght
way. Sometimes however the simplest possible way is enough, and you can
use
something like this :

class SimpleDispatcher(object):
"""A dispatcher is a callable object that looks in a "namespace"
for callable objects and calls them with the signature

``<dispatcher>(<callablename>, <dispatchtag>, <*args>, <**kw>)``

The "namespace" can be a module, a class, a dictionary, or anything
that responds to ``getattr`` or (alternatively) to ``__getitem__``.

Here is an example of usage:
call = SimpleDispatcher(globals()) def manager_showpage(): .... return 'Manager'
def member_showpage(): .... return 'Member'
def anonymous_showpage(): .... return 'Anonymous'
call('showpage', 'anonymous') 'Anonymous' call('showpage', 'manager') 'Manager' call('showpage', 'member')

'Member'
"""
def __init__(self, ns):
self._ns = ns
def __call__(self, funcname, classname, *args, **kw):
try:
func = getattr(self._ns, '%s_%s' % (classname, funcname))
except AttributeError:
func = self._ns['%s_%s' % (class

May 4 '06 #3
Michele Simionato writes:
Apparently Guido fell in love with generic functions, so
(possibly) in future Python versions you will be able to
solve dispatching problems in in an industrial strenght way.
Looks interesting, I'll keep an eye on that.
Sometimes however the simplest possible way is enough, and you
can use something like this :

class SimpleDispatcher(object):
(...)


That doesn't make use of any subclass hierarchies the user defines
though. But maybe it's just as well to scan his class for names
once he has defined it, and build the dispatch table myself.

--
Hallvard
May 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4453
by: teddysnips | last post by:
Currently studying for 70-229. I'm trying to understand how security for users is managed in SQL Server. I've been using SQL Server for a few years now, but without investigating the bits that...
0
1614
by: Edson Tadeu | last post by:
I was thinking in a way to do static dispatching on enumerations, in a way similar to dispatching on integral constants using Loki's Int2Type<> or Boost.MPL's int_<>, i.e, creating types based on...
4
3252
by: Jono | last post by:
Hi Everyone, As it says in the title, I'm looking for a way to display a page while long running operations are performed on the server. Ideally, I'd like some way to push the current request...
7
1576
by: BruceWho | last post by:
Hi, all Is there any mature library which implements a global message dispatching mechanism? I'm playing with wxpython in my spare time, and I like the pubsub or pyDispatch module very much. Any...
0
1151
by: Cesar Zapata | last post by:
I brainstorming on the best way to get this DB working. i'm building a dispatching delivery db this is my idea of set up. TblOrders OrderID OrderDate/Time CustomerID RunID
5
1624
by: Fekri | last post by:
Hi, I'm looking for the best way to dispatch my database to many computers which I don't want any access to the source! my database is for entring the data by users without see what is...
1
1615
by: HopfZ | last post by:
I tried the javascript code dispatching click event to a link in Firefox(2.0.0.4), it does not work, it does trigger onclick handlers but doesn't trigger browser default action, that is, opening...
2
1392
by: Shraddha | last post by:
On which of the following we cannot perform max. operations? 1. Array 2. Hash Table 3. Linked List 4. Heap 5. Bianry Tree
1
1240
by: shaileshkumar | last post by:
i have developed three servlets whose registered names are Demo,Next & Last respectively. //code for dispatching to Next in Demo RequestDispatcher rd=getRequestDispatcher("Next");...
2
1776
by: =?Utf-8?B?d2R1ZGVr?= | last post by:
I have a website using windows integrated security, with anonymous access turned off. The site is used to query orders from a database and when the search takes a long time, a windows login box...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.