<commit_before>"""
filemail.users
~~~~~~~~~~~~~~

Contains :User:, :Contacts: and :Company: classes
"""

from calendar import timegm
from datetime import datetime, timedelta

from urls import getURL
from config import Config
from transfer import Transfer
from http import FMConnection
from errors import hellraiser, FMBaseError


class User():
    """This is the entry point to filemail. You need a valid user to login.

    :param username: String with registered filemail username (email address)
    :param apikey: (optional) String api key from filemail.com
    :param password: (optional) String users filemail password

    :class:`User <User>` object needs to be passed to :class:`Transfer` for
    successful transfers.
    """

    def __init__(self, username, apikey=None, password=<PASSWORD>, **kwargs):

        self._logged_in = False
        self._transfers = []
        self.username = username

        self.config = Config(self.username)
        if apikey and password:
            self.config.set('apikey', apikey)
            self.config.set('password', password)
            for key, value in kwargs.items():
                self.config.set(key, value)

        else:
            if 'config_file' in kwargs:
                config_file = kwargs['config_file']

            else:
                config_file = None

            self.config.load(config_file)

        self.session = FMConnection(self)

    def getInfo(self):
        """:returns: :class:`Config <Config>` object containig user information
        and default settings.
        """

        #: Fail if user not logged in
        self.validateLoginStatus()

        url = getURL('user_get')

        payload = {
            'apikey': self.config.get('apikey'),
            'logintoken': self.config.get('logintoken')
            }

        res = self.session.post(url=url, params=payload)

        if not res.ok:
            hellraiser(res.json())

        return Config(self.username, **res.json()['user'])

    def updateUserInfo(self, info):
        """Update user information and settings.

        :param info: Dictionary containing information"""

        self.validateLoginStatus()

        self.config.update(info)

        url = getURL('user_update')

        res = self.session.post(url=url, params=self.config.dump())
<commit_msg>enable passing Config object to updateUserInfo method or just use the current config<commit_after>"""
filemail.users
~~~~~~~~~~~~~~

Contains :User:, :Contacts: and :Company: classes
"""

from calendar import timegm
from datetime import datetime, timedelta

from urls import getURL
from config import Config
from transfer import Transfer
from http import FMConnection
from errors import hellraiser, FMBaseError


class User():
    """This is the entry point to filemail. You need a valid user to login.

    :param username: String with registered filemail username (email address)
    :param apikey: (optional) String api key from filemail.com
    :param password: (optional) String users filemail password

    :class:`User <User>` object needs to be passed to :class:`Transfer` for
    successful transfers.
    """

    def __init__(self, username, apikey=None, password=<PASSWORD>, **kwargs):

        self._logged_in = False
        self._transfers = []
        self.username = username

        self.config = Config(self.username)
        if apikey and password:
            self.config.set('apikey', apikey)
            self.config.set('password', password)
            for key, value in kwargs.items():
                self.config.set(key, value)

        else:
            if 'config_file' in kwargs:
                config_file = kwargs['config_file']

            else:
                config_file = None

            self.config.load(config_file)

        self.session = FMConnection(self)

    def getInfo(self):
        """:returns: :class:`Config <Config>` object containig user information
        and default settings.
        """

        #: Fail if user not logged in
        self.validateLoginStatus()

        url = getURL('user_get')

        payload = {
            'apikey': self.config.get('apikey'),
            'logintoken': self.config.get('logintoken')
            }

        res = self.session.post(url=url, params=payload)

        if not res.ok:
            hellraiser(res.json())

        return Config(self.username, **res.json()['user'])

    def updateUserInfo(self, info=None):
        """Update user information and settings.

        :param info: Dictionary containing information"""

        self.validateLoginStatus()

        if info is not None:
            if isinstance(info, Config):
                info = info.dump()

            self.config.update(info)

        url = getURL('user_update')

        res = self.session.post(url=url, params=self.config.dump())

{'fraction_non_alphanumeric': 0.10674389739346297, 'fraction_numerical': 0.0, 'mean_word_length': 2.4585121602288984, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, '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': '184483', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1257, 'n_words': 396}