本文整理汇总了Python中string.joinfields函数的典型用法代码示例。如果您正苦于以下问题:Python joinfields函数的具体用法?Python joinfields怎么用?Python joinfields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了joinfields函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dotfork
def dotfork(i,b, machineClass, xnrefs):
global TRANSITION_ARCS
global ARC_TRANSITIONS
global TRANSITION_NODES
if len(xnrefs) == 1:
# no need for fork if only one xn ref
return ("", xnrefs[0])
elif len(xnrefs) == 0:
nodeShape = 'shape=box, width=".05", height=".05", fixedsize=true'
else:
nodeShape = 'style=filled, color=black, shape=circle, width=".05", height=".05", fixedsize=true'
forkName = "FORK.%s" % string.joinfields(map(str, [ i ] + b), "_")
forkNodeName = string.joinfields(machineClass + [ forkName ], ".")
# fork node declaration
rv = '"%s" [label="", %s];\n' % (forkNodeName, nodeShape)
forkRef = [ [], forkNodeName, "", "" ]
key = string.joinfields(machineClass + [ str(i) ], ".")
try:
arcs = TRANSITION_ARCS[key]
nodes = TRANSITION_NODES[key]
except KeyError:
arcs = {}
nodes = {}
TRANSITION_ARCS[key] = arcs
TRANSITION_NODES[key] = nodes
nodes[forkNodeName] = None
for ref in xnrefs:
arc = "%s->%s" % (forkNodeName, ref[1])
ARC_TRANSITIONS[arc] = key
arcs[arc] = None
nodes[ref[1]] = None
rv = rv + '"%s" -> "%s" [headlabel="%s", lhead="%s", label=""];\n' % (forkNodeName, ref[1], ref[2], ref[3])
return (rv, forkRef)
示例2: excepthook
def excepthook(type, exc_msg, tb):
cfg = self.recipe.cfg
sys.excepthook = sys.__excepthook__
if cfg.debugRecipeExceptions:
lines = traceback.format_exception(type, exc_msg, tb)
print string.joinfields(lines, "")
if self.linenum is not None:
prefix = "%s:%s:" % (self.file, self.linenum)
prefix_len = len(prefix)
if str(exc_msg)[:prefix_len] != prefix:
exc_message = "%s:%s: %s: %s" % (self.file, self.linenum,
type.__name__, exc_msg)
print exc_message
if self.recipe.buildinfo:
try:
buildinfo = self.recipe.buildinfo
buildinfo.error = exc_message
buildinfo.file = self.file
buildinfo.lastline = self.linenum
buildinfo.stop()
except:
log.warning("could not write out to buildinfo")
if cfg.debugRecipeExceptions and self.recipe.isatty():
debugger.post_mortem(tb, type, exc_msg)
else:
sys.exit(1)
示例3: addTable
def addTable(items, cols=COLS):
divrecs = []
tabrecs = []
names = {'tab': TAB}
tabrecs.append('<div id="table0" class="gtable" >')
tabrecs.append('%(tab)s<table>' % names)
names['tab'] = 2 * TAB
i = 0
while i < len(items):
tabrecs.append('%(tab)s<tr align=left>' % names)
names['tab'] = 3 * TAB
for col in range(cols):
if i >= len(items): break
ahref, adiv = items[i]
names['item'] = ahref
tabrecs.append('%(tab)s<td>%(item)s%(tab)s</td>' % names)
names['item'] = adiv
divrecs.append('%(item)s' % names)
i += 1
names['tab'] = 2 * TAB
tabrecs.append('%(tab)s</tr>' % names)
names['tab'] = TAB
tabrecs.append('%(tab)s</table>\n' % names)
tabrecs.append('</div>\n')
return (joinfields(tabrecs,'\n'), joinfields(divrecs,'\n'))
示例4: docstring
def docstring(self):
import string
input = []
output = []
for arg in self.argumentList:
if arg.flags == ErrorMode or arg.flags == SelfMode:
continue
if arg.type == None:
str = 'void'
else:
if hasattr(arg.type, 'typeName'):
typeName = arg.type.typeName
if typeName is None: # Suppressed type
continue
else:
typeName = "?"
print "Nameless type", arg.type
str = typeName + ' ' + arg.name
if arg.mode in (InMode, InOutMode):
input.append(str)
if arg.mode in (InOutMode, OutMode):
output.append(str)
if not input:
instr = "()"
else:
instr = "(%s)" % string.joinfields(input, ", ")
if not output or output == ["void"]:
outstr = "None"
else:
outstr = "(%s)" % string.joinfields(output, ", ")
return instr + " -> " + outstr
示例5: docecma
def docecma():
rv = "var transitionArcs = {};\n"
for xn in dotmachine.TRANSITION_ARCS.keys():
rv = rv + "transitionArcs[\"%s\"] = [ " % xn
rv = rv + string.joinfields(map(lambda x: "\"%s\"" % x, dotmachine.TRANSITION_ARCS[xn].keys()), ", ")
rv = rv + " ];\n"
rv = rv + "\n"
rv = rv + "var arcTransitions = {};\n"
for arc in dotmachine.ARC_TRANSITIONS.keys():
rv = rv + "arcTransitions[\"%s\"] = \"%s\";\n" % (arc, dotmachine.ARC_TRANSITIONS[arc])
rv = rv + "\n"
rv = rv + "var transitionNodes = {};\n"
for xn in dotmachine.TRANSITION_NODES.keys():
rv = rv + "transitionNodes[\"%s\"] = [ " % xn
rv = rv + string.joinfields(map(lambda x: "\"%s\"" % x, dotmachine.TRANSITION_NODES[xn].keys()), ", ")
rv = rv + " ];\n"
rv = rv + "\n"
rv = rv + "var nodeStates = {};\n"
for node in dotmachine.NODE_STATES.keys():
rv = rv + "nodeStates[\"%s\"] = \"%s\";\n" % ( node, dotmachine.NODE_STATES[node] )
rv = rv + "\n"
rv = rv + "var transitionComments = {};\n"
for xn in dotmachine.TRANSITION_COMMENTS.keys():
rv = rv + "transitionComments[\"%s\"] = \"%s\";\n" % ( xn, string.replace(dotmachine.TRANSITION_COMMENTS[xn], '"', r'\"' ) )
rv = rv + "\n"
rv = rv + "var stateComments = {};\n"
for state in dotmachine.STATE_COMMENTS.keys():
rv = rv + "stateComments[\"%s\"] = \"%s\";\n" % ( state, string.replace(dotmachine.STATE_COMMENTS[state], '"', r'\"' ) )
rv = rv + "\n"
rv = rv + "var machineComment = \"%s\";\n" % string.replace(dotmachine.MACHINE_COMMENT, '"', r'\"')
rv = rv + "\n"
rv = rv + "var externalStates = [ "
rv = rv + string.joinfields(map(lambda x: "\"%s\"" % x, dotmachine.EXTERNAL_STATES), ", ")
rv = rv + " ];\n"
return rv
示例6: create_test_tab
def create_test_tab(num_of_jobs, uid):
# Will contain parsed auto-generated crontab entries
cron_strings = {}
job_num = 1
while job_num <= num_of_jobs:
cron_strings.setdefault(job_num, [])
create_test_intervals(cron_strings[job_num])
cron_strings[job_num].append(create_test_commands(job_num,
cron_strings[job_num]))
job_num += 1
with open(TAB_FILE,'w') as tab:
for line in cron_strings.iterkeys():
rand = random.randrange(100)
# Approximately 30% chance that we will include a comment
if(rand > 85):
tab.write('#')
if(rand >= 70 and rand < 85):
tab.write('# ')
# Approximately 15% chance that we will include a blank line
if(rand >= 50 and rand < 70):
tab.write('\n')
for item in cron_strings[line]:
tab.write(item)
# Will contain assembled job-interval strings
test_jobs = []
with open(TAB_FILE, 'r') as tab:
for job in tab:
first_char = job[0]
if first_char != '\n':
tmp = job.strip().split(' ')
interval = string.joinfields(tmp[:5], ' ')
cmd = string.joinfields(tmp[5:], ' ')
test_jobs.append(api.Job(interval, cmd, uid, datetime.now()))
return test_jobs
示例7: dotjoin
def dotjoin(i, machineClass, xnrefs):
global TRANSITION_ARCS
global ARC_TRANSITIONS
global TRANSITION_NODES
if len(xnrefs) == 1:
# no need for join if only one xn ref
return ("", xnrefs[0])
elif len(xnrefs) == 0:
nodeShape = 'shape=box, width=".05", height=".05", fixedsize=true'
else:
nodeShape = 'style=filled, color=black, shape=circle, width=".05", height=".05", fixedsize=true'
joinName = "JOIN.%s" % i
joinNodeName = string.joinfields(machineClass + [ joinName ], ".")
# join node declaration
rv = '"%s" [label="", %s];\n' % (joinNodeName, nodeShape)
joinRef = [ [], joinNodeName, "", "" ]
key = string.joinfields(machineClass + [ str(i) ], ".")
try:
nodes = TRANSITION_NODES[key]
arcs = TRANSITION_ARCS[key]
except KeyError:
arcs = {}
nodes = {}
TRANSITION_ARCS[key] = arcs
TRANSITION_NODES[key] = nodes
nodes[joinNodeName] = None
for ref in xnrefs:
arc = "%s->%s" % (ref[1], joinNodeName)
ARC_TRANSITIONS[arc] = key
arcs[arc] = None
nodes[ref[1]] = None
rv = rv + '"%s" -> "%s" [taillabel="%s", ltail="%s", label=""];\n' % (ref[1], joinNodeName, ref[2], ref[3])
return (rv, joinRef)
示例8: translate
def translate(compilationUnit, machine, targetDirectory, opts):
header = """//
// This file was generated by ech2java. Do not modify.
//
"""
# package declaration
package = ""
if len(getPackage(compilationUnit)) > 0:
packageString = "package " + string.joinfields(getPackage(compilationUnit), ".") + ";\n"
package = echartsLineReference(getPackageLineColumn(compilationUnit), packageString) + "\n"
# imports
imports = "import org.echarts.*;\n"
imports = imports + "import org.echarts.monitor.*;\n"
for imported in getImports(compilationUnit):
importedPackage = getImportPackage(imported)
importModifiers = getImportModifiers(imported)
importString = "import %s %s;\n" % (string.joinfields(importModifiers, " "), string.joinfields(importedPackage, ".") )
imports = imports + echartsLineReference(getImportLineColumn(imported), importString)
imports = imports + "\n"
# the machine itself
machine = javamachine(compilationUnit)
# the translated program
rv = header + package + imports + machine
# return the program
return rv
示例9: javaconstructor
def javaconstructor(constructor, machineName, machineClass):
# constructor header
accessString = string.joinfields(getConstructorAccessModifiers(constructor), " ")
rv = "%s %s(" % (accessString, machineClass)
userParamStrings = []
for param in getConstructorParameters(constructor):
userParamStrings = userParamStrings + [ javatype(param[0]) + " " + param[1] ]
paramStrings = userParamStrings + [ "final Machine parentMachine", "final int machineIndex",
"final MachineCode machineCode" ]
rv = rv + string.joinfields(paramStrings, ", ") + ") throws Exception {\n"
rv = rv + "super(%s_states, %s_messageTransitions, %s_messagelessTransitions, %s.class.getName(), parentMachine, machineIndex, machineCode);\n" % \
(machineName, machineName, machineName, machineClass)
# constructor body
rv = rv + javaaction(getConstructorActionBlock(constructor)) + "}\n"
# constructor called when creating machine as top-level machine
rv = rv + getConstructorComment(constructor) + "\n"
rv = rv + "%s %s(" % (accessString, machineClass)
rv = rv + string.joinfields(userParamStrings, ", ") + ") throws Exception {\n"
rv = rv + "this("
userParamStrings = []
for param in getConstructorParameters(constructor):
userParamStrings = userParamStrings + [ param[1] ]
paramStrings = userParamStrings + [ "null", "-1", "null" ]
rv = rv + string.joinfields(paramStrings, ", ") + ");\n"
return rv + "}\n"
示例10: javatop
def javatop(machine, machineName):
machineClass = machineName
if getExtendsClause(machine) == None:
extends = "TransitionMachine"
else:
extends = string.joinfields(getExtendsClause(machine), ".")
if getImplementsClause(machine) == None:
implements = ""
else:
implementsClasses = []
for interface in getImplementsClause(machine):
implementsClasses = implementsClasses + [ string.joinfields(interface, ".") ]
implements = " implements %s" % string.joinfields(implementsClasses, ", ")
rv = getMachineComment(machine) + "\n"
rv = rv + "public class %s extends %s%s {\n" % (machineClass, extends, implements)
# Define static members and methods for top-level machine and its
# submachines
rv = rv + javastatic(machine, machineName, machineClass)
rv = rv + "// Declarations for %s\n" % machineClass
# Define top-level machine constructors
rv = rv + javaconstructors(machine, machineName, machineClass)
# Define instance members, methods and subclasses for top-level
# machine and its submachines
rv = rv + javabody(machine, machineName, machineClass)
return rv
示例11: _ctag
def _ctag(str, hrefs=()):
"""Quote, tag, and escape the text.
This is a modified version of the 'ctag' function appearing in
StructuredText.py. The differences include,
* it uses _split, so that it avoids escaping text in quotes or
in math-mode.
* it processes hrefs.
* it escapes LaTeX special characters.
* it doesn't try to find duplicate list items - that got moved
into LaTeX.
"""
if str is None: str = ''
str = ' %s' % str # prepend a space
str = _split(str)
for i in xrange(len(str)):
if not i%2:
str[i]=regsub.gsub(quotable_re, '\\\\[email protected]\\g<0>@', str[i])
str[i]=regsub.gsub(slashable_re, '\\\\\\g<0>', str[i])
str[i]=regsub.gsub(ST.strong,' {\\\\bfseries \\1}\\2', str[i])
str[i]=regsub.gsub(ST.em,' {\\\\itshape \\1}\\2',str[i])
for ref, link in hrefs:
tag = '{\slshape %s}\\footnote{%s}' % (ref[1:-1], link)
str[i] = string.joinfields(string.split(str[i], ref), tag)
return string.joinfields(str)
示例12: rebuild_lines
def rebuild_lines(self):
"""Rebuild a list of lines representing the SubBlock data from the stored values."""
# If there's no data in this SubBlock, then we don't need to return any lines!
# if len(self.data) == 0:
# return []
# Otherwise, let's rebuild the lines
self.lines = []
# Append the SubBlock title line
self.lines.append('[ %s ]\n'%self.name)
# Append the header comment line
if len(self.headerFields) >= self.numberHeaderFields:
self.lines.append(self.headerFormat%tuple(self.headerFields[0:self.numberHeaderFields]) \
+ string.joinfields(self.headerFields[self.numberHeaderFields:],' ')+'\n')
# Append the data lines
sorted_keys = self.data.keys()
sorted_keys.sort()
for key in sorted_keys:
if len(self.data[key]) >= self.numberDataFields:
self.lines.append(self.dataFormat%tuple(self.data[key][0:self.numberDataFields]) \
+ string.joinfields(self.data[key][self.numberDataFields:],' ') +'\n')
# A blank line always
self.lines.append('\n')
return self.lines
示例13: xml_to_tree
def xml_to_tree(filename, class_table = None):
p = TreeBuildingParser(class_table = class_table)
if isinstance(filename, url_directory.BasePath):
try:
lines = filename.Readlines()
except IOError:
raise NoXMLFile, filename.PathString()
s = string.joinfields(lines, "")
path = filename
elif filename == "-":
s_list = []
s = sys.stdin.read()
while s:
s_list.append(s)
s = sys.stdin.read()
s = string.joinfields(s_list, "")
path = None
else:
try:
fp = open(filename, "r")
except IOError:
raise NoXMLFile, filename
s = fp.read()
fp.close()
path = url_directory.FilePath(filename)
p.feed(s)
p.close()
p.cur_tag[0].path = path
return p.cur_tag[0]
示例14: main
def main():
uid = os.getuid()
if len(sys.argv) < 3:
jobs_old = api.get_jobs_for_user(uid)
with tempfile.NamedTemporaryFile('w', delete=False) as temp:
for job in jobs_old:
temp.write("%s %s\n" % (job.interval, job.command))
tb_file = temp.name
editor = os.getenv('EDITOR')
if editor is not None:
os.system("%s %s" % (editor, tb_file))
else:
subprocess.call("vim %s" % tb_file, shell=True)
elif sys.argv[1] == '-u':
tb_file = sys.argv[2]
jobs_new = []
with open(tb_file, 'r') as tab:
for job in tab:
tmp = job.strip().split(' ')
interval = string.joinfields(tmp[:5], ' ')
cmd = string.joinfields(tmp[5:], ' ')
jobs_new.append(api.Job(interval, cmd, uid, datetime.now()))
if len(sys.argv) < 3:
os.unlink(tb_file)
api.set_jobs(jobs_new, uid)
示例15: custom_default_zpt_report
def custom_default_zpt_report(id, result, action='', no_table=0,
goofy=re.compile('\W').search
):
columns=result._searchable_result_columns()
__traceback_info__=columns
heading=('<tr>\n%s </tr>' %
string.joinfields(
map(lambda c:
' <th>%s</th>\n' % nicify(c['name']),
columns),
''
)
)
if no_table: tr, _tr, td, _td, delim = '<p>', '</p>', '', '', ',\n'
else: tr, _tr, td, _td, delim = '<tr>', '</tr>', '<td>', '</td>', '\n'
row=[]
for c in columns:
n=c['name']
# ugh! what the hell is goofy?
# if goofy(n) is not None:
# n='expr="_[\'%s]"' % (`'"'+n`[2:])
row.append(' %s<span tal:replace="result/%s">%s goes here</span>%s'
% (td,n,n,_td))
row=(' %s\n%s\n %s' % (tr,string.joinfields(row,delim), _tr))
return custom_default_zpt_report_src(
id=id, heading=heading, row=row, action=action, no_table=no_table)