~gary/python-openid/python-openid-2.2.1-patched

« back to all changes in this revision

Viewing changes to openid/server/trustroot.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2007-11-30 02:46:28 UTC
  • mfrom: (1.1.1 pyopenid-2.0)
  • Revision ID: launchpad@pqm.canonical.com-20071130024628-qktwsew3383iawmq
[rs=SteveA] upgrade to python-openid-2.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
    'com|edu|gov|int|mil|net|org|biz|info|name|museum|coop|aero|ac|ad|ae|'
14
14
    'af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|'
15
15
    'bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|'
16
 
    'cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|'
 
16
    'cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|'
17
17
    'fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|'
18
18
    'ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|'
19
19
    'kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|'
27
27
 
28
28
def _parseURL(url):
29
29
    proto, netloc, path, params, query, frag = urlparse(url)
 
30
    if not path:
 
31
        # Python <2.4 does not parse URLs with no path properly
 
32
        if not query and '?' in netloc:
 
33
            netloc, query = netloc.split('?', 1)
 
34
 
 
35
        path = '/'
 
36
 
30
37
    path = urlunparse(('', '', path, params, query, frag))
31
38
 
32
39
    if ':' in netloc:
39
46
        port = ''
40
47
 
41
48
    host = host.lower()
42
 
    if not path:
43
 
        path = '/'
44
 
 
45
49
    return proto, host, port, path
46
50
 
47
51
class TrustRoot(object):
105
109
        if tld not in _top_level_domains:
106
110
            return False
107
111
 
108
 
        if len(tld) == 2:
109
 
            if len(host_parts) == 1:
110
 
                # entire host part is 2-letter tld
111
 
                return False
 
112
        if len(host_parts) == 1:
 
113
            return False
112
114
 
113
 
            if len(host_parts[-2]) <= 3:
 
115
        if self.wildcard:
 
116
            if len(tld) == 2 and len(host_parts[-2]) <= 3:
114
117
                # It's a 2-letter tld with a short second to last segment
115
118
                # so there needs to be more than two segments specified 
116
119
                # (e.g. *.co.uk is insane)
117
120
                return len(host_parts) > 2
118
 
            else:
119
 
                # A long second to last segment is specified.
120
 
                return len(host_parts) > 1
121
 
        else:
122
 
            # It's a regular tld, so it needs at least one more segment
123
 
            return len(host_parts) > 1
124
121
 
125
 
        # Fell through, so not sane
126
 
        return False
 
122
        # Passed all tests for insanity.
 
123
        return True
127
124
 
128
125
    def validateURL(self, url):
129
126
        """
214
211
        if proto not in _protocols:
215
212
            return None
216
213
 
 
214
        # check for URI fragment
 
215
        if path.find('#') != -1:
 
216
            return None
 
217
 
217
218
        # extract wildcard if it is there
218
219
        if host.find('*', 1) != -1:
219
220
            # wildcard must be at start of domain:  *.foo.com, not foo.*.com