<commit_before># -*- coding: utf-8 -*-
import sys
import traceback
import requests

from jsonschema import validate, SchemaError, ValidationError

from pluct import schema
from pluct.request import Request
from pluct.schema import Schema


def add_methods(resource, s, auth=None):
    for link in getattr(s, "links", []) or []:
        method = link.get("method", "GET")
        href = link.get("href")
        rel = link.get("rel")
        method_class = Request(method, href, auth, resource)
        setattr(resource, rel, method_class.process)


class Resource(dict):

    def __init__(self, url, data=None, schema=None,
                 auth=None, response=None, timeout=30):
        self.auth = auth
        self.url = url
        self.data = data
        self.schema = schema
        self.timeout = timeout
        self.response = response
        if self.schema:
            if self.is_valid():
                add_methods(self, self.schema, self.auth)
                self.parse_data()

    def __repr__(self):
        return str(self.data)

    def __iter__(self):
        return iter(self.data)

    def __getitem__(self, attr):
        if attr in self.data:
            return self.data[attr]
        raise KeyError

    def is_valid(self):
        try:
            validate(self.data, self.schema._raw_schema)
        except (SchemaError, ValidationError):<commit_msg>Fix Resource to support __contains__ used in validation<commit_after># -*- coding: utf-8 -*-
import sys
import traceback
import requests

from jsonschema import validate, SchemaError, ValidationError

from pluct import schema
from pluct.request import Request
from pluct.schema import Schema


def add_methods(resource, s, auth=None):
    for link in getattr(s, "links", []) or []:
        method = link.get("method", "GET")
        href = link.get("href")
        rel = link.get("rel")
        method_class = Request(method, href, auth, resource)
        setattr(resource, rel, method_class.process)


class Resource(dict):

    def __init__(self, url, data=None, schema=None,
                 auth=None, response=None, timeout=30):
        self.auth = auth
        self.url = url
        self.data = data
        self.schema = schema
        self.timeout = timeout
        self.response = response
        if self.schema:
            if self.is_valid():
                add_methods(self, self.schema, self.auth)
                self.parse_data()

    def __repr__(self):
        return str(self.data)

    def __iter__(self):
        return iter(self.data)

    def __getitem__(self, attr):
        if attr in self.data:
            return self.data[attr]
        raise KeyError

    def __contains__(self, item):
        return dict.__contains__(self.data, item)

    def is_valid(self):
        try:
            validate(self.data, self.schema._raw_schema)
        except (SchemaError, ValidationError):
{'fraction_non_alphanumeric': 0.1028749567024593, 'fraction_numerical': 0.0020782819535850364, 'mean_word_length': 2.362048894062864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2437731', 'n_tokens_mistral': 836, 'n_tokens_neox': 812, 'n_words': 230}