Hi Ross,

I thought deeply on the implication on using the dist object. There
are many points in favour:

1) Only dist object could be mobile ones from the code, Android -
Iphone - Ipad are all dist objects.
2) If you want to detect Windows Mobile in a near future, you'll
create a new dist object right? Then you can add the is_mobile flag
there.
3) I think that is_mobile flag should be in dist object, because a
Linux could have a dist like ubuntu whithout is_mobile or a dist like
android whit is_mobile = True.

I agree whit you that the is_mobile flag should be on root of the
result object and not on a leaf object as dist, we could copy the flag
if found at the end of detect phase.
Furthermore I think that is a waste copying everey time the is_mobile
flag to the root of result also when the useragent is not mobile.

I think that the detect method should be like this:

    def detect(self, agent, result):
        if agent and self.checkWords(agent):
            result[self.info_type] = Storage(name=self.name)
            is_mobile = getattr(self, 'is_mobile', False)
            if version:
                result[self.info_type].version = version
            if is_mobile:
                result.is_mobile = \
                result[self.info_type].is_mobile = is_mobile
            return True
        return False

The getattr is really a speedy python operation and the "if is_mobile"
is evaluated to True only one time, the one it founds a dist whit
is_mobile = True.

What do you think?

2011/8/24 Ross Peoples <ross.peop...@gmail.com>:
> Forgot to attach, sorry
>
>

Reply via email to