code: def authbasic(request):
      
      if len(request.environ.get('HTTP_AUTHORIZATION', '')) > 0:
          auth = request.environ.get('HTTP_AUTHORIZATION')
          scheme, data = auth.split(None, 1)
          assert scheme.lower() == 'basic'
          data = base64.b64decode(data)
          if not isinstance(data, unicode):
              data = data.decode('utf-8')
          username, password = data.split(':', 1)
          if User.by_ldap_credentials(
                  DBSession(), username, password, request.registry.settings):
              return HTTPFound(location=request.url)
          if User.by_credentials(DBSession(), username, password):
              return HTTPFound(location=request.url)
      return Response(status=401,
                      headerlist=[(str('WWW-Authenticate'),
                                   str('Basic realm="pyshop repository access"'),
                                   )],
                      )
docs: Authentification basic, Upload pyshop repository access