<commit_before><commit_msg>Steam backend<commit_after>"""Steam OpenId support"""
import re
import json
import urllib

from social.backends.open_id import OpenIdAuth
from social_auth.exceptions import AuthFailed


STEAM_ID = re.compile('steamcommunity.com/openid/id/(.*?)$')
USER_INFO = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?'


class SteamOpenId(OpenIdAuth):
    name = 'steam'

    def openid_url(self):
        """Return Steam OpenID service url"""
        return 'http://steamcommunity.com/openid'

    def get_user_id(self, details, response):
        """Return user unique id provided by service"""
        return self._user_id(response)

    def get_user_details(self, response):
        user_id = self._user_id(response)
        url = USER_INFO + urllib.urlencode({
            'key': self.setting('API_KEY'),
            'steamids': user_id
        })
        details = {}
        try:
            player = json.load(self.urlopen(url))
        except (ValueError, IOError):
            pass
        else:
            if len(player['response']['players']) > 0:
                player = player['response']['players'][0]
                details = {'username': player.get('personaname'),
                           'email': '',
                           'fullname': '',
                           'first_name': '',
                           'last_name': '',
                           'player': player}
        return details

    def _user_id(self, response):
        match = STEAM_ID.search(response.identity_url)
        if match is None:
            raise AuthFailed(self, 'Missing Steam Id')
        return match.group(1)


BACKENDS = {
    'steam': SteamOpenId
}

{'fraction_non_alphanumeric': 0.12272460364063417, 'fraction_numerical': 0.004110393423370522, 'mean_word_length': 2.092558983666062, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3481750', 'n_tokens_mistral': 501, 'n_tokens_neox': 483, 'n_words': 104}