本文整理汇总了Python中reportlab.lib.utils.open_and_read函数的典型用法代码示例。如果您正苦于以下问题:Python open_and_read函数的具体用法?Python open_and_read怎么用?Python open_and_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了open_and_read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(pagesize=None, verbose=0, outDir=None):
import os
from reportlab.tools.docco.rl_doc_utils import setStory, getStory, RLDocTemplate, defaultPageSize
from reportlab.tools.docco import rl_doc_utils
from reportlab.lib.utils import open_and_read, _RL_DIR
if not outDir: outDir = os.path.join(_RL_DIR,'docs')
destfn = os.path.join(outDir,'userguide.pdf')
doc = RLDocTemplate(destfn,pagesize = pagesize or defaultPageSize)
#this builds the story
setStory()
G = {}
exec 'from reportlab.tools.docco.rl_doc_utils import *' in G, G
for f in (
'ch1_intro',
'ch2_graphics',
'ch2a_fonts',
'ch3_pdffeatures',
'ch4_platypus_concepts',
'ch5_paragraphs',
'ch6_tables',
'ch7_custom',
'ch9_future',
'app_demos',
):
exec open_and_read(f+'.py',mode='t') in G, G
del G
story = getStory()
if verbose: print 'Built story contains %d flowables...' % len(story)
doc.build(story)
if verbose: print 'Saved "%s"' % destfn
开发者ID:alexissmirnov,项目名称:donomo,代码行数:32,代码来源:genuserguide.py
示例2: run
def run(pagesize=None, verbose=1, outDir=None):
import os
from reportlab.tools.docco.rl_doc_utils import setStory, getStory, RLDocTemplate, defaultPageSize
from reportlab.tools.docco import rl_doc_utils
from reportlab.lib.utils import open_and_read, _RL_DIR
if not outDir: outDir = os.path.join(_RL_DIR,'docs')
destfn = os.path.join(outDir,'graphguide.pdf')
doc = RLDocTemplate(destfn,pagesize = pagesize or defaultPageSize)
#this builds the story
setStory()
G = {}
exec 'from reportlab.tools.docco.rl_doc_utils import *' in G, G
doc = RLDocTemplate(destfn,pagesize = pagesize or defaultPageSize)
for f in (
'ch1_intro',
'ch2_concepts',
'ch3_shapes',
'ch4_widgets',
'ch5_charts',
):
exec open_and_read(f+'.py',mode='t') in G, G
del G
story = getStory()
if verbose: print 'Built story contains %d flowables...' % len(story)
doc.build(story)
if verbose: print 'Saved "%s"' % destfn
开发者ID:eaudeweb,项目名称:naaya,代码行数:28,代码来源:gengraphguide.py
示例3: run
def run(pagesize=None, verbose=0, outDir=None):
import sys,os
from reportlab.lib.utils import open_and_read
cwd = os.getcwd()
docsDir=os.path.dirname(os.path.dirname(sys.argv[0]) or cwd)
topDir=os.path.dirname(docsDir)
if not outDir: outDir=docsDir
G = {}
sys.path.insert(0,topDir)
from reportlab.pdfbase.pdfmetrics import registerFontFamily
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont('Vera', 'Vera.ttf'))
pdfmetrics.registerFont(TTFont('VeraBd', 'VeraBd.ttf'))
pdfmetrics.registerFont(TTFont('VeraIt', 'VeraIt.ttf'))
pdfmetrics.registerFont(TTFont('VeraBI', 'VeraBI.ttf'))
registerFontFamily('Vera',normal='Vera',bold='VeraBd',italic='VeraIt',boldItalic='VeraBI')
from tools.docco.rl_doc_utils import setStory, getStory, RLDocTemplate, defaultPageSize, H1, H2, H3, H4
from tools.docco import rl_doc_utils
exec 'from tools.docco.rl_doc_utils import *' in G, G
destfn = os.path.join(outDir,'reportlab-userguide.pdf')
doc = RLDocTemplate(destfn,pagesize = pagesize or defaultPageSize)
#this builds the story
setStory()
for f in (
'ch1_intro',
'ch2_graphics',
'ch2a_fonts',
'ch3_pdffeatures',
'ch4_platypus_concepts',
'ch5_paragraphs',
'ch6_tables',
'ch7_custom',
'graph_intro',
'graph_concepts',
'graph_charts',
'graph_shapes',
'graph_widgets',
'app_demos',
):
exec open_and_read(f+'.py',mode='t') in G, G
del G
story = getStory()
if verbose: print 'Built story contains %d flowables...' % len(story)
doc.multiBuild(story)
if verbose: print 'Saved "%s"' % destfn
开发者ID:jbacou,项目名称:myReportLab_installPackage,代码行数:50,代码来源:genuserguide.py
示例4: checkFileForTabs
def checkFileForTabs(self, filename):
txt = open_and_read(filename, "r")
chunks = string.split(txt, "\t")
tabCount = len(chunks) - 1
if tabCount:
# raise Exception, "File %s contains %d tab characters!" % (filename, tabCount)
self.output.write("file %s contains %d tab characters!\n" % (filename, tabCount))
开发者ID:eaudeweb,项目名称:naaya,代码行数:7,代码来源:test_source_chars.py
示例5: eoCB
def eoCB(s,targets=targets,dtdDirs=dtdDirs):
from reportlab.lib.utils import open_and_read, rl_isfile
bn = os.path.basename(s)
if bn in targets:
for d in dtdDirs:
fn = os.path.join(d,bn)
if rl_isfile(fn): return fn, open_and_read(fn,'t')
return s
开发者ID:AndyKovv,项目名称:hostel,代码行数:8,代码来源:xmlutils.py
示例6: _rel_open_and_read
def _rel_open_and_read(fn):
from reportlab.lib.utils import open_and_read
from reportlab.lib.testutils import testsFolder
cwd = os.getcwd()
os.chdir(testsFolder)
try:
return open_and_read(fn)
finally:
os.chdir(cwd)
开发者ID:sengupta,项目名称:scilab_cloud,代码行数:9,代码来源:test_lib_utils.py
示例7: run
def run(pagesize=None, verbose=0, outDir=None):
import sys, os
from reportlab.lib.utils import open_and_read
cwd = os.getcwd()
docsDir = os.path.dirname(os.path.dirname(sys.argv[0]) or cwd)
topDir = os.path.dirname(docsDir)
if not outDir:
outDir = docsDir
G = {}
sys.path.insert(0, topDir)
from reportlab.pdfbase.pdfmetrics import registerFontFamily
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont("Vera", "Vera.ttf"))
pdfmetrics.registerFont(TTFont("VeraBd", "VeraBd.ttf"))
pdfmetrics.registerFont(TTFont("VeraIt", "VeraIt.ttf"))
pdfmetrics.registerFont(TTFont("VeraBI", "VeraBI.ttf"))
registerFontFamily("Vera", normal="Vera", bold="VeraBd", italic="VeraIt", boldItalic="VeraBI")
from tools.docco.rl_doc_utils import setStory, getStory, RLDocTemplate, defaultPageSize, H1, H2, H3, H4
from tools.docco import rl_doc_utils
exec("from tools.docco.rl_doc_utils import *", G, G)
destfn = os.path.join(outDir, "reportlab-userguide.pdf")
doc = RLDocTemplate(destfn, pagesize=pagesize or defaultPageSize)
# this builds the story
setStory()
for f in (
"ch1_intro",
"ch2_graphics",
"ch2a_fonts",
"ch3_pdffeatures",
"ch4_platypus_concepts",
"ch5_paragraphs",
"ch6_tables",
"ch7_custom",
"graph_intro",
"graph_concepts",
"graph_charts",
"graph_shapes",
"graph_widgets",
"app_demos",
):
exec(open_and_read(f + ".py", mode="t"), G, G)
del G
story = getStory()
if verbose:
print("Built story contains %d flowables..." % len(story))
doc.multiBuild(story)
if verbose:
print('Saved "%s"' % destfn)
开发者ID:wolf29,项目名称:EG-notifications,代码行数:55,代码来源:genuserguide.py
示例8: xml2rad
def xml2rad(xml, validating=1, eoCB=None):
'''convert xml to radxml form'''
if validating:
from reportlab.lib.utils import isCompactDistro, open_and_read
if not eoCB and isCompactDistro():
eoCB = lambda x, open_and_read=open_and_read: (x, open_and_read(x))
import pyRXPU
rad = pyRXPU.Parser().parse(xml,eoCB=eoCB)
else:
from reportlab.lib import rparsexml
rad = rparsexml.parsexml0(xml)[0][2][0]
return rad
开发者ID:AndyKovv,项目名称:hostel,代码行数:12,代码来源:xmlutils.py
示例9: testAscii
def testAscii(self):
"Test if Python files are pure ASCII ones."
from reportlab.lib.testutils import RL_HOME
allPyFiles = GlobDirectoryWalker(RL_HOME, '*.py')
for path in allPyFiles:
fileContent = open_and_read(path,'r')
nonAscii = u''.join(list(set([c for c in fileContent if ord(c)>127])))
truncPath = path[path.find('reportlab'):]
args = (truncPath, repr(map(ord, nonAscii)))
msg = "File %s contains characters: %s." % args
assert len(nonAscii) == 0, msg
开发者ID:jeffery9,项目名称:reportlab,代码行数:13,代码来源:test_pyfiles.py
示例10: run
def run(pagesize=None, verbose=0, outDir=None):
import os
from reportlab.tools.docco.rl_doc_utils import setStory, getStory, RLDocTemplate, defaultPageSize
from reportlab.tools.docco import rl_doc_utils
from reportlab.lib.utils import open_and_read, _RL_DIR
if not outDir:
outDir = '../manuals/'#os.path.join(_RL_DIR,'docs')
if not os.path.isdir(outDir):
os.mkdir(outDir)
destfn = os.path.join(outDir,'X4 - Installazione.pdf')
doc = RLDocTemplate(destfn,pagesize = pagesize or defaultPageSize)
doc.title = 'X4 Setup'
doc.subject = 'Manuale di installazione di X4GA'
doc.author = 'Astra S.r.l.'
#this builds the story
setStory()
G = {}
exec 'from reportlab.tools.docco.rl_doc_utils import *' in G, G
for f in (
'ch1_intro',
'ch2_dbengine',
'ch3_workstation',
#'ch3_pdffeatures',
#'ch4_platypus_concepts',
#'ch5_paragraphs',
#'ch6_tables',
#'ch7_custom',
#'ch9_future',
#'app_demos',
):
exec open_and_read(f+'.py',mode='t') in G, G
del G
story = getStory()
if verbose: print 'Built story contains %d flowables...' % len(story)
doc.build(story)
if verbose: print 'Saved "%s"' % destfn
开发者ID:alexsandrino,项目名称:X4GA,代码行数:38,代码来源:genuserguide.py
示例11: checkFileForTrailingSpaces
def checkFileForTrailingSpaces(self, filename):
txt = open_and_read(filename, 'r')
initSize = len(txt)
badLines = 0
badChars = 0
for line in string.split(txt, '\n'):
stripped = string.rstrip(line)
spaces = len(line) - len(stripped) # OK, so they might be trailing tabs, who cares?
if spaces:
badLines = badLines + 1
badChars = badChars + spaces
if badChars != 0:
self.output.write("file %s contains %d trailing spaces, or %0.2f%% wastage\n" % (filename, badChars, 100.0*badChars/initSize))
开发者ID:sengupta,项目名称:scilab_cloud,代码行数:14,代码来源:test_source_chars.py
示例12: _loadGlyphs
def _loadGlyphs(self, pfbFileName):
"""Loads in binary glyph data, and finds the four length
measurements needed for the font descriptor"""
assert rl_isfile(pfbFileName), 'file %s not found' % pfbFileName
d = open_and_read(pfbFileName, 'b')
s1, l1 = _pfbCheck(0,d,PFB_ASCII,pfbFileName)
s2, l2 = _pfbCheck(l1,d,PFB_BINARY,pfbFileName)
s3, l3 = _pfbCheck(l2,d,PFB_ASCII,pfbFileName)
_pfbCheck(l3,d,PFB_EOF,pfbFileName)
self._binaryData = d[s1:l1]+d[s2:l2]+d[s3:l3]
self._length = len(self._binaryData)
self._length1 = l1-s1
self._length2 = l2-s2
self._length3 = l3-s3
开发者ID:eaudeweb,项目名称:naaya,代码行数:15,代码来源:pdfmetrics.py
示例13: testAscii
def testAscii(self):
"Test if Python files are pure ASCII ones."
from reportlab.lib.testutils import RL_HOME
allPyFiles = GlobDirectoryWalker(RL_HOME, '*.py')
for path in allPyFiles:
fileContent = open_and_read(path,'r')
nonAscii = filter(lambda c: ord(c)>127, fileContent)
nonAscii = unique(nonAscii)
truncPath = path[string.find(path, 'reportlab'):]
args = (truncPath, repr(map(ord, nonAscii)))
msg = "File %s contains characters: %s." % args
## if nonAscii:
## print msg
assert nonAscii == '', msg
开发者ID:ingob,项目名称:mwlib.ext,代码行数:16,代码来源:test_pyfiles.py
示例14: epsBBox
def epsBBox(fn,bbpat=re.compile(r'^\s*%%boundingbox:\s*(.*)\s*$',re.I|re.M)):
'''
read an eps file and attempt to obtain its bounding box
>>> cleanup()
>>> x=pdfConvert('zzzdingo.pdf',scale=0.5,device='eps',outfile='zzzdingo.eps')
>>> assert x and os.path.isfile(os.path.basename(x[0]))
>>> print epsBBox('zzzdingo.eps')
[0, 0, 100, 50]
'''
text = open_and_read(fn)
m=bbpat.search(text)
if not m:
raise ValueError('Cannot find bounding box in "%s"' % fn)
bb = m.group(1).strip().split()
if len(bb)!=4:
raise ValueError('Not enough bounding box entries "%s" found in "%s"' % (m.group(0).strip(),fn))
try:
return list(map(float,bb))
except:
raise ValueError('Bad bounding box entries "%s" found in "%s"' % (m.group(0).strip(),fn))
开发者ID:AndyKovv,项目名称:hostel,代码行数:21,代码来源:pdf2jpeg.py
示例15: open
def open(self, fileName):
"""Parse and resolve a PDF file as much as possible"""
from reportlab.lib.utils import open_and_read
self.rawContent = open_and_read(fileName)
self._parse()
开发者ID:AndyKovv,项目名称:hostel,代码行数:5,代码来源:pdfexplorer.py
示例16: includePdfFlowables
def includePdfFlowables(fileName,
pages=None,
dx=0, dy=0, sx=1, sy=1, degrees=0,
orientation=None,
isdata=False, #True if this is a preprocessed data file
leadingBreak=True, #True/False or 'notattop'
template=None,
outlineText=None,
outlineLevel=0,
outlineClosed=0,
pdfBoxType = None,
autoCrop = False,
pageSize=None,
callback=None,
user_data=None,
):
'''
includePdfFlowables creates a list of story flowables that
represents an included PDF.
Arguments meaning
fileName string name of a .pdf or .data file
pages If None all pages will be used, else this argument can
be a string like '1,2,4-6,12-10,15' or an explicit
list of integers eg [1,2,7].
dx,dy, translation together all these make up a transformation
sx,sy, scaling matrix
degrees, rotation
orientation None or integer degrees eg 0 90 270 or 'portrait'/'landscape'
isdata True if fileName argument refers to a .data file (as
produced by pageCatcher)
leadingBreak True/False or 'notattop' specifies whether a leading
page break should be used; 'notattop' means a page break
will not be used if the story is at the top of a frame.
template If specified the index or name of a template to be used.
outlineText Any outline text to be used (default None)
outlineLevel The level of any outline text.
outlineClosed True/False if the outline should be closed or open.
pdfBoxType which box to use or None or [x0,y0, x1,y1]
autoCrop True/False crop/don't crop with CropBox (default is False)
boxname use for cropping
[x0,y0, x1,y1] crop area
pageSize default None ie leave page size alone
'set' adjust page size to incoming box
'fit' scale incoming box to fit page size
'orthfit' orthogonally scale incoming box to fit
'center' or 'centre' center the incoming box in
the existing page size
[x0,y0, x1,y1] use this as the page size
callback draw time callback with signature
callback(canvas,key,obj,pdf_data,user_data)
canvas the canvas being drawn on
key may be 'raw-pre'|'transformed-pre'|'transformed-post'|'raw-post'
obj the flowable calling the callback
pdf_data ('fileName',pageNumber)
user_data user data passed down to the flowable from
IncludePdfFlowable.
user_data information to be passed to the callback
'''
try:
orientation=int(orientation)
orientation = orientation % 360
except:
if orientation=='portrait':
orientation = 0
elif orientation=='landscape':
orientation = 90
elif orientation!='auto' and orientation!=None:
raise ValueError('Bad value %r for orientation attribute' % orientation)
iptrans = IPTrans(sx,sy,dx,dy,degrees)
if iptrans.trivial(): iptrans = None
pages = expandPageNumbers(pages)
# this one is unusual in that it returns a list of objects to
# go into the story.
output = []
output_append = output.append
if template:
output_append(NextPageTemplate(template))
try:
if isdata:
pickledStuff = pickle.loads(open_and_read(fileName))
formNames = pickledStuff[None]
else:
#read in the PDF file right now and get the pickled object
# and names
pdfContent = open_and_read(fileName)
prefix = fileName2Prefix(fileName)
#.........这里部分代码省略.........
开发者ID:AndyKovv,项目名称:hostel,代码行数:101,代码来源:pageflow.py
示例17: test10
def test10(self):
"test open and read of a simple relative file"
from reportlab.lib.utils import open_and_read, getStringIO
b = getStringIO(open_and_read('../docs/images/Edit_Prefs.gif'))
b = open_and_read(b)
开发者ID:eaudeweb,项目名称:naaya,代码行数:5,代码来源:test_lib_utils.py
示例18: test9
def test9(self):
"test open and read of an http: URL"
from reportlab.lib.utils import open_and_read
b = open_and_read('http://www.reportlab.com/rsrc/encryption.gif')
开发者ID:eaudeweb,项目名称:naaya,代码行数:4,代码来源:test_lib_utils.py
示例19: test8
def test8(self):
"test open and read of a relative file: URL"
from reportlab.lib.utils import open_and_read
b = open_and_read('file:../docs/images/Edit_Prefs.gif')
开发者ID:eaudeweb,项目名称:naaya,代码行数:4,代码来源:test_lib_utils.py
示例20: test7
def test7(self):
"test open and read of a simple relative file"
from reportlab.lib.utils import open_and_read
b = open_and_read('../docs/images/Edit_Prefs.gif')
开发者ID:eaudeweb,项目名称:naaya,代码行数:4,代码来源:test_lib_utils.py
注:本文中的reportlab.lib.utils.open_and_read函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论