本文整理汇总了Python中Preprocessor.Preprocessor.do_include方法的典型用法代码示例。如果您正苦于以下问题:Python Preprocessor.do_include方法的具体用法?Python Preprocessor.do_include怎么用?Python Preprocessor.do_include使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Preprocessor.Preprocessor
的用法示例。
在下文中一共展示了Preprocessor.do_include方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preprocess
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import do_include [as 别名]
def preprocess(input, parser, defines={}):
'''
Preprocess the file-like input with the given defines, and send the
preprocessed output line by line to the given parser.
'''
pp = Preprocessor()
pp.context.update(defines)
pp.do_filter('substitution')
pp.out = PreprocessorOutputWrapper(pp, parser)
pp.do_include(input)
示例2: TestLineEndings
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import do_include [as 别名]
class TestLineEndings(unittest.TestCase):
"""
Unit tests for the Context class
"""
def setUp(self):
self.pp = Preprocessor()
self.pp.out = StringIO()
self.tempnam = os.tempnam('.')
def tearDown(self):
os.remove(self.tempnam)
def createFile(self, lineendings):
f = open(self.tempnam, 'wb')
for line, ending in zip(['a', '#literal b', 'c'], lineendings):
f.write(line+ending)
f.close()
def testMac(self):
self.createFile(['\x0D']*3)
self.pp.do_include(self.tempnam)
self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
def testUnix(self):
self.createFile(['\x0A']*3)
self.pp.do_include(self.tempnam)
self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
def testWindows(self):
self.createFile(['\x0D\x0A']*3)
self.pp.do_include(self.tempnam)
self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
示例3: TestPreprocessor
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import do_include [as 别名]
class TestPreprocessor(unittest.TestCase):
"""
Unit tests for the Context class
"""
def setUp(self):
self.pp = Preprocessor()
self.pp.out = StringIO()
def test_conditional_if_0(self):
f = NamedIO("conditional_if_0.in", """#if 0
FAIL
#else
PASS
#endif
""")
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "PASS\n")
def test_string_value(self):
f = NamedIO("string_value.in", """#define FOO STRING
#if FOO
string value is true
#else
string value is false
#endif
""")
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "string value is false\n")
def test_number_value(self):
f = NamedIO("string_value.in", """#define FOO 1
#if FOO
number value is true
#else
number value is false
#endif
""")
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "number value is true\n")
def test_conditional_if_0_elif_1(self):
f = NamedIO('conditional_if_0_elif_1.in', '''#if 0
#elif 1
PASS
#else
FAIL
#endif
''')
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "PASS\n")
def test_conditional_if_1(self):
f = NamedIO('conditional_if_1.in', '''#if 1
PASS
#else
FAILE
#endif
''')
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "PASS\n")
def test_conditional_if_1_elif_1_else(self):
f = NamedIO('conditional_if_1_elif_1_else.in', '''#if 1
PASS
#elif 1
FAIL
#else
FAIL
#endif
''')
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "PASS\n")
def test_conditional_if_1_if_1(self):
f = NamedIO('conditional_if_1_if_1.in', '''#if 1
#if 1
PASS
#else
FAIL
#endif
#else
FAIL
#endif
''')
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "PASS\n")
def test_conditional_not_0(self):
f = NamedIO('conditional_not_0.in', '''#if !0
PASS
#else
FAIL
#endif
''')
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "PASS\n")
def test_conditional_not_1(self):
f = NamedIO('conditional_not_1.in', '''#if !1
#.........这里部分代码省略.........
示例4: JarMaker
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import do_include [as 别名]
class JarMaker(object):
'''JarMaker reads jar.mn files and process those into jar files or
flat directories, along with chrome.manifest files.
'''
ignore = re.compile('\s*(\#.*)?$')
jarline = re.compile('(?:(?P<jarfile>[\w\d.\-\_\\\/]+).jar\:)|(?:\s*(\#.*)?)\s*$')
relsrcline = re.compile('relativesrcdir\s+(?P<relativesrcdir>.+?):')
regline = re.compile('\%\s+(.*)$')
entryre = '(?P<optPreprocess>\*)?(?P<optOverwrite>\+?)\s+'
entryline = re.compile(entryre + '(?P<output>[\w\d.\-\_\\\/\+\@]+)\s*(\((?P<locale>\%?)(?P<source>[\w\d.\-\_\\\/\@]+)\))?\s*$')
def __init__(self, outputFormat = 'flat', useJarfileManifest = True,
useChromeManifest = False):
self.outputFormat = outputFormat
self.useJarfileManifest = useJarfileManifest
self.useChromeManifest = useChromeManifest
self.pp = Preprocessor()
self.topsourcedir = None
self.sourcedirs = []
self.localedirs = None
self.l10nbase = None
self.l10nmerge = None
self.relativesrcdir = None
self.rootManifestAppId = None
def getCommandLineParser(self):
'''Get a optparse.OptionParser for jarmaker.
This OptionParser has the options for jarmaker as well as
the options for the inner PreProcessor.
'''
# HACK, we need to unescape the string variables we get,
# the perl versions didn't grok strings right
p = self.pp.getCommandLineParser(unescapeDefines = True)
p.add_option('-f', type="choice", default="jar",
choices=('jar', 'flat', 'symlink'),
help="fileformat used for output", metavar="[jar, flat, symlink]")
p.add_option('-v', action="store_true", dest="verbose",
help="verbose output")
p.add_option('-q', action="store_false", dest="verbose",
help="verbose output")
p.add_option('-e', action="store_true",
help="create chrome.manifest instead of jarfile.manifest")
p.add_option('--both-manifests', action="store_true",
dest="bothManifests",
help="create chrome.manifest and jarfile.manifest")
p.add_option('-s', type="string", action="append", default=[],
help="source directory")
p.add_option('-t', type="string",
help="top source directory")
p.add_option('-c', '--l10n-src', type="string", action="append",
help="localization directory")
p.add_option('--l10n-base', type="string", action="store",
help="base directory to be used for localization (requires relativesrcdir)")
p.add_option('--locale-mergedir', type="string", action="store",
help="base directory to be used for l10n-merge (requires l10n-base and relativesrcdir)")
p.add_option('--relativesrcdir', type="string",
help="relativesrcdir to be used for localization")
p.add_option('-j', type="string",
help="jarfile directory")
p.add_option('--root-manifest-entry-appid', type="string",
help="add an app id specific root chrome manifest entry.")
return p
def processIncludes(self, includes):
'''Process given includes with the inner PreProcessor.
Only use this for #defines, the includes shouldn't generate
content.
'''
self.pp.out = StringIO()
for inc in includes:
self.pp.do_include(inc)
includesvalue = self.pp.out.getvalue()
if includesvalue:
logging.info("WARNING: Includes produce non-empty output")
self.pp.out = None
pass
def finalizeJar(self, jarPath, chromebasepath, register,
doZip=True):
'''Helper method to write out the chrome registration entries to
jarfile.manifest or chrome.manifest, or both.
The actual file processing is done in updateManifest.
'''
# rewrite the manifest, if entries given
if not register:
return
chromeManifest = os.path.join(os.path.dirname(jarPath),
'..', 'chrome.manifest')
if self.useJarfileManifest:
self.updateManifest(jarPath + '.manifest', chromebasepath % '',
register)
addEntriesToListFile(chromeManifest, ['manifest chrome/%s.manifest' % (os.path.basename(jarPath),)])
if self.useChromeManifest:
self.updateManifest(chromeManifest, chromebasepath % 'chrome/',
#.........这里部分代码省略.........
示例5: JarMaker
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import do_include [as 别名]
#.........这里部分代码省略.........
'--l10n-base',
type="string",
action="append",
default=[],
help="base directory to be used for localization (multiple)")
p.add_option('-j', type="string", help="jarfile directory")
# backwards compat, not needed
p.add_option(
'-a',
action="store_false",
default=True,
help=
"NOT SUPPORTED, turn auto-registration of chrome off (installed-chrome.txt)"
)
p.add_option('-d', type="string", help="UNUSED, chrome directory")
p.add_option('-o', help="cross compile for auto-registration, ignored")
p.add_option(
'-l',
action="store_true",
help="ignored (used to switch off locks)")
p.add_option('-x', action="store_true", help="force Unix")
p.add_option('-z', help="backwards compat, ignored")
p.add_option('-p', help="backwards compat, ignored")
return p
def processIncludes(self, includes):
'''Process given includes with the inner PreProcessor.
Only use this for #defines, the includes shouldn't generate
content.
'''
self.pp.out = StringIO()
for inc in includes:
self.pp.do_include(inc)
includesvalue = self.pp.out.getvalue()
if includesvalue:
logging.info("WARNING: Includes produce non-empty output")
self.pp.out = None
pass
def finalizeJar(self, jarPath, chromebasepath, register, doZip=True):
'''Helper method to write out the chrome registration entries to
jarfile.manifest or chrome.manifest, or both.
The actual file processing is done in updateManifest.
'''
# rewrite the manifest, if entries given
if not register:
return
if self.useJarfileManifest:
self.updateManifest(jarPath + '.manifest', chromebasepath % '',
register)
if self.useChromeManifest:
manifestPath = os.path.join(
os.path.dirname(jarPath), '..', 'chrome.manifest')
self.updateManifest(manifestPath, chromebasepath % 'chrome/',
register)
def updateManifest(self, manifestPath, chromebasepath, register):
'''updateManifest replaces the % in the chrome registration entries
with the given chrome base path, and updates the given manifest file.
'''
myregister = dict.fromkeys(
map(lambda s: s.replace('%', chromebasepath), register.iterkeys()))
manifestExists = os.path.isfile(manifestPath)
mode = (manifestExists and 'r+b') or 'wb'
示例6: JarMaker
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import do_include [as 别名]
class JarMaker(object):
'''JarMaker reads jar.mn files and process those into jar files or
flat directories, along with chrome.manifest files.
'''
ignore = re.compile('\s*(\#.*)?$')
jarline = re.compile('(?:(?P<jarfile>[\w\d.\-\_\\\/]+).jar\:)|(?:\s*(\#.*)?)\s*$')
relsrcline = re.compile('relativesrcdir\s+(?P<relativesrcdir>.+?):')
regline = re.compile('\%\s+(.*)$')
entryre = '(?P<optPreprocess>\*)?(?P<optOverwrite>\+?)\s+'
entryline = re.compile(entryre + '(?P<output>[\w\d.\-\_\\\/\+\@]+)\s*(\((?P<locale>\%?)(?P<source>[\w\d.\-\_\\\/\@]+)\))?\s*$')
def __init__(self, outputFormat = 'flat', useJarfileManifest = True,
useChromeManifest = False):
self.outputFormat = outputFormat
self.useJarfileManifest = useJarfileManifest
self.useChromeManifest = useChromeManifest
self.pp = Preprocessor()
self.topsourcedir = None
self.sourcedirs = []
self.localedirs = None
self.l10nbase = None
self.l10nmerge = None
self.relativesrcdir = None
self.rootManifestAppId = None
def getCommandLineParser(self):
'''Get a optparse.OptionParser for jarmaker.
This OptionParser has the options for jarmaker as well as
the options for the inner PreProcessor.
'''
# HACK, we need to unescape the string variables we get,
# the perl versions didn't grok strings right
p = self.pp.getCommandLineParser(unescapeDefines = True)
p.add_option('-f', type="choice", default="jar",
choices=('jar', 'flat', 'symlink'),
help="fileformat used for output", metavar="[jar, flat, symlink]")
p.add_option('-v', action="store_true", dest="verbose",
help="verbose output")
p.add_option('-q', action="store_false", dest="verbose",
help="verbose output")
p.add_option('-e', action="store_true",
help="create chrome.manifest instead of jarfile.manifest")
p.add_option('--both-manifests', action="store_true",
dest="bothManifests",
help="create chrome.manifest and jarfile.manifest")
p.add_option('-s', type="string", action="append", default=[],
help="source directory")
p.add_option('-t', type="string",
help="top source directory")
p.add_option('-c', '--l10n-src', type="string", action="append",
help="localization directory")
p.add_option('--l10n-base', type="string", action="store",
help="base directory to be used for localization (requires relativesrcdir)")
p.add_option('--locale-mergedir', type="string", action="store",
help="base directory to be used for l10n-merge (requires l10n-base and relativesrcdir)")
p.add_option('--relativesrcdir', type="string",
help="relativesrcdir to be used for localization")
p.add_option('-j', type="string",
help="jarfile directory")
p.add_option('--root-manifest-entry-appid', type="string",
help="add an app id specific root chrome manifest entry.")
return p
def processIncludes(self, includes):
'''Process given includes with the inner PreProcessor.
Only use this for #defines, the includes shouldn't generate
content.
'''
self.pp.out = StringIO()
for inc in includes:
self.pp.do_include(inc)
includesvalue = self.pp.out.getvalue()
if includesvalue:
logging.info("WARNING: Includes produce non-empty output")
self.pp.out = None
pass
def finalizeJar(self, jarPath, chromebasepath, register,
doZip=True):
'''Helper method to write out the chrome registration entries to
jarfile.manifest or chrome.manifest, or both.
The actual file processing is done in updateManifest.
'''
# rewrite the manifest, if entries given
if not register:
return
chromeManifest = os.path.join(os.path.dirname(jarPath),
'..', 'chrome.manifest')
if self.useJarfileManifest:
self.updateManifest(jarPath + '.manifest', chromebasepath.format(''),
register)
addEntriesToListFile(chromeManifest, ['manifest chrome/{0}.manifest'
.format(os.path.basename(jarPath))])
if self.useChromeManifest:
#.........这里部分代码省略.........
示例7: JarMaker
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import do_include [as 别名]
class JarMaker(object):
'''JarMaker reads jar.mn files and process those into jar files or
flat directories, along with chrome.manifest files.
'''
ignore = re.compile('\s*(\#.*)?$')
jarline = re.compile('(?:(?P<jarfile>[\w\d.\-\_\\\/]+).jar\:)|(?:\s*(\#.*)?)\s*$')
regline = re.compile('\%\s+(.*)$')
entryre = '(?P<optPreprocess>\*)?(?P<optOverwrite>\+?)\s+'
entryline = re.compile(entryre + '(?P<output>[\w\d.\-\_\\\/\+]+)\s*(\((?P<locale>\%?)(?P<source>[\w\d.\-\_\\\/]+)\))?\s*$')
def __init__(self, outputFormat = 'flat', useJarfileManifest = True,
useChromeManifest = False):
self.outputFormat = outputFormat
self.useJarfileManifest = useJarfileManifest
self.useChromeManifest = useChromeManifest
self.pp = Preprocessor()
def getCommandLineParser(self):
'''Get a optparse.OptionParser for jarmaker.
This OptionParser has the options for jarmaker as well as
the options for the inner PreProcessor.
'''
# HACK, we need to unescape the string variables we get,
# the perl versions didn't grok strings right
p = self.pp.getCommandLineParser(unescapeDefines = True)
p.add_option('-f', type="choice", default="jar",
choices=('jar', 'flat', 'symlink'),
help="fileformat used for output", metavar="[jar, flat, symlink]")
p.add_option('-v', action="store_true", dest="verbose",
help="verbose output")
p.add_option('-q', action="store_false", dest="verbose",
help="verbose output")
p.add_option('-e', action="store_true",
help="create chrome.manifest instead of jarfile.manifest")
p.add_option('--both-manifests', action="store_true",
dest="bothManifests",
help="create chrome.manifest and jarfile.manifest")
p.add_option('-s', type="string", action="append", default=[],
help="source directory")
p.add_option('-t', type="string",
help="top source directory")
p.add_option('-c', '--l10n-src', type="string", action="append",
help="localization directory")
p.add_option('--l10n-base', type="string", action="append", default=[],
help="base directory to be used for localization (multiple)")
p.add_option('-j', type="string",
help="jarfile directory")
# backwards compat, not needed
p.add_option('-a', action="store_false", default=True,
help="NOT SUPPORTED, turn auto-registration of chrome off (installed-chrome.txt)")
p.add_option('-d', type="string",
help="UNUSED, chrome directory")
p.add_option('-o', help="cross compile for auto-registration, ignored")
p.add_option('-l', action="store_true",
help="ignored (used to switch off locks)")
p.add_option('-x', action="store_true",
help="force Unix")
p.add_option('-z', help="backwards compat, ignored")
p.add_option('-p', help="backwards compat, ignored")
return p
def processIncludes(self, includes):
'''Process given includes with the inner PreProcessor.
Only use this for #defines, the includes shouldn't generate
content.
'''
self.pp.out = StringIO()
for inc in includes:
self.pp.do_include(inc)
includesvalue = self.pp.out.getvalue()
if includesvalue:
logging.info("WARNING: Includes produce non-empty output")
self.pp.out = None
pass
def finalizeJar(self, jarPath, chromebasepath, register,
doZip=True):
'''Helper method to write out the chrome registration entries to
jarfile.manifest or chrome.manifest, or both.
The actual file processing is done in updateManifest.
'''
# rewrite the manifest, if entries given
if not register:
return
chromeManifest = os.path.join(os.path.dirname(jarPath),
'..', 'chrome.manifest')
if self.useJarfileManifest:
self.updateManifest(jarPath + '.manifest', chromebasepath % '',
register)
addEntriesToListFile(chromeManifest, ['manifest chrome/%s.manifest' % (os.path.basename(jarPath),)])
if self.useChromeManifest:
self.updateManifest(chromeManifest, chromebasepath % 'chrome/',
register)
#.........这里部分代码省略.........