|
4 | 4 | Stateful programmatic web browsing, after Andy Lester's Perl module |
5 | 5 | WWW::Mechanize. |
6 | 6 |
|
7 | | -The library is layered: mechanize.Browser (stateful web browser), |
8 | | -mechanize.UserAgent (configurable URL opener), plus urllib2 handlers. |
9 | | -
|
10 | | -Features include: ftp:, http: and file: URL schemes, browser history, |
11 | | -high-level hyperlink and HTML form support, HTTP cookies, HTTP-EQUIV and |
12 | | -Refresh, Referer [sic] header, robots.txt, redirections, proxies, and |
13 | | -Basic and Digest HTTP authentication. mechanize's response objects are |
14 | | -(lazily-) .seek()able and still work after .close(). |
15 | | -
|
16 | | -Much of the code originally derived from Perl code by Gisle Aas |
17 | | -(libwww-perl), Johnny Lee (MSIE Cookie support) and last but not least |
18 | | -Andy Lester (WWW::Mechanize). urllib2 was written by Jeremy Hylton. |
| 7 | +mechanize.Browser implements the urllib2.OpenerDirectory interface. Browser |
| 8 | +objects have state, including navigation history, HTML form state, cookies, |
| 9 | +etc. The set of features and URL schemes handled by Browser objects is |
| 10 | +configurable. The library also provides an API that is mostly compatible with |
| 11 | +urllib2: your urllib2 program will likely still work if you replace "urllib2" |
| 12 | +with "mechanize" everywhere. |
| 13 | +
|
| 14 | +Features include: ftp:, http: and file: URL schemes, browser history, hyperlink |
| 15 | +and HTML form support, HTTP cookies, HTTP-EQUIV and Refresh, Referer [sic] |
| 16 | +header, robots.txt, redirections, proxies, and Basic and Digest HTTP |
| 17 | +authentication. |
| 18 | +
|
| 19 | +Much of the code originally derived from Perl code by Gisle Aas (libwww-perl), |
| 20 | +Johnny Lee (MSIE Cookie support) and last but not least Andy Lester |
| 21 | +(WWW::Mechanize). urllib2 was written by Jeremy Hylton. |
19 | 22 |
|
20 | 23 | """ |
21 | 24 |
|
22 | | -def unparse_version(tup): |
23 | | - major, minor, bugfix, state_char, pre = tup |
24 | | - fmt = "%s.%s.%s" |
25 | | - args = [major, minor, bugfix] |
26 | | - if state_char is not None: |
27 | | - fmt += "%s" |
28 | | - args.append(state_char) |
29 | | - if pre is not None: |
30 | | - fmt += "-pre%s" |
31 | | - args.append(pre) |
32 | | - return fmt % tuple(args) |
33 | | - |
34 | | -def str_to_tuple(text): |
35 | | - if text.startswith("("): |
36 | | - text = text[1:-1] |
37 | | - els = [el.strip() for el in text.split(",")] |
38 | | - newEls = [] |
39 | | - for ii in range(len(els)): |
40 | | - el = els[ii] |
41 | | - if el == "None": |
42 | | - newEls.append(None) |
43 | | - elif 0 <= ii < 3: |
44 | | - newEls.append(int(el)) |
45 | | - else: |
46 | | - if el.startswith("'") or el.startswith('"'): |
47 | | - el = el[1:-1] |
48 | | - newEls.append(el) |
49 | | - return tuple(newEls) |
| 25 | +try: |
| 26 | + import setuptools |
| 27 | +except ImportError: |
| 28 | + import ez_setup |
| 29 | + ez_setup.use_setuptools() |
| 30 | + import setuptools |
50 | 31 |
|
51 | | -import re |
52 | | -## VERSION_MATCH = re.search(r'__version__ = \((.*)\)', |
53 | | -## open("mechanize/_mechanize.py").read()) |
54 | | -## VERSION = unparse_version(str_to_tuple(VERSION_MATCH.group(1))) |
55 | 32 | VERSION = "0.1.12" |
56 | | -INSTALL_REQUIRES = ["ClientForm>=0.2.6, ==dev"] |
57 | | -NAME = "mechanize" |
58 | | -PACKAGE = True |
59 | | -LICENSE = "BSD" # or ZPL 2.1 |
60 | | -PLATFORMS = ["any"] |
61 | | -ZIP_SAFE = True |
| 33 | + |
62 | 34 | CLASSIFIERS = """\ |
63 | 35 | Development Status :: 5 - Production/Stable |
64 | 36 | Intended Audience :: Developers |
@@ -92,63 +64,24 @@ def str_to_tuple(text): |
92 | 64 | Topic :: Text Processing :: Markup :: XML |
93 | 65 | """ |
94 | 66 |
|
95 | | -#------------------------------------------------------- |
96 | | -# the rest is constant for most of my released packages: |
97 | | - |
98 | | -import sys |
99 | | - |
100 | | -if PACKAGE: |
101 | | - packages, py_modules = [NAME], None |
102 | | -else: |
103 | | - packages, py_modules = None, [NAME] |
104 | | - |
105 | | -doclines = __doc__.split("\n") |
106 | | - |
107 | | -if not hasattr(sys, "version_info") or sys.version_info < (2, 3): |
108 | | - from distutils.core import setup |
109 | | - _setup = setup |
110 | | - def setup(**kwargs): |
111 | | - for key in [ |
112 | | - # distutils >= Python 2.3 args |
113 | | - # XXX probably download_url came in earlier than 2.3 |
114 | | - "classifiers", "download_url", |
115 | | - # setuptools args |
116 | | - "install_requires", "zip_safe", "test_suite", |
117 | | - ]: |
118 | | - if kwargs.has_key(key): |
119 | | - del kwargs[key] |
120 | | - # Only want packages keyword if this is a package, |
121 | | - # only want py_modules keyword if this is a single-file module, |
122 | | - # so get rid of packages or py_modules keyword as appropriate. |
123 | | - if kwargs["packages"] is None: |
124 | | - del kwargs["packages"] |
125 | | - else: |
126 | | - del kwargs["py_modules"] |
127 | | - apply(_setup, (), kwargs) |
128 | | -else: |
129 | | - import ez_setup |
130 | | - ez_setup.use_setuptools() |
131 | | - from setuptools import setup |
132 | | - |
133 | 67 | def main(): |
134 | | - setup( |
135 | | - name = NAME, |
| 68 | + setuptools.setup( |
| 69 | + name = "mechanize", |
136 | 70 | version = VERSION, |
137 | | - license = LICENSE, |
138 | | - platforms = PLATFORMS, |
| 71 | + license = "BSD", # or ZPL 2.1 |
| 72 | + platforms = ["any"], |
139 | 73 | classifiers = [c for c in CLASSIFIERS.split("\n") if c], |
140 | | - install_requires = INSTALL_REQUIRES, |
141 | | - zip_safe = ZIP_SAFE, |
| 74 | + install_requires = ["ClientForm>=0.2.6, ==dev"], |
| 75 | + zip_safe = True, |
142 | 76 | test_suite = "test", |
143 | 77 | author = "John J. Lee", |
144 | 78 | author_email = "jjl@pobox.com", |
145 | | - description = doclines[0], |
146 | | - long_description = "\n".join(doclines[2:]), |
147 | | - url = "http://wwwsearch.sourceforge.net/%s/" % NAME, |
148 | | - download_url = ("http://wwwsearch.sourceforge.net/%s/src/" |
149 | | - "%s-%s.tar.gz" % (NAME, NAME, VERSION)), |
150 | | - py_modules = py_modules, |
151 | | - packages = packages, |
| 79 | + description = __doc__.split("\n", 1)[0], |
| 80 | + long_description = __doc__.split("\n", 2)[-1], |
| 81 | + url = "http://wwwsearch.sourceforge.net/mechanize/", |
| 82 | + download_url = ("http://wwwsearch.sourceforge.net/mechanize/src/" |
| 83 | + "mechanize-%s.tar.gz" % VERSION), |
| 84 | + packages = ["mechanize"], |
152 | 85 | ) |
153 | 86 |
|
154 | 87 |
|
|
0 commit comments