<commit_before>import uuid
from uritools import urisplit

from unis.models import Extent
from libdlt.logging import info, debug
from libdlt.protocol.ceph.allocation import CephExtent
from libdlt.protocol.ceph.services import ProtocolService
from libdlt.protocol.exceptions import AllocationException

ceph = ProtocolService()

@info("Ceph.factory")
def buildAllocation(obj):
    if type(obj) is str:
        try:
            obj = json.loads(obj)
        except Exception as exp:
            raise AllocationException("Could not decode json")
    if type(obj) is dict:
        alloc = CephExtent(obj)
    elif type(obj) in [CephExtent, Extent]:
        alloc = obj
    else:
        raise AllocationException("Invalid input type")
    return CephAdaptor(alloc)

@info("Ceph.factory")
async def makeAllocation(data, offset, depot, loop, **kwds):
    alloc = CephExtent()
    pool = kwds.get("pool", "dlt")
    oid = str(uuid.uuid4())
    alloc.location = "{0}/{1}/{2}".format(depot.endpoint, pool, oid)
    alloc.pool = pool
    alloc.offset = offset
    alloc.size = len(data)
    await ceph.write(oid, data, loop, **kwds)
    print(offset)
    return CephAdaptor(alloc)

class CephAdaptor(object):
    @debug("CephAdaptor")
    def __init__(self, alloc, **kwds):
        self._allocation = alloc
        
    @info("CephAdaptor")
    def getMetadata(self):
        return self._allocation
        
    @info("CephAdaptor")
    def read(self, **kwds):
        o = urisplit(self._allocation.location)
        parts = o.path.split('/')
        size = self._allocation.size
        return ceph.read(parts[1], parts[2], size, **kwds)
    
    @info("CephAdaptor")
    def copy(self, depot, src_kwds, dst_kwds):
        dst_alloc = CephExtent()
        dst_oid = str(uuid.uuid4())
        pool = dst_kwds.get('pool', 'dlt')
        dst_alloc.location = "{}/{}/{}".format(depot.endpoint, pool, dst_oid)
        dst_alloc.pool = pool
        dst_alloc.size = self._allocation.size
        dst_alloc.offset = self._allocation.offset
        
        src = urisplit(self._allocation.location)
        src = src.path.split('/')
        size = self._allocation.size
        
        ceph.copy(src[1], src[2], dst_oid, size, src_kwds, dst_kwds)
        return CephAdaptor(dst_alloc)
<commit_msg>Removed debugging print<commit_after>import uuid
from uritools import urisplit

from unis.models import Extent
from libdlt.logging import info, debug
from libdlt.protocol.ceph.allocation import CephExtent
from libdlt.protocol.ceph.services import ProtocolService
from libdlt.protocol.exceptions import AllocationException

ceph = ProtocolService()

@info("Ceph.factory")
def buildAllocation(obj):
    if type(obj) is str:
        try:
            obj = json.loads(obj)
        except Exception as exp:
            raise AllocationException("Could not decode json")
    if type(obj) is dict:
        alloc = CephExtent(obj)
    elif type(obj) in [CephExtent, Extent]:
        alloc = obj
    else:
        raise AllocationException("Invalid input type")
    return CephAdaptor(alloc)

@info("Ceph.factory")
async def makeAllocation(data, offset, depot, loop, **kwds):
    alloc = CephExtent()
    pool = kwds.get("pool", "dlt")
    oid = str(uuid.uuid4())
    alloc.location = "{0}/{1}/{2}".format(depot.endpoint, pool, oid)
    alloc.pool = pool
    alloc.offset = offset
    alloc.size = len(data)
    await ceph.write(oid, data, loop, **kwds)
    return CephAdaptor(alloc)

class CephAdaptor(object):
    @debug("CephAdaptor")
    def __init__(self, alloc, **kwds):
        self._allocation = alloc
        
    @info("CephAdaptor")
    def getMetadata(self):
        return self._allocation
        
    @info("CephAdaptor")
    def read(self, **kwds):
        o = urisplit(self._allocation.location)
        parts = o.path.split('/')
        size = self._allocation.size
        return ceph.read(parts[1], parts[2], size, **kwds)
    
    @info("CephAdaptor")
    def copy(self, depot, src_kwds, dst_kwds):
        dst_alloc = CephExtent()
        dst_oid = str(uuid.uuid4())
        pool = dst_kwds.get('pool', 'dlt')
        dst_alloc.location = "{}/{}/{}".format(depot.endpoint, pool, dst_oid)
        dst_alloc.pool = pool
        dst_alloc.size = self._allocation.size
        dst_alloc.offset = self._allocation.offset
        
        src = urisplit(self._allocation.location)
        src = src.path.split('/')
        size = self._allocation.size
        
        ceph.copy(src[1], src[2], dst_oid, size, src_kwds, dst_kwds)
        return CephAdaptor(dst_alloc)

{'fraction_non_alphanumeric': 0.12329969284774024, 'fraction_numerical': 0.003949100482667837, 'mean_word_length': 2.8440134907251267, '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': '2739486', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1511, 'n_words': 335}