~moovida-developers/moovida/account_video_intro

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/http_client/utils.py

  • Committer: Philippe Normand
  • Date: 2009-08-18 14:02:23 UTC
  • mfrom: (1466.5.7 moovida_http_auth)
  • Revision ID: philippe@fluendo.com-20090818140223-0ylij32hufci9lph
http_client: basic authentication support

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Moovida - Home multimedia server
 
3
# Copyright (C) 2007-2009 Fluendo Embedded S.L. (www.fluendo.com).
 
4
# All rights reserved.
 
5
#
 
6
# This file is available under one of two license agreements.
 
7
#
 
8
# This file is licensed under the GPL version 3.
 
9
# See "LICENSE.GPL" in the root of this distribution including a special
 
10
# exception to use Moovida with Fluendo's plugins.
 
11
#
 
12
# The GPL part of Moovida is also available under a commercial licensing
 
13
# agreement from Fluendo.
 
14
# See "LICENSE.Moovida" in the root directory of this distribution package
 
15
# for details on that license.
 
16
#
 
17
# Author: Philippe Normand <philippe@fluendo.com>
 
18
 
 
19
import base64
 
20
 
 
21
def generate_basic_auth_headers(username, password):
 
22
    """ Generate HTTP Basic Authentication headers given a username
 
23
    and a password. This is implemented in respect with RFC 2617.
 
24
 
 
25
    @param username: user id to use for the authentication against the server
 
26
    @type username:  C{str}
 
27
    @param password: password to use during the authentication
 
28
    @type password:  C{str}
 
29
    @rtype:          C{dict}
 
30
    """
 
31
    challenge = base64.b64encode("%s:%s" % (username, password))
 
32
    headers = {"Authorization": ["Basic %s" % challenge]}
 
33
    return headers