<commit_before>import picoweb
from config import model
from util import notFound
import logging
logger = logging.getLogger(__name__)

def get(req, res):
  yield from picoweb.jsonify(res, model.load())

def set(req, res):
  yield from req.read_form_data()
  cfg = model.load()
  for key, value in req.form.items():
    cfg[key] = value
  model.save(cfg)
  yield from get(req, res)

def reset(req, res):
  yield from picoweb.jsonify(res, {})
  model.reset()

def factory(req, res):
  model.factory()
  yield from picoweb.jsonify(res, {})

def method(req, res):
  ret = {
    'GET': get,
    'PUT': set
  }
  logger.info('{0} {1}'.format(req.method, req.path))
  yield from ret.get(req.method, notFound)(req, res)

app = picoweb.WebApp(__name__)
app.route('/')(method)
app.route('/reset')(reset)
app.route('/factory')(factory)
<commit_msg>return config if factory default is restored<commit_after>import picoweb
from config import model
from util import notFound
import logging
logger = logging.getLogger(__name__)

def get(req, res):
  yield from picoweb.jsonify(res, model.load())

def set(req, res):
  yield from req.read_form_data()
  cfg = model.load()
  for key, value in req.form.items():
    cfg[key] = value
  model.save(cfg)
  yield from get(req, res)

def reset(req, res):
  yield from picoweb.jsonify(res, {})
  model.reset()

def factory(req, res):
  model.factory()
  from wlan.ap import controller
  yield from controller.get(req, res)

def method(req, res):
  ret = {
    'GET': get,
    'PUT': set
  }
  logger.info('{0} {1}'.format(req.method, req.path))
  yield from ret.get(req.method, notFound)(req, res)

app = picoweb.WebApp(__name__)
app.route('/')(method)
app.route('/reset')(reset)
app.route('/factory')(factory)

{'fraction_non_alphanumeric': 0.15495391705069125, 'fraction_numerical': 0.002304147465437788, 'mean_word_length': 4.328220858895706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4710234', 'n_tokens_mistral': 620, 'n_tokens_neox': 622, 'n_words': 163}