Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: third_party/twisted_8_1/twisted/names/hosts.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4
5 from twisted.names import dns
6 from twisted.persisted import styles
7 from twisted.python import failure
8 from twisted.internet import defer
9
10 from twisted.names import common
11
12 def searchFileFor(file, name):
13 try:
14 fp = open(file)
15 except:
16 return None
17
18 lines = fp.readlines()
19 for line in lines:
20 idx = line.find('#')
21 if idx != -1:
22 line = line[:idx]
23 if not line:
24 continue
25 parts = line.split()
26 if name.lower() in [s.lower() for s in parts[1:]]:
27 return parts[0]
28 return None
29
30
31
32 class Resolver(common.ResolverBase, styles.Versioned):
33 """A resolver that services hosts(5) format files."""
34 #TODO: IPv6 support
35
36 persistenceVersion = 1
37
38 def upgradeToVersion1(self):
39 # <3 exarkun
40 self.typeToMethod = {}
41 for (k, v) in common.typeToMethod.items():
42 self.typeToMethod[k] = getattr(self, v)
43
44
45 def __init__(self, file='/etc/hosts', ttl = 60 * 60):
46 common.ResolverBase.__init__(self)
47 self.file = file
48 self.ttl = ttl
49
50
51 def lookupAddress(self, name, timeout = None):
52 res = searchFileFor(self.file, name)
53 if res:
54 return defer.succeed([
55 (dns.RRHeader(name, dns.A, dns.IN, self.ttl, dns.Record_A(res, s elf.ttl)),), (), ()
56 ])
57 return defer.fail(failure.Failure(dns.DomainError(name)))
58
59
60 # When we put IPv6 support in, this'll need a real impl
61 lookupAllRecords = lookupAddress
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/names/error.py ('k') | third_party/twisted_8_1/twisted/names/resolve.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698