it seems that I've finallygraspedthe essence of what we needed. A little example on GLModule and its getDependencies() method:
class GLModule(object): def __init__(self, module, istemp): '''Create new GLModule instance. Arguments are module and istemp, where module is a string representing the path to the module and istemp is a bool
indicating that module was created after applying patch.''' self.args = dict() self.cache = dict() self.data = ""> if type(module) is bytes or type(module) is string: if type(module) is bytes:
module = module.decode(ENCS['default']) else: # if module has not bytes or string type raise(TypeError( 'module must be a string, not %s' % type(module).__name__)) if type(istemp) is not bool:
raise(TypeError( 'istemp must be a bool, not %s' % type(module).__name__)) self.args['module'] = module self.args['istemp'] = istemp with codecs.open(module, 'rb', 'UTF-8') as file:
self.content = file.read()
def getDescription(self) if 'description' not in self.cache: pattern = compiler('^Description:\n(.*?)\n\n') self.cache['description'] = pattern.findall(self.content)[0]
return(self.cache['description'])
Hope I've understood correctly this time? Also as I see we can understand cache variable for each value that we get using GLModule.get* methods.
> I think what you are describing here is the translated implementation
> of func_modules_transitive_closure? Yes, I wanted to explain what I've understood rather than to tell how I can translate this code line-by-line.
>
If you can achieve this goal without a cache, sure, do it.
Seems now the question turns to opposite: 'can we use the cache always'?
> As discussed a couple of days ago, let's only throw exceptions for the > moment, and not catch/handle them. Yep, I was talking about the future. :-)
> Do *not* design things so as to assume that there is a global variable
> such as "the list of all modules". Instead, we need a data structure > (possibly a class? possibly only a combination of a 'dict' and a list?) that > represents a list of modules. We will need at least 3, maybe more, instances
> of this data structure. Sure, I'll do this.
If I've catched the aim, I can start work now. Seems that due to my dullness has frozen the work yesterday because I read the code many times and couldn't understand it. I'm really sorry for the delay.