<commit_before>
import idna

from ens import abis
from ens.constants import EMPTY_SHA3_BYTES
from ens.registrar import Registrar
from ens.utils import dict_copy, ensure_hex, init_web3

DEFAULT_TLD = 'eth'
RECOGNIZED_TLDS = [DEFAULT_TLD, 'reverse', 'test']

ENS_MAINNET_ADDR = '0x314159265dd8dbb310642f98f50c066173c1259b'

REVERSE_REGISTRAR_DOMAIN = 'addr.reverse'

GAS_DEFAULT = {
    'setAddr': 60001,
    'setResolver': 60002,
    'setSubnodeOwner': 60003,
}


def Web3():
    from web3 import Web3
    return Web3


class ENS:
    '''
    Unless otherwise specified, all addresses are assumed to be a str in hex format, like:
    "0x314159265dd8dbb310642f98f50c066173c1259b"
    '''

    def __init__(self, providers=None, addr=None):
        '''
        @param providers is a provider or list of providers for web3
        @param addr is the address of the ENS registry on-chain. If not provided,
            ENS.py will default to the mainnet ENS registry address.
        '''
        self.web3 = init_web3(providers)

        ens_addr = addr if addr else ENS_MAINNET_ADDR
        self.ens = self.web3.eth.contract(abi=abis.ENS, address=ens_addr)
        self._resolverContract = self.web3.eth.contract(abi=abis.RESOLVER)
        self.registrar = Registrar(self)

    def address(self, name):
        return self.resolve(name, 'addr')

    def name(self, address):
        reversed_domain = self.reverse_domain(address)
        return self.resolve(reversed_domain, get='name')
    reverse = name

    @dict_copy
    def setup_address(self, name, address=None, transact={}):
        (owner, unowned, owned) = self._first_owner(name)
        if not address:
            address = owner
        if self.address(name) == ensure_hex(address):
            return None
        self._assert_control(owner, name, owned)
        if unowned:
            self._claim_ownership(owner, unowned, owned, transact=transact)
        transact['from'] = owner<commit_msg>ens: get ENS object from a connected web3<commit_after>
import idna

from ens import abis
from ens.constants import EMPTY_SHA3_BYTES
from ens.registrar import Registrar
from ens.utils import dict_copy, ensure_hex, init_web3

DEFAULT_TLD = 'eth'
RECOGNIZED_TLDS = [DEFAULT_TLD, 'reverse', 'test']

ENS_MAINNET_ADDR = '0x314159265dd8dbb310642f98f50c066173c1259b'

REVERSE_REGISTRAR_DOMAIN = 'addr.reverse'

GAS_DEFAULT = {
    'setAddr': 60001,
    'setResolver': 60002,
    'setSubnodeOwner': 60003,
}


def Web3():
    from web3 import Web3
    return Web3


class ENS:
    '''
    Unless otherwise specified, all addresses are assumed to be a str in hex format, like:
    "0x314159265dd8dbb310642f98f50c066173c1259b"
    '''

    def __init__(self, providers=None, addr=None):
        '''
        @param providers is a provider or list of providers for web3
        @param addr is the address of the ENS registry on-chain. If not provided,
            ENS.py will default to the mainnet ENS registry address.
        '''
        self.web3 = init_web3(providers)

        ens_addr = addr if addr else ENS_MAINNET_ADDR
        self.ens = self.web3.eth.contract(abi=abis.ENS, address=ens_addr)
        self._resolverContract = self.web3.eth.contract(abi=abis.RESOLVER)
        self.registrar = Registrar(self)

    @classmethod
    def fromWeb3(cls, web3):
        return cls(web3.manager.providers)

    def address(self, name):
        return self.resolve(name, 'addr')

    def name(self, address):
        reversed_domain = self.reverse_domain(address)
        return self.resolve(reversed_domain, get='name')
    reverse = name

    @dict_copy
    def setup_address(self, name, address=None, transact={}):
        (owner, unowned, owned) = self._first_owner(name)
        if not address:
            address = owner
        if self.address(name) == ensure_hex(address):
            return None
        self._assert_control(owner, name, owned)
        if unowned:
            self._claim_ownership(owner, unowned, owned, transact=transact)
        transact['from'] = owner
{'fraction_non_alphanumeric': 0.0913151364764268, 'fraction_numerical': 0.04466501240694789, 'mean_word_length': 3.084093211752786, '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': '2296859', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1301, 'n_words': 338}