Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 239bbfb

Browse files
author
Chris Glass
committed
All imports seem to be linked, now the real (testing) fun can begin!
1 parent c2b3eaa commit 239bbfb

File tree

7 files changed

+55
-50
lines changed

7 files changed

+55
-50
lines changed

xhtml2pdf/context.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
from reportlab.pdfbase.ttfonts import TTFont
88
from reportlab.platypus.frames import Frame
99
from reportlab.platypus.paraparser import ParaFrag, ps2tt, tt2ps
10-
from xhtml2pdf.reportlab import PmlPageTemplate, PmlTableOfContents, \
10+
from xhtml2pdf.xhtml2pdf_reportlab import PmlPageTemplate, PmlTableOfContents, \
1111
PmlParagraph, PmlParagraphAndImage
1212
from xhtml2pdf.util import getSize, getCoords, getFile, pisaFileObject
1313
from xhtml2pdf.w3c import css
1414
import copy
1515
import logging
1616
import os
17-
import default
18-
import parser
17+
import xhtml2pdf.default
18+
import xhtml2pdf.parser
1919
import re
2020
import reportlab
2121
import types
@@ -256,7 +256,7 @@ def atPage(self, name, pseudopage, declarations):
256256
log.warn(self.c.warning("template '%s' has already been defined", name))
257257

258258
if data.has_key("-pdf-page-size"):
259-
c.pageSize = pisa_default.PML_PAGESIZES.get(str(data["-pdf-page-size"]).lower(), c.pageSize)
259+
c.pageSize = xhtml2pdf.default.PML_PAGESIZES.get(str(data["-pdf-page-size"]).lower(), c.pageSize)
260260

261261
if data.has_key("size"):
262262
size = data["size"]
@@ -271,8 +271,8 @@ def atPage(self, name, pseudopage, declarations):
271271
sizeList.append(getSize(value))
272272
elif valueStr == "landscape":
273273
isLandscape = True
274-
elif pisa_default.PML_PAGESIZES.has_key(valueStr):
275-
c.pageSize = pisa_default.PML_PAGESIZES[valueStr]
274+
elif xhtml2pdf.default.PML_PAGESIZES.has_key(valueStr):
275+
c.pageSize = xhtml2pdf.default.PML_PAGESIZES[valueStr]
276276
else:
277277
log.warn(c.warning("Unknown size value for @page"))
278278

@@ -415,7 +415,7 @@ class pisaContext:
415415
"""
416416

417417
def __init__(self, path, debug=0, capacity=-1):
418-
self.fontList = copy.copy(pisa_default.DEFAULT_FONT)
418+
self.fontList = copy.copy(xhtml2pdf.default.DEFAULT_FONT)
419419
self.path = []
420420
self.capacity=capacity
421421

@@ -628,8 +628,8 @@ def addTOC(self):
628628
self.node.attributes["class"] = "pdftoclevel%d" % i
629629
#self.node.cssAttrs = copy.deepcopy(cssAttrs)
630630
#self.frag = copy.deepcopy(frag)
631-
self.cssAttr = pisa_parser.CSSCollect(self.node, self)
632-
pisa_parser.CSS2Frag(self, {
631+
self.cssAttr = xhtml2pdf.parser.CSSCollect(self.node, self)
632+
xhtml2pdf.parser.CSS2Frag(self, {
633633
"margin-top": 0,
634634
"margin-bottom": 0,
635635
"margin-left": 0,
@@ -892,15 +892,15 @@ def context(self, msg):
892892

893893
def warning(self, msg, *args):
894894
self.warn += 1
895-
self.log.append((pisa_default.PML_WARNING, self._getLineNumber(), str(msg), self._getFragment(50)))
895+
self.log.append((xhtml2pdf.default.PML_WARNING, self._getLineNumber(), str(msg), self._getFragment(50)))
896896
try:
897897
return self.context(msg % args)
898898
except:
899899
return self.context(msg)
900900

901901
def error(self, msg, *args):
902902
self.err += 1
903-
self.log.append((pisa_default.PML_ERROR, self._getLineNumber(), str(msg), self._getFragment(50)))
903+
self.log.append((xhtml2pdf.default.PML_ERROR, self._getLineNumber(), str(msg), self._getFragment(50)))
904904
try:
905905
return self.context(msg % args)
906906
except:

xhtml2pdf/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from xhtml2pdf.parser import pisaParser
55
from reportlab.platypus.flowables import Spacer
66
from reportlab.platypus.frames import Frame
7-
from xhtml2pdf.reportlab import PmlBaseDoc, PmlPageTemplate
7+
from xhtml2pdf.xhtml2pdf_reportlab import PmlBaseDoc, PmlPageTemplate
88
from xhtml2pdf.util import pisaTempFile, getBox, pyPdf
99
import cgi
1010
import logging

xhtml2pdf/parser.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,28 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import pprint
17+
from html5lib import treebuilders, serializer, treewalkers, inputstream
18+
from xhtml2pdf.default import * # TODO: Kill wild import!
19+
from xhtml2pdf.tables import * # TODO: Kill wild import!
20+
from xhtml2pdf.tags import * # TODO: Kill wild import!
21+
from xhtml2pdf.util import * # TODO: Kill wild import!
22+
from xhtml2pdf.xhtml2pdf_reportlab import PmlRightPageBreak, PmlLeftPageBreak
23+
from xml.dom import Node
1824
import copy
19-
import types
20-
import re
25+
import html5lib
26+
import logging
2127
import os
2228
import os.path
23-
24-
import html5lib
25-
from html5lib import treebuilders, serializer, treewalkers, inputstream
26-
from xml.dom import Node
29+
import pprint
30+
import re
31+
import types
32+
import xhtml2pdf.w3c.css as css
33+
import xhtml2pdf.w3c.cssDOMElementInterface as cssDOMElementInterface
2734
import xml.dom.minidom
2835

29-
from xhtml2pdf.default import * # TODO: Kill wild import!
30-
from xhtml2pdf.util import * # TODO: Kill wild import!
31-
from xhtml2pdf.tags import * # TODO: Kill wild import!
32-
from xhtml2pdf.tables import * # TODO: Kill wild import!
3336

34-
import xhtml2pdf.w3c.css as css
35-
import xhtml2pdf.w3c.cssDOMElementInterface as cssDOMElementInterface
3637

37-
import logging
38+
3839
log = logging.getLogger("ho.pisa")
3940

4041
rxhttpstrip = re.compile("https?://[^/]+(.*)", re.M | re.I)
@@ -608,9 +609,8 @@ def pisaParser(src, c, default_css="", xhtml=False, encoding=None, xml_output=No
608609
if not inputstream.isValidEncoding(encoding):
609610
log.error("%r is not a valid encoding e.g. 'utf8' is not valid but 'utf-8' is!", encoding)
610611
else:
611-
if inputstream.codecName(encoding) is None:
612-
log.error("%r is not a valid encoding", encoding)
613-
import ipdb; ipdb.set_trace()
612+
if inputstream.codecName(encoding) is None:
613+
log.error("%r is not a valid encoding", encoding)
614614
document = parser.parse(
615615
src,
616616
encoding=encoding)

xhtml2pdf/pisa.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from xhtml2pdf.default import DEFAULT_CSS
3-
from xhtml2pdf.document import * # TODO: Kill wild import
3+
from xhtml2pdf.document import pisaDocument
44
from xhtml2pdf.util import getFile
55
from xhtml2pdf.version import VERSION, VERSION_STR
66
import getopt
@@ -282,7 +282,6 @@ def execute():
282282
print "--------------------------------------------"
283283
print "OS: ", sys.platform
284284
print "Python: ", sys.version
285-
import html5lib
286285
print "html5lib: ", "?"
287286
import reportlab
288287
print "Reportlab: ", reportlab.Version

xhtml2pdf/tables.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
from xhtml2pdf.reportlab import PmlTable, TableStyle, PmlKeepInFrame
3-
from xhtml2pdf.tags import pisaTag
2+
from reportlab.platypus.tables import TableStyle
43
from sx.pisa3.pisa_util import getSize, getBorderStyle, getAlign
4+
from xhtml2pdf.tags import pisaTag
5+
from xhtml2pdf.xhtml2pdf_reportlab import PmlTable, PmlKeepInFrame
56
import copy
67
import logging
78

xhtml2pdf/tags.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from reportlab.platypus.flowables import Spacer, HRFlowable, PageBreak, Flowable
77
from reportlab.platypus.frames import Frame
88
from reportlab.platypus.paraparser import tt2ps, ABag
9-
from xhtml2pdf.reportlab import PmlImage, PmlPageTemplate
9+
from xhtml2pdf import xhtml2pdf_reportlab
1010
from xhtml2pdf.util import getColor, getSize, getAlign, dpi96
11+
from xhtml2pdf.xhtml2pdf_reportlab import PmlImage, PmlPageTemplate
1112
import copy
1213
import logging
13-
from xhtml2pdf import reportlab
1414
import re
1515
import warnings
1616

@@ -379,7 +379,7 @@ def _render(self, c, attr):
379379
if attr.type == "text":
380380
width = 100
381381
height = 12
382-
c.addStory(pisa_reportlab.PmlInput(attr.name,
382+
c.addStory(xhtml2pdf_reportlab.PmlInput(attr.name,
383383
type=attr.type,
384384
default=attr.value,
385385
width=width,
@@ -396,7 +396,7 @@ def end(self, c):
396396
class pisaTagTEXTAREA(pisaTagINPUT):
397397

398398
def _render(self, c, attr):
399-
c.addStory(pisa_reportlab.PmlInput(attr.name,
399+
c.addStory(xhtml2pdf_reportlab.PmlInput(attr.name,
400400
default="",
401401
width=100,
402402
height=100))
@@ -407,7 +407,7 @@ def start(self, c):
407407
c.select_options = ["One", "Two", "Three"]
408408

409409
def _render(self, c, attr):
410-
c.addStory(pisa_reportlab.PmlInput(attr.name,
410+
c.addStory(xhtml2pdf_reportlab.PmlInput(attr.name,
411411
type="select",
412412
default=c.select_options[0],
413413
options=c.select_options,

xhtml2pdf/reportlab.py renamed to xhtml2pdf/xhtml2pdf_reportlab.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,26 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from reportlab.platypus.doctemplate import BaseDocTemplate, PageTemplate, FrameBreak, NextPageTemplate
18-
from reportlab.platypus.tables import Table, TableStyle
19-
from reportlab.platypus.flowables import Flowable, Image, CondPageBreak, KeepInFrame, ParagraphAndImage
20-
from reportlab.platypus.frames import Frame
17+
from hashlib import md5
18+
from reportlab.lib.enums import TA_RIGHT
19+
from reportlab.lib.styles import ParagraphStyle
20+
from reportlab.lib.utils import flatten, open_for_read, getStringIO, \
21+
LazyImageReader, haveImages
22+
from reportlab.platypus.doctemplate import BaseDocTemplate, PageTemplate
23+
from reportlab.platypus.flowables import Flowable, Image, CondPageBreak, \
24+
KeepInFrame, ParagraphAndImage
2125
from reportlab.platypus.tableofcontents import TableOfContents
26+
from reportlab.platypus.tables import Table, TableStyle
27+
from xhtml2pdf.reportlab_paragraph import Paragraph
28+
from xhtml2pdf.util import getUID, getBorderStyle
29+
import StringIO
30+
import cgi
31+
import copy
32+
import logging
33+
import reportlab.pdfbase.pdfform as pdfform
34+
import sys
2235

23-
from reportlab_paragraph import Paragraph
2436

25-
from reportlab.lib.utils import * # TODO: Kill the wild import!
2637

2738
try:
2839
import PIL.Image as PILImage
@@ -32,13 +43,8 @@
3243
except:
3344
PILImage = None
3445

35-
from xhtml2pdf.util import * # TODO: Kill the wild import!
36-
from xhtml2pdf.default import TAGS, STRING
3746

38-
import copy
39-
import cgi
4047

41-
import logging
4248
log = logging.getLogger("ho.pisa")
4349

4450
MAX_IMAGE_RATIO = 0.95
@@ -776,7 +782,6 @@ def wrap(self, availWidth, availHeight):
776782

777783
# --- Pdf Form
778784

779-
import reportlab.pdfbase.pdfform as pdfform
780785

781786
class PmlInput(Flowable):
782787

0 commit comments

Comments
 (0)