8000 Improve style of handler code (#134) · sonlinux/client_python@c07b63e · GitHub
[go: up one dir, main page]

Skip to content

Commit c07b63e

Browse files
authored
Improve style of handler code (prometheus#134)
1 parent aa4b4fb commit c07b63e

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

prometheus_client/exposition.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
from __future__ import unicode_literals
44

5+
import base64
56
import os
67
import socket
7-
import time
88
import threading
9+
import time
910
from contextlib import closing
1011
from wsgiref.simple_server import make_server
11-
import base64
12-
import sys
1312

1413
from . import core
1514
try:
@@ -146,13 +145,9 @@ def handle():
146145
'''Handler that implements HTTP Basic Auth.
147146
'''
148147
if username is not None and password is not None:
149-
if sys.version_info >= (3,0):
150-
auth_value = bytes('{0}:{1}'.format(username, password), 'utf8')
151-
auth_token = str(base64.b64encode(auth_value), 'utf8')
152-
else:
153-
auth_value = '{0}:{1}'.format(username, password)
154-
auth_token = base64.b64encode(auth_value)
155-
auth_header = "Basic {0}".format(auth_token)
148+
auth_value = '{0}:{1}'.format(username, password).encode('utf-8')
149+
auth_token = base64.b64encode(auth_value)
150+
auth_header = b'Basic ' + auth_token
156151
headers.append(['Authorization', auth_header])
157152
default_handler(url, method, timeout, headers, data)()
158153

0 commit comments

Comments
 (0)
0