File: discover

package info (click to toggle)
python3-openid 3.0.2%2Bgit20140828-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,672 kB
  • ctags: 2,679
  • sloc: python: 17,137; xml: 234; sh: 15; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
from openid.consumer.discover import discover, DiscoveryFailure
from openid.fetchers import HTTPFetchingError

names = [["server_url",  "Server URL  "],
         ["local_id",    "Local ID    "],
         ["canonicalID", "Canonical ID"],
        ]

def show_services(user_input, normalized, services):
    print " Claimed identifier:", normalized
    if services:
        print " Discovered OpenID services:"
        for n, service in enumerate(services):
            print " %s." % (n,)
            for attr, name in names:
                val = getattr(service, attr, None)
                if val is not None:
                    print "  %s: %s" % (name, val)

            print "  Type URIs:"
            for type_uri in service.type_uris:
                print "   *", type_uri

            print

    else:
        print " No OpenID services found"
        print

if __name__ == "__main__":
    import sys

    for user_input in sys.argv[1:]:
        print "=" * 50
        print "Running discovery on", user_input
        try:
            normalized, services = discover(user_input)
        except DiscoveryFailure, why:
            print "Discovery failed:", why
            print
        except HTTPFetchingError, why:
            print "HTTP request failed:", why
            print
        else:
            show_services(user_input, normalized, services)