<commit_before>import logging
import time
import re
import json
import traceback

from .. import SteamWebBase, SteamIdParser


# https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService
class ETradeOfferState:
    Invalid = 1  # Invalid
    Active = 2  # This trade offer has been sent, neither party has acted on it yet.
    Accepted = 3  # The trade offer was accepted by the recipient and items were exchanged.
    Countered = 4  # The recipient made a counter offer
    Expired = 5  # The trade offer was not accepted before the expiration date
    Canceled = 6  # The sender cancelled the offer
    Declined = 7  # The recipient declined the offer

    # 	Some of the items in the offer are no longer available (indicated by the missing flag in the output)
    InvalidItems = 8
    # The offer hasn't been sent yet and is awaiting email/mobile confirmation. The offer is only visible to the sender.
    CreatedNeedsConfirmation = 9
    # Either party canceled the offer via email/mobile. The offer is visible to both parties,
    # even if the sender canceled it before it was sent.
    CanceledBySecondFactor = 10
    # The trade has been placed on hold. The items involved in the trade have all been removed from both parties'
    # inventories and will be automatically delivered in the future.
    InEscrow = 11


class ETradeOfferConfirmationMethod:
    Invalid = 0  # Invalid
    Email = 1  # An email was sent with details on how to confirm the trade offer
    MobileApp = 2  # The trade offer may be confirmed via the mobile app


class SteamTrade(SteamWebBase):
    ETradeOfferState = ETradeOfferState
    ETradeOfferConfirmationMethod = ETradeOfferConfirmationMethod

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.api_key = kwargs.get('api_key')

    @classmethod
    def is_valid_trade_url(cls, trade_url):
        regex = re.compile(r'^https?://steamcommunity\.com/tradeoffer/new/\?partner=(\d+)&token=([a-zA-Z0-9_-]+)$')
        return True if regex.match(trade_url) is not None else False

    @classmethod
    def get_parse_trade_url(cls, trade_url):
        regex = re.compile(r'^https?://steamcommunity\.com/tradeoffer/new/\?partner=(\d+)&token=([a-zA-Z0-9_-]+)$')
        match = regex.match(trade_url)
        if match:
            return None

        return {
            'token': match.group(1),
            'partner': match.group(2),
        }

    async def check_user_trade_url(self, trade_url):
        logging.debug('start check_user_trade_url, for: {}'.format(trade_url))

        trade_data = self.get_parse_trade_url(trade_url)<commit_msg>fix parsing trade_url<commit_after>import logging
import time
import re
import json
import traceback

from .. import SteamWebBase, SteamIdParser


# https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService
class ETradeOfferState:
    Invalid = 1  # Invalid
    Active = 2  # This trade offer has been sent, neither party has acted on it yet.
    Accepted = 3  # The trade offer was accepted by the recipient and items were exchanged.
    Countered = 4  # The recipient made a counter offer
    Expired = 5  # The trade offer was not accepted before the expiration date
    Canceled = 6  # The sender cancelled the offer
    Declined = 7  # The recipient declined the offer

    # 	Some of the items in the offer are no longer available (indicated by the missing flag in the output)
    InvalidItems = 8
    # The offer hasn't been sent yet and is awaiting email/mobile confirmation. The offer is only visible to the sender.
    CreatedNeedsConfirmation = 9
    # Either party canceled the offer via email/mobile. The offer is visible to both parties,
    # even if the sender canceled it before it was sent.
    CanceledBySecondFactor = 10
    # The trade has been placed on hold. The items involved in the trade have all been removed from both parties'
    # inventories and will be automatically delivered in the future.
    InEscrow = 11


class ETradeOfferConfirmationMethod:
    Invalid = 0  # Invalid
    Email = 1  # An email was sent with details on how to confirm the trade offer
    MobileApp = 2  # The trade offer may be confirmed via the mobile app


class SteamTrade(SteamWebBase):
    ETradeOfferState = ETradeOfferState
    ETradeOfferConfirmationMethod = ETradeOfferConfirmationMethod

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.api_key = kwargs.get('api_key')

    @classmethod
    def is_valid_trade_url(cls, trade_url):
        regex = re.compile(r'^https?://steamcommunity\.com/tradeoffer/new/\?partner=(\d+)&token=([a-zA-Z0-9_-]+)$')
        return True if regex.match(trade_url) is not None else False

    @classmethod
    def get_parse_trade_url(cls, trade_url):
        regex = re.compile(r'^https?://steamcommunity\.com/tradeoffer/new/\?partner=(\d+)&token=([a-zA-Z0-9_-]+)$')
        match = regex.match(trade_url)
        if not match:
            return None

        return {
            'token': match.group(1),
            'partner': match.group(2),
        }

    async def check_user_trade_url(self, trade_url):
        logging.debug('start check_user_trade_url, for: {}'.format(trade_url))

        trade_data = self.get_parse_trade_url(trade_url)
{'fraction_non_alphanumeric': 0.08070041872858774, 'fraction_numerical': 0.008374571754853444, 'mean_word_length': 3.1839171974522293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2732351', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1498, 'n_words': 538}