<commit_before>import os
import requests
import hashlib
import json

cfg = {
  'tokenurl': os.environ['TOKENURL'],
  'userurl': os.environ['USERURL'],
  'userlisturl': os.environ['USERLISTURL'],
  'client': {
    'id': os.environ['CLIENT_ID'],
    'secret': os.environ['CLIENT_SECRET']
  },
  'scope': os.environ['SCOPE']
}

'''
  authenticate user and return oauth2 response
'''
def login(user):
  data = { 'grant_type': 'password', 'username': user['id'], 'password': user['<PASSWORD>'], 'scope': cfg['scope'] } 
  return requests.post(cfg['tokenurl'], auth=(cfg['client']['id'], cfg['client']['secret']), data=data)

'''
  authenticate cfg.user and return token
'''
def token(user):
  res = json.loads(login(user).text)
  return res['access_token']

'''
  authenticate cfg.user and return if athenticated
'''
def isauth(user):
  return login(user).status_code == 200

'''
user = 'user1'
'''
def isuser(user):
  r = requests.get(cfg['userurl'].format(user))
  return userJson(json.loads(r.text)) if r.status_code == 200 else {}

'''
return json resprentation of input user
'''
def userJson(user):
  name = user['username']
  uid = int(hashlib.sha1(user['url']).hexdigest(), 16) % (10 ** 8)
  gid = 10000
  home = "/home/{0}".format(name)
  shell = '/bin/sh'
  return {'name': name, 'uid': uid, 'gid': gid, 'home': home, 'shell': shell}

'''
return list of users
'''
def users():
  users = []
  res = {'next': cfg['userlisturl']}
  while res['next']:
    r = requests.get(res['next'])
    res = json.loads(r.text)
    for user in res['results']:
      users.append(userJson(user))
  return users
<commit_msg>get env vars inside the function scope<commit_after>import os
import requests
import hashlib
import json

'''
  authenticate user and return oauth2 response
'''
def login(user):
  data = { 'grant_type': 'password', 'username': user['id'], 'password': user['<PASSWORD>'], 'scope': os.environ['SCOPE'] } 
  return requests.post(os.environ['tokenurl'], auth=(os.environ['CLIENT_ID'], os.environ['CLIENT_SECRET']), data=data)

'''
  authenticate user and return token
'''
def token(user):
  res = json.loads(login(user).text)
  return res['access_token']

'''
  authenticate user and return if athenticated
'''
def isauth(user):
  return login(user).status_code == 200

'''
user = 'user1'
'''
def isuser(user):
  r = requests.get(os.environ['USERURL'].format(user))
  return userJson(json.loads(r.text)) if r.status_code == 200 else {}

'''
return json resprentation of input user
'''
def userJson(user):
  name = user['username']
  uid = int(hashlib.sha1(user['url']).hexdigest(), 16) % (10 ** 8)
  gid = 10000
  home = "/home/{0}".format(name)
  shell = '/bin/sh'
  return {'name': name, 'uid': uid, 'gid': gid, 'home': home, 'shell': shell}

'''
return list of users
'''
def users():
  users = []
  res = {'next': os.environ['USERLISTURL']}
  while res['next']:
    r = requests.get(res['next'])
    res = json.loads(r.text)
    for user in res['results']:
      users.append(userJson(user))
  return users

{'fraction_non_alphanumeric': 0.19535655058043117, 'fraction_numerical': 0.013266998341625208, 'mean_word_length': 4.6373831775700936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '300517', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1053, 'n_words': 258}