<commit_before># -*- coding: UTF-8 -*-
from assopy import settings
from assopy.clients.gnrbag import Bag

from lxml import objectify

import urllib

def _get(subpath):
    url = settings.BACKEND + subpath
    f = urllib.urlopen(url)
    return objectify.fromstring(f.read())

def _post(subpath, bag=None):
    url = settings.BACKEND + subpath
    body = {}
    if bag is not None:
        body['data'] = bag.toXml()
    f = urllib.urlopen(url, urllib.urlencode(body))
    b = Bag()
    b.fromXml(f.read())
    return b

def user(id):
    return _get('/users/%s' % id)   

def create_user(first_name, last_name, email):
    b = Bag()
    b['firstname'] = first_name
    b['lastname'] = last_name
    b['email'] = email
    return _post('/users/', b)<commit_msg>api genro: utilizzo di logging e urlparse.<commit_after># -*- coding: UTF-8 -*-
from assopy import settings
from assopy.clients.gnrbag import Bag

from lxml import objectify

import logging
import urllib
from urlparse import urlparse, urlunparse

log = logging.getLogger('assopy.genro')

_url = urlparse(settings.BACKEND)

def _build(path, query=None):
    splitted = list(_url)
    if not path.startswith('/'):
        path = '/' + path
    splitted[2] = (splitted[2] + path).replace('//', '/')
    if query:
        splitted[4] = urllib.urlencode(query)
    return urlunparse(splitted)

def _get(subpath, **kwargs):
    url = _build(subpath, kwargs)
    log.debug('get -> %s', url)
    f = urllib.urlopen(url)
    b = Bag()
    b.fromXml(f.read())
    return b

def _post(subpath, bag=None):
    url = settings.BACKEND + subpath
    log.debug('post -> %s', url)
    body = {}
    if bag is not None:
        body['data'] = bag.toXml()
    f = urllib.urlopen(url, urllib.urlencode(body))
    b = Bag()
    b.fromXml(f.read())
    return b

def users(email):
    """
    restituisce gli id degli utenti remoti che hanno l'email passata
    """
    return _get('/users/', email=email)

def user(id):
    return _get('/users/%s' % id)   

def create_user(firstname, lastname, email):
    b = Bag()
    b['firstname'] = firstname
    b['lastname'] = lastname
    b['email'] = email
    return _post('/users/', b)['id']
{'fraction_non_alphanumeric': 0.14942528735632185, 'fraction_numerical': 0.0022988505747126436, 'mean_word_length': 3.0521415270018624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3791771', 'n_tokens_mistral': 776, 'n_tokens_neox': 775, 'n_words': 196}