OK,
I think I found the problem.
It's located in these two functions.
def detect(self, agent, result):
if agent and self.checkWords(agent):
result[self.info_type] = Storage(name=self.name)
version = self.getVersion(agent)
if version:
result[self.info_type].version = version
return True
return False
def checkWords(self, agent):
for w in self.skip_if_found:
if w in agent:
return False
if self.look_for:
return True
return False
Detect should return true only if agent is not empty and
checkWords(agent) returns true.
The method checkWords(agent) shows a problem, the method return true
when the variable self.look_for exist, and not check if the words in
the useragent really match the ones into look_for variable.
It should be something like this:
def checkWords(self, agent):
for w in self.skip_if_found:
if w in agent:
return False
if self.look_for in agent: <----
return True
return False
Whith this fix it works for me!
Bye!
2011/8/23 Angelo Compagnucci <[email protected]>:
> Hi list,
>
> I'm using user_agent_parser.py from the latest stable version.
>
> I have this user agent:
>
> "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0"
>
> I cannot understand why the code looks for the Opera user agent (I
> have not read carefully the code) but it fails with this error:
>
> File
> "C:\Users\Collaboratore\Documents\HotSpot\MANAGER\web2py\gluon\contrib\user_agent_parser.py",
> line 134, in getVersion
> return agent.split(self.look_for)[1][1:].split(' ')[0]
> IndexError: list index out of range
>
> Clearly the code has a problem:
>
> class Opera(Browser):
> look_for = "Opera"
> def getVersion(self, agent):
> return agent.split(self.look_for)[1][1:].split(' ')[0]
>
> This agent.split(self.look_for)[1] raise an exception when look_for
> returns nothing (as in my case).
>
> I think it should be a sort of checking prior calling getVersion, or
> call getVersion only when the useragent is really Opera!
>
> I'll look forward into the code and I'll try to look for a solution.
>
> Thank you!
>