当前位置: 首页>>代码示例>>Python>>正文


Python HTTPDigestAuthHandler.add_password方法代码示例

本文整理汇总了Python中urllib2.HTTPDigestAuthHandler.add_password方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPDigestAuthHandler.add_password方法的具体用法?Python HTTPDigestAuthHandler.add_password怎么用?Python HTTPDigestAuthHandler.add_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib2.HTTPDigestAuthHandler的用法示例。


在下文中一共展示了HTTPDigestAuthHandler.add_password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, attendeeCount, samples):
    user = password = "user01"
    root = "/"
    principal = "/"
    calendar = "event-creation-benchmark"

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri="http://%s:%d/" % (host, port),
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # First set things up
    yield initialize(agent, host, port, user, password, root, principal, calendar)

    method = 'PUT'
    uri = 'http://%s:%d/calendars/__uids__/%s/%s/foo-%%d.ics' % (
        host, port, user, calendar)
    headers = Headers({"content-type": ["text/calendar"]})

    # An infinite stream of VEVENTs to PUT to the server.
    events = ((i, makeEvent(i, attendeeCount)) for i in count(2))

    # Sample it a bunch of times
    samples = yield sample(
        dtrace, samples, 
        agent, ((method, uri % (i,), headers, StringProducer(body))
                for (i, body)
                in events).next)
    returnValue(samples)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:34,代码来源:event.py

示例2: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, attendeeCount, samples, fieldName,
            replacer, eventPerSample=False):
    user = password = "user01"
    root = "/"
    principal = "/"
    calendar = "event-%s-benchmark" % (fieldName,)

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri="http://%s:%d/" % (host, port),
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # Set up the calendar first
    yield initialize(agent, host, port, user, password, root, principal, calendar)

    if eventPerSample:
        # Create an event for each sample that will be taken, so that no event
        # is used for two different samples.
        f = _selfish_sample
    else:
        # Just create one event and re-use it for all samples.
        f = _generous_sample

    data = yield f(
        dtrace, replacer, agent, host, port, user, calendar, fieldName,
        attendeeCount, samples)
    returnValue(data)
开发者ID:nunb,项目名称:calendarserver,代码行数:32,代码来源:_event_change.py

示例3: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, events, samples):
    user = password = "user01"
    root = "/"
    principal = "/"
    calendar = "vfreebusy-benchmark"

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri="http://%s:%d/" % (host, port),
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # First set things up
    account = yield initialize(
        agent, host, port, user, password, root, principal, calendar)

    base = "/calendars/users/%s/%s/foo-%%d.ics" % (user, calendar)
    for i, cal in enumerate(makeEvents(events)):
        yield account.writeData(base % (i,), cal, "text/calendar")

    method = 'POST'
    uri = 'http://%s:%d/calendars/__uids__/%s/outbox/' % (host, port, user)
    headers = Headers({"content-type": ["text/calendar"]})
    body = StringProducer(vfreebusy)

    samples = yield sample(
        dtrace, samples,
        agent, lambda: (method, uri, headers, body))
    returnValue(samples)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:33,代码来源:vfreebusy.py

示例4: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(calendar, organizerSequence, events, host, port, dtrace, samples):
    """
    Benchmark event creation.
    """
    user = password = "user%02d" % (organizerSequence,)
    root = "/"
    principal = "/"

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri="http://%s:%d/" % (host, port),
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # First set things up
    yield initialize(agent, host, port, user, password, root, principal, calendar)

    method = 'PUT'
    uri = 'http://%s:%d/calendars/__uids__/%s/%s/foo-%%d.ics' % (
        host, port, user, calendar)
    headers = Headers({"content-type": ["text/calendar"]})

    # Sample it a bunch of times
    samples = yield sample(
        dtrace, samples,
        agent, ((method, uri % (i,), headers, StringProducer(body))
                for (i, body)
                in events).next,
        CREATED)
    returnValue(samples)
开发者ID:anemitz,项目名称:calendarserver,代码行数:34,代码来源:_event_create.py

示例5: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, attendeeCount, samples):
    organizerSequence = 1
    user = password = "user%02d" % (organizerSequence,)
    root = "/"
    principal = "/"

    # Two calendars between which to move the event.
    fooCalendar = "event-move-foo-benchmark"
    barCalendar = "event-move-bar-benchmark"

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(realm="Test Realm", uri="http://%s:%d/" % (host, port), user=user, passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # Set up the calendars first
    for calendar in [fooCalendar, barCalendar]:
        yield initialize(agent, host, port, user, password, root, principal, calendar)

    fooURI = "http://%s:%d/calendars/__uids__/%s/%s/some-event.ics" % (host, port, user, fooCalendar)
    barURI = "http://%s:%d/calendars/__uids__/%s/%s/some-event.ics" % (host, port, user, barCalendar)

    # Create the event that will move around
    headers = Headers({"content-type": ["text/calendar"]})
    yield agent.request("PUT", fooURI, headers, StringProducer(makeEvent(1, organizerSequence, attendeeCount)))

    # Move it around sooo much
    source = cycle([fooURI, barURI])
    dest = cycle([barURI, fooURI])

    params = (("MOVE", source.next(), Headers({"destination": [dest.next()], "overwrite": ["F"]})) for i in count(1))

    samples = yield sample(dtrace, samples, agent, params.next, CREATED)
    returnValue(samples)
开发者ID:eventable,项目名称:CalendarServer,代码行数:35,代码来源:event_move.py

示例6: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, attendees, samples):
    userNumber = 1
    user = password = "user%02d" % (userNumber,)
    root = "/"
    principal = "/"
    calendar = "vfreebusy-vary-attendees-benchmark"

    targets = range(2, attendees + 2)

    authinfo = HTTPDigestAuthHandler()

    # Set up authentication info for our own user and all the other users that
    # may need an event created on one of their calendars.
    for i in [userNumber] + targets:
        targetUser = "user%02d" % (i,)
        for path in ["calendars/users/%s/" % (targetUser,),
                     "calendars/__uids__/10000000-0000-0000-0000-000000000%03d/" % (i,)]:
            authinfo.add_password(
                realm="Test Realm",
                uri="http://%s:%d/%s" % (host, port, path),
                user=targetUser, passwd=targetUser)

    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # Set up events on about half of the target accounts
    baseTime = datetime.now().replace(minute=45, second=0, microsecond=0)
    for i in targets[::2]:
        targetUser = "user%02d" % (i,)
        account = CalDAVAccount(
            agent,
            "%s:%d" % (host, port),
            user=targetUser, password=password,
            root=root, principal=principal)
        cal = "/calendars/users/%s/%s/" % (targetUser, calendar)
        yield account.deleteResource(cal)
        yield account.makeCalendar(cal)
        yield account.writeData(cal + "foo.ics", makeEventNear(baseTime, i), "text/calendar")

    # And now issue the actual VFREEBUSY request
    method = 'POST'
    uri = 'http://%s:%d/calendars/__uids__/10000000-0000-0000-0000-000000000001/outbox/' % (host, port)
    headers = Headers({
            "content-type": ["text/calendar"],
            "originator": ["mailto:%[email protected]" % (user,)],
            "recipient": [", ".join(["urn:x-uid:10000000-0000-0000-0000-000000000%03d" % (i,) for i in [userNumber] + targets])]})
    body = StringProducer(VFREEBUSY % {
            "attendees": "".join([
                    "ATTENDEE:urn:x-uid:10000000-0000-0000-0000-000000000%03d\n" % (i,)
                    for i in [userNumber] + targets]),
            "start": formatDate(baseTime.replace(hour=0, minute=0)) + 'Z',
            "end": formatDate(
                baseTime.replace(hour=0, minute=0) + timedelta(days=1)) + 'Z'})

    samples = yield sample(
        dtrace, samples,
        agent, lambda: (method, uri, headers, body),
        OK)

    returnValue(samples)
开发者ID:nunb,项目名称:calendarserver,代码行数:61,代码来源:vfreebusy_vary_attendees.py

示例7: Client

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
class Client(object):
    """
    An Exscriptd client that communicates via HTTP.
    """

    def __init__(self, address, user, password):
        """
        Constructor. Any operations performed with an
        instance of a client are directed to the server with the
        given address, using the given login data.

        @type  address: str
        @param address: The base url of the server.
        @type  user: str
        @param user: The login name on the server.
        @type  password: str
        @param password: The password of the user.
        """
        self.address = 'http://' + address
        self.handler = HTTPDigestAuthHandler()
        self.opener  = build_opener(self.handler)
        self.handler.add_password(realm  = default_realm,
                                  uri    = self.address,
                                  user   = user,
                                  passwd = password)

    def place_order(self, order):
        """
        Sends the given order to the server, and updates the status
        of the order accordingly.

        @type  order: Order
        @param order: The order that is placed.
        """
        if order.status != 'new':
            msg = 'order status is "%s", should be "new"' % order.status
            raise ValueError(msg)
        if not order.is_valid():
            raise ValueError('incomplete or invalid order')

        order.status = 'accepted'
        url          = self.address + '/order/'
        xml          = order.toxml()
        data         = urlencode({'xml': xml})
        try:
            result = self.opener.open(url, data)
        except HTTPError, e:
            if hasattr(e, 'read'):
                raise Exception(str(e) + ' with ' + e.read())
            else:
                raise Exception(str(e))
        if result.getcode() != 200:
            raise Exception(result.read())
        order.id = json.loads(result.read())
开发者ID:amito,项目名称:exscript,代码行数:56,代码来源:Client.py

示例8: _createUser

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
 def _createUser(self, number):
     record = self._records[number]
     user = record.uid
     authBasic = HTTPBasicAuthHandler()
     authBasic.add_password(
         realm="Test Realm",
         uri=self.server,
         user=user.encode('utf-8'),
         passwd=record.password.encode('utf-8'))
     authDigest = HTTPDigestAuthHandler()
     authDigest.add_password(
         realm="Test Realm",
         uri=self.server,
         user=user.encode('utf-8'),
         passwd=record.password.encode('utf-8'))
     return user, {"basic": authBasic, "digest": authDigest, }
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:18,代码来源:population.py

示例9: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, events, samples):
    user = password = "user01"
    uid = "10000000-0000-0000-0000-000000000001"
    root = "/"
    principal = "/"
    calendar = "vfreebusy-benchmark"

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri="http://%s:%d/" % (host, port),
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # First set things up
    account = yield initialize(
        agent, host, port, user, password, root, principal, calendar)

    base = "/calendars/users/%s/%s/foo-%%d.ics" % (user, calendar)
    baseTime = datetime.now().replace(hour=12, minute=15, second=0, microsecond=0)
    for i, cal in enumerate(makeEvents(baseTime, events)):
        yield account.writeData(base % (i,), cal, "text/calendar")

    method = 'POST'
    uri = 'http://%s:%d/calendars/__uids__/%s/outbox/' % (host, port, user)
    headers = Headers({
        "content-type": ["text/calendar"],
        "originator": ["mailto:%[email protected]" % (user,)],
        "recipient": ["urn:x-uid:%s, urn:x-uid:10000000-0000-0000-0000-000000000002" % (uid,)]})

    vfb = VFREEBUSY % {
        "attendees": "".join([
            "ATTENDEE:urn:x-uid:%s\n" % (uid,),
            "ATTENDEE:urn:x-uid:10000000-0000-0000-0000-000000000002\n"]),
        "start": formatDate(baseTime.replace(hour=0, minute=0)) + 'Z',
        "end": formatDate(
            baseTime.replace(hour=0, minute=0) + timedelta(days=1)) + 'Z'}
    body = StringProducer(vfb.replace("\n", "\r\n"))

    samples = yield sample(
        dtrace, samples,
        agent, lambda: (method, uri, headers, body),
        OK)
    returnValue(samples)
开发者ID:eventable,项目名称:CalendarServer,代码行数:47,代码来源:vfreebusy.py

示例10: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, numCalendars, samples):
    # There's already the "calendar" calendar
    numCalendars -= 1

    user = password = "user10"
    root = "/"
    principal = "/"

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri="http://%s:%d/" % (host, port),
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # Create the number of calendars necessary
    account = CalDAVAccount(
        agent,
        "%s:%d" % (host, port),
        user=user, password=password,
        root=root, principal=principal)
    cal = "/calendars/users/%s/propfind-%%d/" % (user,)
    for i in range(numCalendars):
        yield account.makeCalendar(cal % (i,))

    body = StringProducer(PROPFIND)
    params = (
        ('PROPFIND', 'http://%s:%d/calendars/__uids__/%s/' % (host, port, user),
         Headers({"depth": ["1"], "content-type": ["text/xml"]}), body)
        for i in count(1))

    samples = yield sample(dtrace, samples, agent, params.next, MULTI_STATUS)

    # Delete the calendars we created to leave the server in roughly
    # the same state as we found it.
    for i in range(numCalendars):
        yield account.deleteResource(cal % (i,))

    returnValue(samples)
开发者ID:nunb,项目名称:calendarserver,代码行数:42,代码来源:find_calendars.py

示例11: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, numEvents, samples):
    user = password = "user11"
    root = "/"
    principal = "/"

    uri = "http://%s:%d/" % (host, port)
    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri=uri,
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # Create the number of calendars necessary
    account = CalDAVAccount(
        agent,
        "%s:%d" % (host, port),
        user=user, password=password,
        root=root, principal=principal)
    cal = "calendars/users/%s/find-events/" % (user,)
    yield account.makeCalendar("/" + cal)

    # Create the indicated number of events on the calendar
    yield uploadEvents(numEvents, agent, uri, cal)

    body = StringProducer(PROPFIND)
    params = (
        ('PROPFIND',
         '%scalendars/__uids__/%s/find-events/' % (uri, user),
         Headers({"depth": ["1"], "content-type": ["text/xml"]}), body)
        for i in count(1))

    samples = yield sample(dtrace, samples, agent, params.next, MULTI_STATUS)

    # Delete the calendar we created to leave the server in roughly
    # the same state as we found it.
    yield account.deleteResource("/" + cal)

    returnValue(samples)
开发者ID:anemitz,项目名称:calendarserver,代码行数:42,代码来源:find_events.py

示例12: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, attendeeCount, samples):
    organizerSequence = 1
    user = password = "user%02d" % (organizerSequence,)
    root = "/"
    principal = "/"
    calendar = "event-deletion-benchmark"

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri="http://%s:%d/" % (host, port),
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # Set up the calendar first
    yield initialize(agent, host, port, user, password, root, principal, calendar)

    # An infinite stream of VEVENTs to PUT to the server.
    events = ((i, makeEvent(i, organizerSequence, attendeeCount))
              for i in count(2))

    # Create enough events to delete
    uri = 'http://%s:%d/calendars/__uids__/%s/%s/foo-%%d.ics' % (
        host, port, user, calendar)
    headers = Headers({"content-type": ["text/calendar"]})
    urls = []
    for i, body in events:
        urls.append(uri % (i,))
        yield agent.request(
            'PUT', urls[-1], headers, StringProducer(body))
        if len(urls) == samples:
            break

    # Now delete them all
    samples = yield sample(
        dtrace, samples,
        agent, (('DELETE', url) for url in urls).next,
        NO_CONTENT)
    returnValue(samples)
开发者ID:anemitz,项目名称:calendarserver,代码行数:42,代码来源:event_delete.py

示例13: measure

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def measure(host, port, dtrace, attendeeCount, samples):
    user = password = "user01"
    root = "/"
    principal = "/"
    calendar = "report-principal"

    authinfo = HTTPDigestAuthHandler()
    authinfo.add_password(
        realm="Test Realm",
        uri="http://%s:%d/" % (host, port),
        user=user,
        passwd=password)
    agent = AuthHandlerAgent(Agent(reactor), authinfo)

    # Set up the calendar first
    yield initialize(agent, host, port, user, password, root, principal, calendar)

    url = 'http://%s:%d/principals/' % (host, port)
    headers = Headers({"content-type": ["text/xml"]})

    samples = yield sample(
        dtrace, samples, agent,
        lambda: ('REPORT', url, headers, StringProducer(body)))
    returnValue(samples)
开发者ID:eventable,项目名称:CalendarServer,代码行数:26,代码来源:report_principals.py

示例14: HTTPDigestAuthHandler

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
                key = 'basic'
            else:
                key = None
            if key:
                self._challenged[self._authKey(method, uri)] = challenges[key]
                return self._respondToChallenge(challenges[key], method, uri, headers, bodyProducer)
        return response



if __name__ == '__main__':
    from urllib2 import HTTPDigestAuthHandler
    handler = HTTPDigestAuthHandler()
    handler.add_password(
        realm="Test Realm",
        uri="http://localhost:8008/",
        user="user01",
        passwd="user01")

    from twisted.web.client import Agent
    from twisted.internet import reactor
    from twisted.python.log import err
    agent = AuthHandlerAgent(Agent(reactor), handler)
    d = agent.request(
        'DELETE', 'http://localhost:8008/calendars/users/user01/monkeys3/')
    def deleted(response):
        print(response.code)
        print(response.headers)
        reactor.stop()
    d.addCallback(deleted)
    d.addErrback(err)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:33,代码来源:httpauth.py

示例15: _request

# 需要导入模块: from urllib2 import HTTPDigestAuthHandler [as 别名]
# 或者: from urllib2.HTTPDigestAuthHandler import add_password [as 别名]
def _request(url, post=False, user=None, passwd=None,
             allow_TLSv1=False, **kwargs):
    timeout = float(kwargs.pop('timeout', g_timeout))
    url_values = urlencode(kwargs)
    if url_values:
        url += '?' + url_values

    logger.debug('Accessing URL %s' % url)
    url_args = {
        'timeout': timeout
    }

    if allow_TLSv1:
        url_args['context'] = ssl.SSLContext(ssl.PROTOCOL_TLSv1)

    opener = None

    req = Request(url)
    if post:
        if isinstance(post, str):
            post = post.encode('utf8')
        logger.debug('POST data: \n%s' % post.decode('utf8'))
        req.data = post

    req.add_header('Accept', '*/*')

    itry = 0
    while True:
        itry += 1
        try:
            urlopen_ = opener.open if opener else urlopen
            while True:
                try:
                    resp = urlopen_(req, **url_args)
                    break
                except TypeError:
                    del url_args['context']  # context not avail before 3.4.3

            logger.debug('Response: %s' % resp.getcode())
            if resp.getcode() == 204:
                raise EmptyResult(url)
            return resp

        except HTTPError as e:
            if e.code == 413:
                raise RequestEntityTooLarge(url)

            elif e.code == 401:
                headers = getattr(e, 'headers', e.hdrs)

                realm = get_realm_from_auth_header(headers)

                if itry == 1 and user is not None:
                    auth_handler = HTTPDigestAuthHandler()
                    auth_handler.add_password(
                        realm=realm,
                        uri=url,
                        user=user,
                        passwd=passwd or '')

                    opener = build_opener(auth_handler)
                    continue
                else:
                    logger.error(
                        'authentication failed for realm "%s" when '
                        'accessing url "%s"' % (realm, url))

                    raise DownloadError('Original error was: %s' % str(e))

            else:
                logger.error(
                    'error content returned by server:\n%s' % e.read())

                raise DownloadError('Original error was: %s' % str(e))

        break
开发者ID:emolch,项目名称:pyrocko,代码行数:78,代码来源:fdsn.py


注:本文中的urllib2.HTTPDigestAuthHandler.add_password方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。