All Samples(1084) | Call(1041) | Derive(0) | Import(43)
Create an opener object from a list of handlers. The opener will use several default handlers, including support for HTTP, FTP and when applicable, HTTPS. If any of the handlers passed as arguments are subclasses of the default handlers, the default handlers will not be used.
def build_opener(*handlers):
"""Create an opener object from a list of handlers.
The opener will use several default handlers, including support
for HTTP, FTP and when applicable, HTTPS.
If any of the handlers passed as arguments are subclasses of the
default handlers, the default handlers will not be used.
"""
import types
def isclass(obj):
return isinstance(obj, (types.ClassType, type))
opener = OpenerDirector()
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
HTTPDefaultErrorHandler, HTTPRedirectHandler,
FTPHandler, FileHandler, HTTPErrorProcessor]
if hasattr(httplib, 'HTTPS'):
default_classes.append(HTTPSHandler)
skip = set()
for klass in default_classes:
for check in handlers:
if isclass(check):
if issubclass(check, klass):
skip.add(klass)
elif isinstance(check, klass):
skip.add(klass)
for klass in skip:
default_classes.remove(klass)
for klass in default_classes:
opener.add_handler(klass())
for h in handlers:
if isclass(h):
h = h()
opener.add_handler(h)
return opener
'''
from urllib import urlencode
from urllib2 import HTTPBasicAuthHandler, \
HTTPPasswordMgrWithDefaultRealm, \
HTTPRedirectHandler, \
HTTPDefaultErrorHandler, \
passwordManager = HTTPPasswordMgrWithDefaultRealm()
passwordManager.add_password(None, url, username, password)
opener = build_opener(SmartRedirectHandler(),
DefaultErrorHandler(),
HTTPBasicAuthHandler(passwordManager))
passwordManager = HTTPPasswordMgrWithDefaultRealm()
passwordManager.add_password(None, url, username, password)
opener = build_opener(SmartRedirectHandler(),
DefaultErrorHandler(),
HTTPBasicAuthHandler(passwordManager))
passwordManager = HTTPPasswordMgrWithDefaultRealm()
passwordManager.add_password(None, url, username, password)
opener = build_opener(SmartRedirectHandler(),
DefaultErrorHandler(),
HTTPBasicAuthHandler(passwordManager))
passwordManager = HTTPPasswordMgrWithDefaultRealm()
passwordManager.add_password(None, url, username, password)
opener = build_opener(SmartRedirectHandler(),
DefaultErrorHandler(),
HTTPBasicAuthHandler(passwordManager))
src/r/s/rsl-0.2.1/src/rsl/misc/http.py rsl(Download)
from urllib2 import Request as Urllib2Request from urllib2 import HTTPPasswordMgrWithDefaultRealm, BaseHandler from urllib2 import HTTPCookieProcessor from urllib2 import HTTPBasicAuthHandler, build_opener, install_opener from cookielib import LWPCookieJar from httplib import HTTPMessage from StringIO import StringIO
cookie_handler = HTTPCookieProcessor(COOKIEJAR)
auth_handler = HTTPBasicAuthHandler(AskPasswordHandler())
auth_handler.add_password('realm', 'host', 'username', 'password')
OPENER = build_opener(cache_handler, cookie_handler, auth_handler)
install_opener(OPENER)
return OPENER
src/e/a/easynewsgrabber-HEAD/showDownloader.py easynewsgrabber(Download)
if row == 0: print 'I didnt find the following show: ', link.string, ' - I will download it now' from urllib2 import (HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler, build_opener, install_opener, HTTPError, Request, urlopen, URLError ) password_mgr = HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, "http://members.easynews.com/global4/search.html", easyNewsUsername,easyNewsPassword) handler = HTTPBasicAuthHandler(password_mgr) opener = build_opener(handler)
password_mgr = HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, "http://boost4-downloads.members.easynews.com/news/", easyNewsUsername,easyNewsPassword) handler = HTTPBasicAuthHandler(password_mgr) opener = build_opener(handler) install_opener(opener) f = urlopen(downloadLink) print "downloading " + downloadLink
src/p/y/py-smsgv-HEAD/smsgv.py py-smsgv(Download)
def login (self, password):
"""Logs into the Google Account system and receives the cookies into a
file to allow continued use of the Google Voice system."""
if not self.logged_in:# We don't need to repeat this process over and over
from urllib2 import HTTPCookieProcessor, build_opener, install_opener, Request, urlopen
opener = build_opener(HTTPCookieProcessor(self.cookies))
install_opener(opener) # Let Google know we'll accept its nomtastic cookies
src/t/r/trowl-HEAD/src/trowl/job.py trowl(Download)
import pyres, re, urlparse, urllib2, cookielib
from urllib2 import build_opener, HTTPCookieProcessor, HTTPRedirectHandler
from lessly.misc import keystringer
from trowl.util import pquery
BASE_HEADERS = {
'User-Agent' : 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5',
def fetch(self):
"Fetches the url (but does not read from the response)."
self.cookies = cookielib.CookieJar()
self.opener = build_opener( HTTPCookieProcessor(self.cookies), HTTPRedirectHandler )
self.opener.addheaders = BASE_HEADERS.copy().items()
src/e/n/ensemblerewards-HEAD/trunk/python/mailinglist.py ensemblerewards(Download)
import re
from datetime import datetime
from urllib import urlencode
from urllib2 import urlopen, build_opener, install_opener,\
Request, HTTPCookieProcessor
from BeautifulSoup import BeautifulSoup, SoupStrainer
def __init__(self, list_id):
self.list_id = list_id
# Install a cookie jar to handle cookie-based logins.
self._cookie_jar = cookielib.CookieJar()
install_opener(build_opener(HTTPCookieProcessor(self._cookie_jar)))
def login(self, email, password):
src/e/n/ensemblerewards-HEAD/python/mailinglist.py ensemblerewards(Download)
import re
from datetime import datetime
from urllib import urlencode
from urllib2 import urlopen, build_opener, install_opener,\
Request, HTTPCookieProcessor
from BeautifulSoup import BeautifulSoup, SoupStrainer
def __init__(self, list_id):
self.list_id = list_id
# Install a cookie jar to handle cookie-based logins.
self._cookie_jar = cookielib.CookieJar()
install_opener(build_opener(HTTPCookieProcessor(self._cookie_jar)))
def login(self, email, password):
src/p/y/pyMessaging-0.3-r4247/pymessaging/zwitschr.py pyMessaging(Download)
import time import unittest import urllib from urllib2 import build_opener, install_opener, urlopen from urllib2 import Request, HTTPBasicAuthHandler, HTTPPasswordMgrWithDefaultRealm
def send_twitter(self, message):
"""Actually sends a message to Twitter/zwitschr"""
req = Request('http://zwitschr.hudora.biz/api/statuses/update.json')
twit_auth = HTTPPasswordMgrWithDefaultRealm()
twit_auth.add_password(None, 'zwitschr.hudora.biz', self.__username, self.__password)
# install the auth handler built from the HTTPPasswordMgrWithDefaultRealm password manager
install_opener(build_opener(HTTPBasicAuthHandler(twit_auth)))
src/p/y/pywilima-0.2/lib/pywilima.py pywilima(Download)
import sys, logging, time from urllib2 import urlopen, HTTPError, HTTPCookieProcessor, install_opener, build_opener from cookielib import CookieJar from ClientForm import ParseResponse from BeautifulSoup import BeautifulSoup
def install_cookieopener(): # Install opener that handles cookies cj = CookieJar() processor = HTTPCookieProcessor(cj) install_opener(build_opener(processor))
src/s/h/shorty-python-HEAD/shorty.py shorty-python(Download)
""" ## !!! This file is machine generated !! ## from urllib2 import urlopen, Request, URLError, HTTPError, HTTPRedirectHandler, build_opener from urllib import urlencode, quote from urlparse import urlparse from random import randint
return None
def http_error_302(self, req, fp, code, smg, headers):
return None
o = build_opener(StopRedirectHandler())
try:
o.open(url)
except HTTPError, e:
1 | 2 | 3 | 4 | 5 Next