Skip to content

Commit

Permalink
Adapted our ParaParser to work with ReportLab 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Jul 24, 2014
1 parent 80d7fa4 commit 05675af
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/z3c/rml/paraparser.py
Expand Up @@ -23,8 +23,8 @@
class PageNumberFragment(reportlab.platypus.paraparser.ParaFrag):
"""A fragment whose `text` is computed at access time."""

def __init__(self, attributes):
reportlab.platypus.paraparser.ParaFrag.__init__(self)
def __init__(self, **attributes):
reportlab.platypus.paraparser.ParaFrag.__init__(self, **attributes)
self.counting_from = attributes.get('countingFrom', 1)

@property
Expand All @@ -50,8 +50,8 @@ def text(self):
class GetNameFragment(reportlab.platypus.paraparser.ParaFrag):
"""A fragment whose `text` is computed at access time."""

def __init__(self, attributes):
reportlab.platypus.paraparser.ParaFrag.__init__(self)
def __init__(self, **attributes):
reportlab.platypus.paraparser.ParaFrag.__init__(self, **attributes)
self.id = attributes['id']
self.default = attributes.get('default')

Expand All @@ -78,8 +78,8 @@ def text(self):
class EvalStringFragment(reportlab.platypus.paraparser.ParaFrag):
"""A fragment whose `text` is evaluated at access time."""

def __init__(self, attributes):
reportlab.platypus.paraparser.ParaFrag.__init__(self)
def __init__(self, **attributes):
reportlab.platypus.paraparser.ParaFrag.__init__(self, **attributes)
self.frags = []

@property
Expand All @@ -97,10 +97,8 @@ def text(self):
class NameFragment(reportlab.platypus.paraparser.ParaFrag):
"""A fragment whose attribute `value` is set to a variable."""

def __init__(self, attributes):
reportlab.platypus.paraparser.ParaFrag.__init__(self)
self.id = attributes['id']
self.value = attributes['value']
def __init__(self, **attributes):
reportlab.platypus.paraparser.ParaFrag.__init__(self, **attributes)

@property
def text(self):
Expand Down Expand Up @@ -131,7 +129,7 @@ def __init__(self, *args, **kwargs):
self.in_eval = False

def startDynamic(self, attributes, klass):
frag = klass(attributes)
frag = klass(**attributes)
frag.__dict__.update(self._stack[-1].__dict__)
frag.fontName = reportlab.lib.fonts.tt2ps(
frag.fontName, frag.bold, frag.italic)
Expand All @@ -145,16 +143,16 @@ def endDynamic(self):
if not self.in_eval:
self._pop()

def start_pageNumber(self, attributes):
def start_pagenumber(self, attributes):
self.startDynamic(attributes, PageNumberFragment)

def end_pageNumber(self):
def end_pagenumber(self):
self.endDynamic()

def start_getName(self, attributes):
def start_getname(self, attributes):
self.startDynamic(attributes, GetNameFragment)

def end_getName(self):
def end_getname(self):
self.endDynamic()

def start_name(self, attributes):
Expand All @@ -163,11 +161,11 @@ def start_name(self, attributes):
def end_name(self):
self.endDynamic()

def start_evalString(self, attributes):
def start_evalstring(self, attributes):
self.startDynamic(attributes, EvalStringFragment)
self.in_eval = True

def end_evalString(self):
def end_evalstring(self):
self.in_eval = False
self.endDynamic()

Expand All @@ -180,4 +178,4 @@ def handle_data(self, data):

# Monkey-patch reportlabs global parser instance. Wah.
import reportlab.platypus.paragraph
reportlab.platypus.paragraph._parser = Z3CParagraphParser()
reportlab.platypus.paragraph.ParaParser = Z3CParagraphParser

0 comments on commit 05675af

Please sign in to comment.