OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/env python |
2 # | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Copyright 2007 Google Inc. All Rights Reserved. | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
4 | 5 |
5 """Selects the appropriate scraper for a given browser and version.""" | 6 """Selects the appropriate scraper for a given browser and version.""" |
6 | 7 |
7 __author__ = 'jhaas@google.com (Jonathan Haas)' | |
8 | |
9 import types | 8 import types |
10 | 9 |
11 # TODO(jhaas): unify all optional scraper parameters into kwargs | 10 # TODO(jhaas): unify all optional scraper parameters into kwargs |
12 | 11 |
13 def GetScraper(browser): | 12 def GetScraper(browser): |
14 """Given a browser and an optional version, returns the scraper module. | 13 """Given a browser and an optional version, returns the scraper module. |
15 | 14 |
16 Args: | 15 Args: |
17 browser: either a string (browser name) or a tuple (name, version) | 16 browser: either a string (browser name) or a tuple (name, version) |
18 | 17 |
19 Returns: | 18 Returns: |
20 module | 19 module |
21 """ | 20 """ |
22 | 21 |
23 if type(browser) == types.StringType: browser = (browser, None) | 22 if type(browser) == types.StringType: browser = (browser, None) |
24 | 23 |
25 package = __import__(browser[0], globals(), locals(), ['']) | 24 package = __import__(browser[0], globals(), locals(), ['']) |
26 module = package.GetScraper(browser[1]) | 25 module = package.GetScraper(browser[1]) |
27 if browser[1] is not None: module.version = browser[1] | 26 if browser[1] is not None: module.version = browser[1] |
28 | 27 |
29 return module | 28 return module |
30 | 29 |
| 30 |
31 # if invoked rather than imported, do some tests | 31 # if invoked rather than imported, do some tests |
32 if __name__ == "__main__": | 32 if __name__ == "__main__": |
33 print GetScraper("IE") | 33 print GetScraper("IE") |
34 | |
OLD | NEW |