MCPcopy
hub / github.com/benoitc/gunicorn / _get_user

Method _get_user

gunicorn/glogging.py:469–483  ·  view source on GitHub ↗
(self, environ)

Source from the content-addressed store, hash-verified

467 log.addHandler(h)
468
469 def _get_user(self, environ):
470 user = None
471 http_auth = environ.get("HTTP_AUTHORIZATION")
472 if http_auth and http_auth.lower().startswith('basic'):
473 auth = http_auth.split(" ", 1)
474 if len(auth) == 2:
475 try:
476 # b64decode doesn't accept unicode in Python < 3.3
477 # so we need to convert it to a byte string
478 auth = base64.b64decode(auth[1].strip().encode('utf-8'))
479 # b64decode returns a byte string
480 user = auth.split(b":", 1)[0].decode("UTF-8")
481 except (TypeError, binascii.Error, UnicodeDecodeError) as exc:
482 self.debug("Couldn't get username: %s", exc)
483 return user

Callers 1

atomsMethod · 0.95

Calls 4

debugMethod · 0.95
encodeMethod · 0.80
decodeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected