home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1455 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.8 KB  |  56 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import cherrypy
  5. from cherrypy.lib import httpauth
  6.  
  7. def check_auth(users, encrypt = None, realm = None):
  8.     if 'authorization' in cherrypy.request.headers:
  9.         ah = httpauth.parseAuthorization(cherrypy.request.headers['authorization'])
  10.         if ah is None:
  11.             raise cherrypy.HTTPError(400, 'Bad Request')
  12.         ah is None
  13.         if not encrypt:
  14.             encrypt = httpauth.DIGEST_AUTH_ENCODERS[httpauth.MD5]
  15.         
  16.         if callable(users):
  17.             
  18.             try:
  19.                 users = users()
  20.                 if not isinstance(users, dict):
  21.                     raise ValueError, 'Authentication users must be a dictionary'
  22.                 isinstance(users, dict)
  23.                 password = users.get(ah['username'], None)
  24.             except TypeError:
  25.                 password = users(ah['username'])
  26.             except:
  27.                 None<EXCEPTION MATCH>TypeError
  28.             
  29.  
  30.         None<EXCEPTION MATCH>TypeError
  31.         if not isinstance(users, dict):
  32.             raise ValueError, 'Authentication users must be a dictionary'
  33.         isinstance(users, dict)
  34.         password = users.get(ah['username'], None)
  35.         if httpauth.checkResponse(ah, password, method = cherrypy.request.method, encrypt = encrypt, realm = realm):
  36.             cherrypy.request.login = ah['username']
  37.             return True
  38.         cherrypy.request.login = False
  39.     
  40.     return False
  41.  
  42.  
  43. def basic_auth(realm, users, encrypt = None):
  44.     if check_auth(users, encrypt):
  45.         return None
  46.     cherrypy.response.headers['www-authenticate'] = httpauth.basicAuth(realm)
  47.     raise cherrypy.HTTPError(401, 'You are not authorized to access that resource')
  48.  
  49.  
  50. def digest_auth(realm, users):
  51.     if check_auth(users, realm = realm):
  52.         return None
  53.     cherrypy.response.headers['www-authenticate'] = httpauth.digestAuth(realm)
  54.     raise cherrypy.HTTPError(401, 'You are not authorized to access that resource')
  55.  
  56.