<commit_before># -*- coding: utf-8 -*-

import pycurl

from module.common.json_layer import json_loads
from module.plugins.Account import Account


class PremiumizeMe(Account):
    __name__    = "PremiumizeMe"
    __type__    = "account"
    __version__ = "0.15"

    __description__ = """Premiumize.me account plugin"""
    __license__     = "GPLv3"
    __authors__     = [("<NAME>", "<EMAIL>")]


    def getAccountRequest(self, user=None):
        req = super(PremiumizeMe, self).getAccountRequest(user)
        if req:
            req.http.c.setopt(pycurl.CURLOPT_SSL_CIPHER_LIST, "TLSv1")
        return req


    def loadAccountInfo(self, user, req):
        # Get user data from premiumize.me
        status = self.getAccountStatus(user, req)
        self.logDebug(status)

        # Parse account info
        account_info = {"validuntil": float(status['result']['expires']),
                        "trafficleft": max(0, status['result']['trafficleft_bytes'] / 1024)}  #@TODO: Remove `/ 1024` in 0.4.10

        if status['result']['type'] == 'free':
            account_info['premium'] = False

        return account_info


    def login(self, user, data, req):
        # Get user data from premiumize.me
        status = self.getAccountStatus(user, req)

        # Check if user and password are valid
        if status['status'] != 200:
            self.wrongPassword()


    def getAccountStatus(self, user, req):
        # Use premiumize.me API v1 (see https://secure.premiumize.me/?show=api)
        # to retrieve account info and return the parsed json answer
        answer = req.load("https://api.premiumize.me/pm-api/v1.php",
                           get={'method'       : "accountstatus",
                                'params[login]': user,
                                'params[pass]' : self.getAccountData(user)['password']})
        return json_loads(answer)
<commit_msg>[PremiumizeMe] Account fixup<commit_after># -*- coding: utf-8 -*-

from module.common.json_layer import json_loads
from module.plugins.Account import Account


class PremiumizeMe(Account):
    __name__    = "PremiumizeMe"
    __type__    = "account"
    __version__ = "0.16"

    __description__ = """Premiumize.me account plugin"""
    __license__     = "GPLv3"
    __authors__     = [("<NAME>", "<EMAIL>")]


    def loadAccountInfo(self, user, req):
        # Get user data from premiumize.me
        status = self.getAccountStatus(user, req)
        self.logDebug(status)

        # Parse account info
        account_info = {"validuntil": float(status['result']['expires']),
                        "trafficleft": max(0, status['result']['trafficleft_bytes'] / 1024)}  #@TODO: Remove `/ 1024` in 0.4.10

        if status['result']['type'] == 'free':
            account_info['premium'] = False

        return account_info


    def login(self, user, data, req):
        # Get user data from premiumize.me
        status = self.getAccountStatus(user, req)

        # Check if user and password are valid
        if status['status'] != 200:
            self.wrongPassword()


    def getAccountStatus(self, user, req):
        # Use premiumize.me API v1 (see https://secure.premiumize.me/?show=api)
        # to retrieve account info and return the parsed json answer
        answer = req.load("http://api.premiumize.me/pm-api/v1.php",
                           get={'method'       : "accountstatus",
                                'params[login]': user,
                                'params[pass]' : self.getAccountData(user)['password']})
        return json_loads(answer)

{'fraction_non_alphanumeric': 0.12656816281014777, 'fraction_numerical': 0.013102871480345692, 'mean_word_length': 2.309963099630996, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 3, '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': '4318589', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1028, 'n_words': 250}