This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5242d1
commit c341809
Showing
56 changed files
with
14,363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
__all__ = [ | ||
'AbstractBasicAuthHandler', | ||
'AbstractDigestAuthHandler', | ||
'BaseHandler', | ||
'Browser', | ||
'BrowserStateError', | ||
'CacheFTPHandler', | ||
'ContentTooShortError', | ||
'Cookie', | ||
'CookieJar', | ||
'CookiePolicy', | ||
'DefaultCookiePolicy', | ||
'DefaultFactory', | ||
'FTPHandler', | ||
'Factory', | ||
'FileCookieJar', | ||
'FileHandler', | ||
'FormNotFoundError', | ||
'FormsFactory', | ||
'HTTPBasicAuthHandler', | ||
'HTTPCookieProcessor', | ||
'HTTPDefaultErrorHandler', | ||
'HTTPDigestAuthHandler', | ||
'HTTPEquivProcessor', | ||
'HTTPError', | ||
'HTTPErrorProcessor', | ||
'HTTPHandler', | ||
'HTTPPasswordMgr', | ||
'HTTPPasswordMgrWithDefaultRealm', | ||
'HTTPProxyPasswordMgr', | ||
'HTTPRedirectDebugProcessor', | ||
'HTTPRedirectHandler', | ||
'HTTPRefererProcessor', | ||
'HTTPRefreshProcessor', | ||
'HTTPResponseDebugProcessor', | ||
'HTTPRobotRulesProcessor', | ||
'HTTPSClientCertMgr', | ||
'HeadParser', | ||
'History', | ||
'LWPCookieJar', | ||
'Link', | ||
'LinkNotFoundError', | ||
'LinksFactory', | ||
'LoadError', | ||
'MSIECookieJar', | ||
'MozillaCookieJar', | ||
'OpenerDirector', | ||
'OpenerFactory', | ||
'ParseError', | ||
'ProxyBasicAuthHandler', | ||
'ProxyDigestAuthHandler', | ||
'ProxyHandler', | ||
'Request', | ||
'RobotExclusionError', | ||
'RobustFactory', | ||
'RobustFormsFactory', | ||
'RobustLinksFactory', | ||
'RobustTitleFactory', | ||
'SeekableResponseOpener', | ||
'TitleFactory', | ||
'URLError', | ||
'USE_BARE_EXCEPT', | ||
'UnknownHandler', | ||
'UserAgent', | ||
'UserAgentBase', | ||
'XHTMLCompatibleHeadParser', | ||
'__version__', | ||
'build_opener', | ||
'install_opener', | ||
'lwp_cookie_str', | ||
'make_response', | ||
'request_host', | ||
'response_seek_wrapper', # XXX deprecate in public interface? | ||
'seek_wrapped_response', # XXX should probably use this internally in place of response_seek_wrapper() | ||
'str2time', | ||
'urlopen', | ||
'urlretrieve', | ||
'urljoin', | ||
|
||
# ClientForm API | ||
'AmbiguityError', | ||
'ControlNotFoundError', | ||
'FormParser', | ||
'ItemCountError', | ||
'ItemNotFoundError', | ||
'LocateError', | ||
'Missing', | ||
'ParseFile', | ||
'ParseFileEx', | ||
'ParseResponse', | ||
'ParseResponseEx', | ||
'ParseString', | ||
'XHTMLCompatibleFormParser', | ||
# deprecated | ||
'CheckboxControl', | ||
'Control', | ||
'FileControl', | ||
'HTMLForm', | ||
'HiddenControl', | ||
'IgnoreControl', | ||
'ImageControl', | ||
'IsindexControl', | ||
'Item', | ||
'Label', | ||
'ListControl', | ||
'PasswordControl', | ||
'RadioControl', | ||
'ScalarControl', | ||
'SelectControl', | ||
'SubmitButtonControl', | ||
'SubmitControl', | ||
'TextControl', | ||
'TextareaControl', | ||
] | ||
|
||
import logging | ||
import sys | ||
|
||
from _version import __version__ | ||
|
||
# high-level stateful browser-style interface | ||
from _mechanize import \ | ||
Browser, History, \ | ||
BrowserStateError, LinkNotFoundError, FormNotFoundError | ||
|
||
# configurable URL-opener interface | ||
from _useragent import UserAgentBase, UserAgent | ||
from _html import \ | ||
Link, \ | ||
Factory, DefaultFactory, RobustFactory, \ | ||
FormsFactory, LinksFactory, TitleFactory, \ | ||
RobustFormsFactory, RobustLinksFactory, RobustTitleFactory | ||
|
||
# urllib2 work-alike interface. This is a superset of the urllib2 interface. | ||
from _urllib2 import * | ||
import _urllib2 | ||
if hasattr(_urllib2, "HTTPSHandler"): | ||
__all__.append("HTTPSHandler") | ||
del _urllib2 | ||
|
||
# misc | ||
from _http import HeadParser | ||
from _http import XHTMLCompatibleHeadParser | ||
from _opener import ContentTooShortError, OpenerFactory, urlretrieve | ||
from _response import \ | ||
response_seek_wrapper, seek_wrapped_response, make_response | ||
from _rfc3986 import urljoin | ||
from _util import http2time as str2time | ||
|
||
# cookies | ||
from _clientcookie import Cookie, CookiePolicy, DefaultCookiePolicy, \ | ||
CookieJar, FileCookieJar, LoadError, request_host_lc as request_host, \ | ||
effective_request_host | ||
from _lwpcookiejar import LWPCookieJar, lwp_cookie_str | ||
# 2.4 raises SyntaxError due to generator / try/finally use | ||
if sys.version_info[:2] > (2,4): | ||
try: | ||
import sqlite3 | ||
except ImportError: | ||
pass | ||
else: | ||
from _firefox3cookiejar import Firefox3CookieJar | ||
from _mozillacookiejar import MozillaCookieJar | ||
from _msiecookiejar import MSIECookieJar | ||
|
||
# forms | ||
from _form import ( | ||
AmbiguityError, | ||
ControlNotFoundError, | ||
FormParser, | ||
ItemCountError, | ||
ItemNotFoundError, | ||
LocateError, | ||
Missing, | ||
ParseError, | ||
ParseFile, | ||
ParseFileEx, | ||
ParseResponse, | ||
ParseResponseEx, | ||
ParseString, | ||
XHTMLCompatibleFormParser, | ||
# deprecated | ||
CheckboxControl, | ||
Control, | ||
FileControl, | ||
HTMLForm, | ||
HiddenControl, | ||
IgnoreControl, | ||
ImageControl, | ||
IsindexControl, | ||
Item, | ||
Label, | ||
ListControl, | ||
PasswordControl, | ||
RadioControl, | ||
ScalarControl, | ||
SelectControl, | ||
SubmitButtonControl, | ||
SubmitControl, | ||
TextControl, | ||
TextareaControl, | ||
) | ||
|
||
# If you hate the idea of turning bugs into warnings, do: | ||
# import mechanize; mechanize.USE_BARE_EXCEPT = False | ||
USE_BARE_EXCEPT = True | ||
|
||
logger = logging.getLogger("mechanize") | ||
if logger.level is logging.NOTSET: | ||
logger.setLevel(logging.CRITICAL) | ||
del logger |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""HTTP Authentication and Proxy support. | ||
Copyright 2006 John J. Lee <[email protected]> | ||
This code is free software; you can redistribute it and/or modify it under | ||
the terms of the BSD or ZPL 2.1 licenses (see the file COPYING.txt | ||
included with the distribution). | ||
""" | ||
|
||
from _urllib2_fork import HTTPPasswordMgr | ||
|
||
|
||
# TODO: stop deriving from HTTPPasswordMgr | ||
class HTTPProxyPasswordMgr(HTTPPasswordMgr): | ||
# has default realm and host/port | ||
def add_password(self, realm, uri, user, passwd): | ||
# uri could be a single URI or a sequence | ||
if uri is None or isinstance(uri, basestring): | ||
uris = [uri] | ||
else: | ||
uris = uri | ||
passwd_by_domain = self.passwd.setdefault(realm, {}) | ||
for uri in uris: | ||
for default_port in True, False: | ||
reduced_uri = self.reduce_uri(uri, default_port) | ||
passwd_by_domain[reduced_uri] = (user, passwd) | ||
|
||
def find_user_password(self, realm, authuri): | ||
attempts = [(realm, authuri), (None, authuri)] | ||
# bleh, want default realm to take precedence over default | ||
# URI/authority, hence this outer loop | ||
for default_uri in False, True: | ||
for realm, authuri in attempts: | ||
authinfo_by_domain = self.passwd.get(realm, {}) | ||
for default_port in True, False: | ||
reduced_authuri = self.reduce_uri(authuri, default_port) | ||
for uri, authinfo in authinfo_by_domain.iteritems(): | ||
if uri is None and not default_uri: | ||
continue | ||
if self.is_suburi(uri, reduced_authuri): | ||
return authinfo | ||
user, password = None, None | ||
|
||
if user is not None: | ||
break | ||
return user, password | ||
|
||
def reduce_uri(self, uri, default_port=True): | ||
if uri is None: | ||
return None | ||
return HTTPPasswordMgr.reduce_uri(self, uri, default_port) | ||
|
||
def is_suburi(self, base, test): | ||
if base is None: | ||
# default to the proxy's host/port | ||
hostport, path = test | ||
base = (hostport, "/") | ||
return HTTPPasswordMgr.is_suburi(self, base, test) | ||
|
||
|
||
class HTTPSClientCertMgr(HTTPPasswordMgr): | ||
# implementation inheritance: this is not a proper subclass | ||
def add_key_cert(self, uri, key_file, cert_file): | ||
self.add_password(None, uri, key_file, cert_file) | ||
def find_key_cert(self, authuri): | ||
return HTTPPasswordMgr.find_user_password(self, None, authuri) |
Binary file not shown.
Oops, something went wrong.