<commit_before>#!/usr/bin/python

import os
import sys

import auth
import commands
import generate as gen
import parse

def greeting():
    return gen.success('2', '2', '( ANONYMOUS )', '( edit-pipeline )')

def auth_request():
    return gen.success('( CRAM-MD5 )', '4:test')

uuid = 'ffffffff-ffff-ffff-ffff-ffffffffffff'
repos_url = 'svn://localhost/'
def server_id():
    return gen.success(gen.string(uuid), gen.string(repos_url))

setup_steps = []
def setup(f):
    setup_steps.append(f)

@setup
def handle_client_greeting(msg):
    proto_ver = int(msg[0])
    client_caps = msg[1]
    url = parse.string(msg[2])

    print "ver: %d" % proto_ver
    print "caps: %s" % client_caps
    print "url: %s" % url

    return auth_request()

@setup
def handle_client_auth_resp(msg):
    auth_type = msg[0]

    if auth_type in auth.auths:
        raise auth.Needed(auth_type, server_id)

    return gen.failure(gen.string('unknown auth type: %s' % auth_type))

def handle_msg(msg_str):
    msg = parse.msg(msg_str)

    while len(setup_steps) > 0:
        fn = setup_steps.pop(0)
        return fn(msg)

    print "%d:%s" % (os.getpid(), msg)

    return commands.handle_command(msg)<commit_msg>Match URL from client to a repository<commit_after>#!/usr/bin/python

import os
import sys

import auth
import commands
import generate as gen
import parse
from repos import find_repos

repos = None

def greeting():
    return gen.success('2', '2', '( ANONYMOUS )', '( edit-pipeline )')

def auth_request():
    return gen.success('( CRAM-MD5 )', '4:test')

uuid = 'ffffffff-ffff-ffff-ffff-ffffffffffff'
repos_url = 'svn://localhost/'
def server_id():
    return gen.success(gen.string(uuid), gen.string(repos_url))

setup_steps = []
def setup(f):
    setup_steps.append(f)

@setup
def handle_client_greeting(msg):
    global repos

    proto_ver = int(msg[0])
    client_caps = msg[1]
    url = parse.string(msg[2])

    print "ver: %d" % proto_ver
    print "caps: %s" % client_caps
    print "url: %s" % url

    repos = find_repos(url)

    if repos is None:
        return gen.failure(gen.list('210005',
                                    gen.string("No repository found in '%s'" %
                                    url),
                                    gen.string('message.py'), '0'))

    return auth_request()

@setup
def handle_client_auth_resp(msg):
    auth_type = msg[0]

    if auth_type in auth.auths:
        raise auth.Needed(auth_type, server_id)

    return gen.failure(gen.string('unknown auth type: %s' % auth_type))

def handle_msg(msg_str):
    msg = parse.msg(msg_str)

    while len(setup_steps) > 0:
        fn = setup_steps.pop(0)
        return fn(msg)

    print "%d:%s" % (os.getpid(), msg)

    return commands.handle_command(msg)
{'fraction_non_alphanumeric': 0.13649529326574947, 'fraction_numerical': 0.009775524981897175, 'mean_word_length': 3.021834061135371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1136483', 'n_tokens_mistral': 985, 'n_tokens_neox': 940, 'n_words': 227}