<commit_before>import requests
import StringIO
import xml.etree.cElementTree as ElementTree


def userUtil(user_id):
    def parseUser(source, handle):
        for event, elem in ElementTree.iterparse(source,
                                                 events=('start')):
            if event == 'start':
                handle.startElement(elem.tag, elem.attrib)
            elem.clear()

    class userDecoder():
        def __init__(self):
            self.creation = ""
            self.changesets = 0
            self.blocks = 0
            self.active = 0

        def startElement(self, name, attributes):
            if name == 'user':
                self.creation = attributes['account_created']
            elif name == 'changesets':
                self.changesets = int(attributes['count'])
            elif name == 'received':
                self.blocks = int(attributes['count'])
                self.active = int(attributes['active'])

    try:
        url = 'http://www.osm.org/api/0.6/user/' + str(user_id)

        content = requests.get(url)
        if content.status_code == 404:
            raise Exception

        content = StringIO.StringIO(content.content)<commit_msg>User lookup fixes<commit_after>import requests
import StringIO
import xml.etree.cElementTree as ElementTree


def userUtil(user_id):
    def parseUser(source, handle):
        for event, elem in ElementTree.iterparse(source,
                                                 events=('start','end')):
            if event == 'start':
                handle.startElement(elem.tag, elem.attrib)
            elem.clear()

    class userDecoder():
        def __init__(self):
            self.creation = ""
            self.changesets = 0
            self.total_blocks = 0
            self.active_blocks = 0

        def startElement(self, name, attributes):
            if name == 'user':
                self.creation = attributes['account_created']
            elif name == 'changesets':
                self.changesets = int(attributes['count'])
            elif name == 'received':
                self.blocks = int(attributes['count'])
                self.active = int(attributes['active'])

    try:
        url = 'http://www.osm.org/api/0.6/user/' + str(user_id)

        content = requests.get(url)
        if content.status_code == 404:
            raise Exception

        content = StringIO.StringIO(content.content)
{'fraction_non_alphanumeric': 0.1110193974411886, 'fraction_numerical': 0.006603384234420141, 'mean_word_length': 1.7514188422247445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2177469', 'n_tokens_mistral': 650, 'n_tokens_neox': 607, 'n_words': 141}