gnulib-tool-py
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnulib-tool-py] The root of the problem


From: Bruno Haible
Subject: Re: [gnulib-tool-py] The root of the problem
Date: Tue, 26 Jun 2012 20:19 +0200
User-agent: KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; )

Hi Dmitriy,

> 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 = string()
>     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?

Yes, this is how I meant it.

Except that the regular expression that you are applying is not the
one in the original gnulib-tool: '^Description:\n(.*?)\n\n' expects to
find a blank line. Please use the same regular expression as in the
original gnulib-tool (or an equivalent hand-coded search loop).

> Seems now the question turns to opposite: 'can we use the cache always'?

In this case, yes. The code without the cache is just 2 lines shorter than
the code with the cache, and there is no notification happening. So in the
current state, the ability to turn off the cache is not needed.

> Also as I see we can understand cache variable for each value that we get
> using GLModule.get* methods.

Yes.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]