1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 __doc__ = """
21 This module contains the supporting classes for the Two Step Analysis user agent
22 algorithm that is used as the primary way to match user agents with the Java API
23 for the WURFL.
24
25 A description of the way the following source is intended to work can be found
26 within the source for the original Java API implementation here:
27 http://sourceforge.net/projects/wurfl/files/WURFL Java API/
28
29 The original Java code is GPLd and Copyright (c) 2008-2009 WURFL-Pro srl
30 """
31
32 __author__ = "Armand Lynch <lyncha@users.sourceforge.net>"
33 __copyright__ = "Copyright 2010, Armand Lynch"
34 __license__ = "LGPL"
35 __url__ = "http://celljam.net/"
36 __version__ = "1.0.1"
37
38 from functools import partial
39
40
42 user_agent = user_agent.lower()
43 mobile_browsers = [u"tablet", u"mobile", u"wireless", u"palm", u"blazer",
44 u"netfront", u"symbian", u"bolt", u"iris", u"pocketpc"]
45 for mb in mobile_browsers:
46 if mb in user_agent:
47 return True
48 return False
49
50
52 index = -1
53
54 working_target = target[start_index+1:]
55
56 if needle in working_target:
57 i = 0
58 for i, x in enumerate(working_target.split(needle)):
59 if ordinal < 1:
60 break
61 index += len(x)
62 ordinal -= 1
63 index += (i * len(needle)) + start_index + 1
64 index = index - (len(needle) - 1)
65 if ordinal != 0:
66 index = -1
67 return index
68
69
71 value = func(user_agent)
72 if value == -1:
73 value = len(user_agent)
74 return value
75
76
78 value = ordinal_index(target, needle, position, start_index)
79 if value == -1:
80 value = len(target)
81 return value
82
83
84 first_space = indexof_or_length
85 first_slash = partial(indexof_or_length, needle=u"/")
86 second_slash = partial(indexof_or_length, needle=u"/", position=2)
87 first_semi_colon = partial(indexof_or_length, needle=u";")
88