<commit_before># A part of pdfrw (pdfrw.googlecode.com)
# Copyright (C) 2006-2009 <NAME>, Austin, Texas
# MIT license -- See LICENSE.txt for details

'''
Converts pdfrw objects into reportlab objects.

Designed for and tested with rl 2.3.

Knows too much about reportlab internals.
What can you do?

The interface to this function is through the makerl() function.

Parameters:
        rldoc       - a reportlab "document"
        pdfobj      - a top-level pdfrw PDF object
        isxobj      - set True if pdfobj is an XObject

Returns:
        A corresponding reportlab object, or the object
        name if the object is an Xobject.

Notes:
    1) Original objects are annotated with a
        _rl_obj attribute which points to the
        reportlab object.  This is great for
        not putting too many objects into the
        new PDF, but not so good if you are modifying
        objects for different pages.  Then you
        need to do your own deep copying (of circular
        structures).  You're on your own.

    2) ReportLab seems weird about FormXObjects.
       They pass around a partial name instead of the
       object or a reference to it.  So we have to
       reach into reportlab and get a number for
       a unique name.  I guess this is to make it
       where you can combine page streams with
       impunity, but that's just a guess.

makerl(rldoc, pdfobj, isxobj=False):

'''

from reportlab.pdfbase import pdfdoc as rldocmodule
from pdfobjects import PdfDict, PdfArray

RLStream = rldocmodule.PDFStream
RLDict = rldocmodule.PDFDictionary
RLArray = rldocmodule.PDFArray


def _makedict(rldoc, pdfobj, isxobj):
    assert isinstance(pdfobj, PdfDict)
    assert pdfobj.stream is None
    assert pdfobj._rl_obj is None
    assert not isxobj

    rlobj = rldict = RLDict()
    if pdfobj.indirect:
        rlobj.__RefOnly__ = 1
        rlobj = rldoc.Reference(rlobj)
    pdfobj.private._rl_obj = rlobj

    for key, value in pdfobj.iteritems():
        rldict[key[1:]] = makerl(rldoc, value)

    return rlobj

def _makestream(rldoc, pdfobj, isxobj):
    assert isinstance(pdfobj, PdfDict)
    assert pdfobj.stream is not None
    assert pdfobj._rl_obj is None

    if isxobj:
        name = 'pdfrw_%s' % (rldoc.objectcounter+1)
        xobjname = rldoc.getXObjectName(name)
    else:
        name = xobjname = None
    rldict = RLDict()
    rlobj = RLStream(rldict, pdfobj.stream)
    rlobj = rldoc.Reference(rlobj, xobjname)
    pdfobj.private._rl_obj = rlobj

    for key, value in pdfobj.iteritems():
        rldict[key[1:]] = makerl(rldoc, value)

    return name or rlobj

def _makearray(rldoc, pdfobj, isxobj):
    assert isinstance(pdfobj, PdfArray)
    assert not hasattr(pdfobj, '_rl_obj')
    assert not isxobj

    rlobj = rlarray = RLArray([])
    if pdfobj.indirect:<commit_msg>Bugfix: Keep reportlab name, rather than object reference, for reuse.<commit_after># A part of pdfrw (pdfrw.googlecode.com)
# Copyright (C) 2006-2009 <NAME>, Austin, Texas
# MIT license -- See LICENSE.txt for details

'''
Converts pdfrw objects into reportlab objects.

Designed for and tested with rl 2.3.

Knows too much about reportlab internals.
What can you do?

The interface to this function is through the makerl() function.

Parameters:
        rldoc       - a reportlab "document"
        pdfobj      - a top-level pdfrw PDF object
        isxobj      - set True if pdfobj is an XObject

Returns:
        A corresponding reportlab object, or the object
        name if the object is an Xobject.

Notes:
    1) Original objects are annotated with a
        _rl_obj attribute which points to the
        reportlab object.  This is great for
        not putting too many objects into the
        new PDF, but not so good if you are modifying
        objects for different pages.  Then you
        need to do your own deep copying (of circular
        structures).  You're on your own.

    2) ReportLab seems weird about FormXObjects.
       They pass around a partial name instead of the
       object or a reference to it.  So we have to
       reach into reportlab and get a number for
       a unique name.  I guess this is to make it
       where you can combine page streams with
       impunity, but that's just a guess.

makerl(rldoc, pdfobj, isxobj=False):

'''

from reportlab.pdfbase import pdfdoc as rldocmodule
from pdfobjects import PdfDict, PdfArray

RLStream = rldocmodule.PDFStream
RLDict = rldocmodule.PDFDictionary
RLArray = rldocmodule.PDFArray


def _makedict(rldoc, pdfobj, isxobj):
    assert isinstance(pdfobj, PdfDict)
    assert pdfobj.stream is None
    assert pdfobj._rl_obj is None
    assert not isxobj

    rlobj = rldict = RLDict()
    if pdfobj.indirect:
        rlobj.__RefOnly__ = 1
        rlobj = rldoc.Reference(rlobj)
    pdfobj.private._rl_obj = rlobj

    for key, value in pdfobj.iteritems():
        rldict[key[1:]] = makerl(rldoc, value)

    return rlobj

def _makestream(rldoc, pdfobj, isxobj):
    assert isinstance(pdfobj, PdfDict)
    assert pdfobj.stream is not None
    assert pdfobj._rl_obj is None

    rldict = RLDict()
    rlobj = RLStream(rldict, pdfobj.stream)

    if isxobj:
        result = 'pdfrw_%s' % (rldoc.objectcounter+1)
        rldoc.Reference(rlobj, rldoc.getXObjectName(result))
    else:
        result = rldoc.Reference(rlobj)
    pdfobj.private._rl_obj = result

    for key, value in pdfobj.iteritems():
        rldict[key[1:]] = makerl(rldoc, value)

    return result

def _makearray(rldoc, pdfobj, isxobj):
    assert isinstance(pdfobj, PdfArray)
    assert not hasattr(pdfobj, '_rl_obj')
    assert not isxobj

    rlobj = rlarray = RLArray([])
    if pdfobj.indirect:
{'fraction_non_alphanumeric': 0.06838209376101516, 'fraction_numerical': 0.005639760310186817, 'mean_word_length': 2.8087248322147653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1508262', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1781, 'n_words': 652}