Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6946859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:37:09+00:00 2026-05-27T13:37:09+00:00

Some background: We have a system for transactions where we devide the flow based

  • 0

Some background:
We have a system for transactions where we devide the flow based upon the country the transaction bills to. We have a logging table that exists in 2 instances, one DB logging transactions to the EU, the other to anywhere else. We also have a test library that manages and hides the guts of working with the DB where roughly speaking each table is represented by a class. I have a class that represents the table, and the db session manager class has two members for each of the two instances of the class. What I want to do is create a generic ‘meta dao’ class that will take any arbitrary call to it, inspect the args, and based upon one of the input arguments, subsequently dispatch the call to the correct db instance-representing class instance. I initially thought about just overloading every method, but that’s clunky and dirty.

I was looking at using __getattr__ to override the method lookup so that I could then call down to the correct instance based upon the name of the method __getattr__ recieves, but from what I understand, I can’t inspect the incoming method arguments from within __getattr__, so I can’t properly dispatch from within it in this case. Does anyone have any ideas of a different direction I can pursue, or a way to ‘inspect’ the arguments, not just the method name, from within __getattr__?

[edit] Here’s a genericized version of what I’m talking about:

class BarBase(object):
    def __init__(self, x):
        self.x = x
    def do_bar(self, i):
        return self.x * i

class FooBar(BarBase):
    def __init__(self, x):
        super(FooBar, self).__init__(x)
    def do_foo(self, i):
        return self.x + i

class MetaFoo(object):
    def __init__(self, bar_manager):
        self.foo_manager = bar_manager
    #something here that will take an arbitrary methodname and args as
    #long as args includes a value named i, inspect i, and call
    #bar_manager.fooa.[methodname](args) if i < 10,
    #and bar_manager.foob.[methodname](args) if i >= 10

class BarManager(object):
    def __init__(self):
        self.bar_list = {}
    def __get_fooa(self):
        if 'fooa' not in self.bar_list.keys():
            self.bar_list['fooa'] = FooBar('a')
        return self.bar_list['fooa']
    fooa = property(__get_fooa)
    def __get_foob(self):
        if 'foob' not in self.bar_list.keys():
            self.bar_list['foob'] = FooBar('b')
        return self.bar_list['foob']
    foob = property(__get_foob)
    def __get_foo(self):
        if 'foo' not in self.bar_list.keys():
            self.bar_list['foo'] = MetaFoo(self)
        return self.bar_list['foo']
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:37:10+00:00Added an answer on May 27, 2026 at 1:37 pm

    Somethings along these lines should work:

    class ProxyCall(object):
       '''Class implementing the dispatch for a certain method call'''
       def __init__(self, proxy, methodname):
          self.proxy = proxy
          self.methodname = methodname
    
       def __call__(self, *p, **kw):
          if p[0] == "EU": # or however you determine the destination
             return getattr(self.proxy.EU, self.methodname)(*p, **kw);
          else:
             return getattr(self.proxy.OTHER, self.methodname)(*p, **kw);
    
    
    class Proxy(object):
       '''Class managing the different "equivalent" instances'''
       def __init__(self, EU, OTHER):
          self.EU = EU
          self.OTHER = OTHER
    
       def __getattr__(self, name):
          if not hasattr(self.EU, name):
             # no such method
             raise AttributeError()
          else:
             # return object that supports __call__ and will make the dispatch
             return ProxyCall(self, name)
    

    Then you would create the two instances and combine them in a proxy object:

    eu = make_instance(...)
    other = make_instance(...)
    p = Proxy(eu, other)
    p.somemethod(foo) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some background: we have a windows application (c#) that locate in the system try.
Some background information: We have an ancient web-based document database system where I work,
I have a background thread and the thread calls some methods that update the
I have some code that starts a background process for search in my WPF
I'm looking for suggestions on new development system from some programmers that have more
we have here some problems with our Magento system. First the background : We
Some background: In Germany (at least) invoice numbers have to follow certain rules: The
Skip to the specific question as needed. Some background: The scenario: I have a
I have background music for some songs available in both .MID and .KAR formats,
Background: I have a ListView / GridView with several columns. In some situations, only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.