<commit_before>#!/usr/bin/env python3
# vim:fileencoding=utf-8:ts=8:et:sw=4:sts=4:tw=79

"""
application.wsgi

The "ScrobbLRR" bottle application.

Copyright (c) 2015 <NAME> <pear at twistedpear dot at>
See the file LICENSE for copying permission.
"""

from bottle import Bottle, request, response
from bottle.ext import redis
from hashlib import md5
from os import environ
from uuid import uuid4

app = application = Bottle()
redis_plugin = redis.RedisPlugin()
app.install(redis_plugin)

EXPIRATION_SEC = int(environ.get("EXPIRATION_SEC", 300))
NOWPLAYING_URL = environ["NOWPLAYING_URL"]
SUBMISSION_URL = environ["SUBMISSION_URL"]


@app.get("/")
def handshake(rdb):
    """
    The initial negotiation with the Audioscrobbler server to establish
    authentication and connection details for the session.
    """
    # all we return here is plain text
    response.content_type = "text/plain"

    # is this really a handshake?
    if request.query.get("hs") != "true":
        return "ScrobbLRR submissions system."

    # we only support protocol version 1.2
    if request.query.get("p") != "1.2":
        return "FAILED Incorrect protocol version"

    # now we need to try and authenticate the user
    user = request.query.get("u")
    time = request.query.get("t")
    auth = request.query.get("a")
    if not all((user, time, auth)):
        return "BADAUTH Incomplete credentials"

    # get credentials for that user (if any)
    ckey = "scrobblrr:user:{user}:cred".format(user=user)
    cred = rdb.get(ckey)
    if not cred:
        return "BADAUTH Invalid user name"

    # calculate token := md5(md5(password) + timestamp)
    ch = md5()
    ch.update(cred)
<commit_msg>Support protocol version 1.2.1 as well<commit_after>#!/usr/bin/env python3
# vim:fileencoding=utf-8:ts=8:et:sw=4:sts=4:tw=79

"""
application.wsgi

The "ScrobbLRR" bottle application.

Copyright (c) 2015 <NAME> <pear at twistedpear dot at>
See the file LICENSE for copying permission.
"""

from bottle import Bottle, request, response
from bottle.ext import redis
from hashlib import md5
from os import environ
from uuid import uuid4

app = application = Bottle()
redis_plugin = redis.RedisPlugin()
app.install(redis_plugin)

EXPIRATION_SEC = int(environ.get("EXPIRATION_SEC", 300))
NOWPLAYING_URL = environ["NOWPLAYING_URL"]
SUBMISSION_URL = environ["SUBMISSION_URL"]


@app.get("/")
def handshake(rdb):
    """
    The initial negotiation with the Audioscrobbler server to establish
    authentication and connection details for the session.
    """
    # all we return here is plain text
    response.content_type = "text/plain"

    # is this really a handshake?
    if request.query.get("hs") != "true":
        return "ScrobbLRR submissions system."

    # we only support protocol version 1.2(.1)
    proto = request.query.get("p")
    if proto != "1.2" and proto != "1.2.1":
        return "FAILED Incorrect protocol version"

    # now we need to try and authenticate the user
    user = request.query.get("u")
    time = request.query.get("t")
    auth = request.query.get("a")
    if not all((user, time, auth)):
        return "BADAUTH Incomplete credentials"

    # get credentials for that user (if any)
    ckey = "scrobblrr:user:{user}:cred".format(user=user)
    cred = rdb.get(ckey)
    if not cred:
        return "BADAUTH Invalid user name"

    # calculate token := md5(md5(password) + timestamp)
    ch = md5()
    ch.update(cred)

{'fraction_non_alphanumeric': 0.1157649796393252, 'fraction_numerical': 0.015415939499709133, 'mean_word_length': 3.6852861035422344, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, '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': '605744', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1111, 'n_words': 336}