jerry wrote: >> That's insightful for me thank you. Actually I've been staring at >> env.py/Environment/get_db_cnx for the past 30 minutes, because the one >> statement that is in it in it is confusing to this python n00b >> >> class Environment >> def get_db_cnx(self): >> return DatabaseManager(self).get_connection() >> >> How does that reference to DatabaseManager(self) work? >> >> When I look at trac/db/api.py, I see: >> class DatabaseManager >> def __init__(self): >> ... >> >> Why does Environment/get_db_cnx need to send a reference to itself to >> DatabaseManager, and what method in DatabaseManager is answering that >> reference? If it is __init__ how come it's __init__ doesn't look >> like: >> def __init__(self, env) >> ... >> >> Can you help me understand this? >> > > Well, I've come a bit farther on that. First the code is not: > class DatabaseManager > but > class DatabaseManager(Component) > > And what is called is not initially > DatabaseManager.__init__(self) > but > Component.__new__(cls, *args, **kwargs) > where args[0] is expected to exist in the code. > > (Thanks to pdb and emacs for helping me get that. Still not clear > when and how DM.__init__(self) is called, but tomorrow is another > day?) >
Well, while it's good that you're looking by yourself at the code, you'll also find useful overviews starting from http://trac.edgewall.org/wiki/TracDev, in particular look at the component architecture. In short: the Component instances are "singletons" only within the scope of a ComponentManager instance, an Environment is a ComponentManager, and there is one Environment instance for each Trac environment that gets "opened" by the application. Further details in trac/core.py and trac/env.py. -- Christian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Trac Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/trac-dev?hl=en -~----------~----~----~----~------~----~------~--~---
