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.0"
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 for i, x in enumerate(working_target.split(needle)):
58 if ordinal < 1:
59 break
60 index += len(x)
61 ordinal -= 1
62 index += (i * len(needle)) + start_index + 1
63 index = index - (len(needle) - 1)
64 if ordinal != 0:
65 index = -1
66 return index
67
68
70 value = func(user_agent)
71 if value == -1:
72 value = len(user_agent)
73 return value
74
75
77 value = ordinal_index(target, needle, position, start_index)
78 if value == -1:
79 value = len(target)
80 return value
81
82
83 first_space = indexof_or_length
84 first_slash = partial(indexof_or_length, needle=u"/")
85 second_slash = partial(indexof_or_length, needle=u"/", position=2)
86