本文整理汇总了Python中misc.option函数的典型用法代码示例。如果您正苦于以下问题:Python option函数的具体用法?Python option怎么用?Python option使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了option函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pandoc_author
def pandoc_author(authors_and_institutions, auth2index,
inst2index, index2inst, auth2email):
# List authors on multiple lines
authors = []
for author, i, e in authors_and_institutions:
author = '**%s**' % author # set in boldface
if i is None:
authors.append(author)
else:
authors.append(author + ' at ' + ' and '.join(i))
plain_text = '### Author'
if len(authors) > 1:
plain_text += 's'
plain_text += '\n\n' + '\n\n'.join(authors) + '\n\n'
if option('strapdown'):
return plain_text
elif option('strict_markdown_output'):
return plain_text
elif option('multimarkdown_output'):
return 'Author: ' + ', '.join(authors) + '\n'
else:
# pandoc-extended markdown syntax
return '% ' + '; '.join(authors) + '\n'
示例2: __init__
def __init__(self):
self.tracks = os.listdir(option("music-dir"))
if option("music-shuffle"):
random.shuffle(self.tracks)
self.track = 0
pygame.mixer.music.set_endevent(Music.MUSIC_FINISHED)
示例3: pandoc_date
def pandoc_date(m):
date = m.group("subst")
if option("strapdown"):
return "#### Date: " + date
elif option("strict_markdown_output"):
return "#### Date: " + date
elif option("multimarkdown_output"):
return "Date: " + date + "\n"
else:
# pandoc-extended markdown syntax
return "% " + date + "\n"
示例4: pandoc_title
def pandoc_title(m):
title = m.group('subst')
if option('strapdown'):
# title is in <title> tag in INTRO for the header of the HTML output
return ''
elif option('strict_markdown_output'):
return '# ' + title
elif option('multimarkdown_output'):
return 'Title: ' + title
else:
return '% ' + title
示例5: pandoc_title
def pandoc_title(m):
title = m.group("subst")
if option("strapdown"):
# title is in <title> tag in INTRO for the header of the HTML output
return ""
elif option("strict_markdown_output"):
return "# " + title
elif option("multimarkdown_output"):
return "Title: " + title
else:
# pandoc-extended markdown syntax
return "% " + title
示例6: pandoc_linebreak
def pandoc_linebreak(m):
# orig: r'\g<text>\\n',
text = m.group("text")
if option("github_md"):
return text + "<br />"
else:
return text + r"\n"
示例7: rst_abstract
def rst_abstract(m):
# r'\n*\g<type>.* \g<text>\n\g<rest>'
name = m.group('type').strip()
text = m.group('text').strip()
rest = m.group('rest').strip()
if option('rst_uio'):
s = """
.. uio-introduction::
%s
.. contents::
.. section-numbering::
%s
""" % (indent_lines(text, 'rst'), rest)
return s
else:
if name.lower() == 'preface':
# Drop heading (short abstract for books)
return '\n%(text)s\n\n%(rest)s' % vars()
else:
return '\n*%(name)s.* %(text)s\n\n%(rest)s' % vars()
示例8: rst_author
def rst_author(authors_and_institutions, auth2index,
inst2index, index2inst, auth2email):
if option('rst_uio'):
if authors_and_institutions:
# Use first author and email
responsible = authors_and_institutions[0][0]
email = authors_and_institutions[0][2]
text = """
.. uio-meta::
:responsible-name: %s
""" % responsible
if email:
text += ' :responsible-email: %s\n\n' % email
else:
errwarn('*** error: with --rst_uio there must be an AUTHOR:')
errwarn(' field with (at least) one author w/email who will be')
errwarn(' listed as the resposible under uio-meta::')
_abort()
else:
authors = []
for author, i, email in authors_and_institutions:
if email:
email = email.replace('@', ' at ')
authors.append(author + ' (%s)' % email)
else:
authors.append(author)
text = ':Authors: ' + ', '.join(authors) # (text is already r-stripped in typeset_authors)
# we skip institutions in rst
return text
示例9: sphinx_movie
def sphinx_movie(m):
filename = m.group("filename")
special_movie = (
"*" in filename
or "->" in filename
or "youtu.be" in filename
or "youtube.com" in filename
or "vimeo.com" in filename
)
if option("runestone") and not special_movie:
# Use RunestoneInteractive video environment
global video_counter
video_counter += 1
text = """
.. video:: video_%d
:controls:
%s
""" % (
video_counter,
filename,
)
return text
else:
# Use plain html code
return rst_movie(m)
示例10: xml_movie
def xml_movie(m):
filename = m.group('filename').srip()
opts = m.group('options').strip()
caption = m.group('caption').strip()
if opts:
opts = [s.split('=') for s in opts.split()]
opts = ['%s="%s"' % (key, value) for key, value in opts]
opts = ' ' + ' '.join(opts)
else:
opts = ''
autoplay = option('html_video_autoplay=', 'False')
if autoplay in ('on', 'off', 'True', 'true'):
autoplay = True
else:
autoplay = False
if opts:
opts.append('autoplay="%s"' % str(autoplay))
text = '<figure filename="%s%s>' % (filename, opts)
if caption:
text += '\n<caption>\n%s\n</caption>' % caption
text += '\n</figure>\n'
return text
示例11: rst_abstract
def rst_abstract(m):
# r'\n*\g<type>.* \g<text>\n\g<rest>'
name = m.group("type").strip()
text = m.group("text").strip()
rest = m.group("rest").strip()
if option("rst_uio"):
s = """
.. uio-introduction::
%s
.. contents::
.. section-numbering::
%s
""" % (
indent_lines(text, "rst"),
rest,
)
return s
else:
return "\n*%(name)s.* %(text)s\n\n%(rest)s" % vars()
示例12: rst_author
def rst_author(authors_and_institutions, auth2index, inst2index, index2inst, auth2email):
if option("rst_uio"):
if authors_and_institutions:
# Use first author and email
responsible = authors_and_institutions[0][0]
email = authors_and_institutions[0][2]
text = (
"""
.. uio-meta::
:responsible-name: %s
"""
% responsible
)
if email:
text += " :responsible-email: %s\n\n" % email
else:
print "*** error: with --rst_uio there must be an AUTHOR:"
print " field with (at least) one author w/email who will be"
print " listed as the resposible under uio-meta::"
_abort()
else:
authors = []
for author, i, email in authors_and_institutions:
if email:
email = email.replace("@", " at ")
authors.append(author + " (%s)" % email)
else:
authors.append(author)
text = ":Authors: " + ", ".join(authors) # (text is already r-stripped in typeset_authors)
# we skip institutions in rst
return text
示例13: plain_quiz
def plain_quiz(quiz):
# Simple typesetting of a quiz
import string
question_prefix = quiz.get("question prefix", option("quiz_question_prefix=", "Question:"))
common_choice_prefix = option("quiz_choice_prefix=", "Choice")
quiz_expl = option("quiz_explanations=", "on")
text = "\n\n"
if "new page" in quiz:
text += "======= %s =======\n\n" % (quiz["new page"])
# Don't write Question: ... if inside an exercise section
if quiz.get("embedding", "None") in ["exercise"]:
pass
else:
text += "\n"
if question_prefix:
text += "%s " % (question_prefix)
text += quiz["question"] + "\n\n"
# List choices as paragraphs
for i, choice in enumerate(quiz["choices"]):
# choice_no = i+1
choice_no = string.ascii_uppercase[i]
answer = choice[0].capitalize() + "!"
choice_prefix = common_choice_prefix
if "choice prefix" in quiz:
if isinstance(quiz["choice prefix"][i], basestring):
choice_prefix = quiz["choice prefix"][i]
if choice_prefix == "" or choice_prefix[-1] in [".", ":", "?"]:
pass # don't add choice number/letter
else:
choice_prefix += " %s:" % choice_no
# Let choice start with a newline if pure code starts the choice
# (test for different code block types so this function can work
# for other formats too...)
choice = choice[1].lstrip()
code_starters = "Code::", "~~~", "```", "{{{"
for code_starter in code_starters:
if choice.startswith(code_starter):
choice = "\n" + choice
# Cannot treat explanations
text += "%s %s\n\n" % (choice_prefix, choice)
return text
示例14: plain_quiz
def plain_quiz(quiz):
# Simple typesetting of a quiz
import string
question_prefix = quiz.get('question prefix',
option('quiz_question_prefix=', 'Question:'))
common_choice_prefix = option('quiz_choice_prefix=', 'Choice')
quiz_expl = option('quiz_explanations=', 'on')
text = '\n\n'
if 'new page' in quiz:
text += '======= %s =======\n\n' % (quiz['new page'])
# Don't write Question: ... if inside an exercise section
if quiz.get('embedding', 'None') in ['exercise',]:
pass
else:
text += '\n'
if question_prefix:
text += '%s ' % (question_prefix)
text += quiz['question'] + '\n\n'
# List choices as paragraphs
for i, choice in enumerate(quiz['choices']):
#choice_no = i+1
choice_no = string.ascii_uppercase[i]
answer = choice[0].capitalize() + '!'
choice_prefix = common_choice_prefix
if 'choice prefix' in quiz:
if isinstance(quiz['choice prefix'][i], basestring):
choice_prefix = quiz['choice prefix'][i]
if choice_prefix == '' or choice_prefix[-1] in ['.', ':', '?']:
pass # don't add choice number/letter
else:
choice_prefix += ' %s:' % choice_no
# Let choice start with a newline if pure code starts the choice
# (test for different code block types so this function can work
# for other formats too...)
choice = choice[1].lstrip()
code_starters = 'Code::', '~~~', '```', '{{{'
for code_starter in code_starters:
if choice.startswith(code_starter):
choice = '\n' + choice
# Cannot treat explanations
text += '%s %s\n\n' % (choice_prefix, choice)
return text
示例15: sphinx_ref_and_label
def sphinx_ref_and_label(section_label2title, format, filestr):
# Special fix early in the process:
# Deal with !split - by default we place splits before
# the all the topmost sections
# (This must be done before labels are put above section
# headings)
if '!split' in filestr and not option('sphinx_keep_splits'):
print '*** warning: new !split inserted (override all existing !split)'
# Note: the title is at this stage translated to a chapter heading!
# This title/heading must be removed for the algorithm below to work
# (remove it, then insert afterwards)
pattern = r'^.. Document title:\n\n={3,9}.+?={3,9}'
m = re.search(pattern, filestr, flags=re.MULTILINE)
title_replacement = '<<<<<<<DOCUMENT TITLE>>>>>>>>>>>>' # "unlikely" str
if m:
title = m.group()
filestr = filestr.replace(title, title_replacement)
else:
title = ''
topmost_section = 0
for i in [9, 7, 5]:
if re.search(r'^%s' % ('='*i), filestr, flags=re.MULTILINE):
topmost_section = i
print ' before every %s heading %s' % \
('='*topmost_section, '='*topmost_section)
print ' because this strategy gives a well-functioning'
print ' table of contents in Sphinx'
print ' (use --sphinx_keep_splits to enforce your own !split commands)'
break
if topmost_section:
# First remove all !split
filestr = re.sub(r'^!split *\n', '', filestr, flags=re.MULTILINE)
# Insert new splits before all topmost sections
pattern = r'^%s (.+?) %s' % \
('='*topmost_section, '='*topmost_section)
lines = filestr.splitlines()
for i in range(len(lines)):
if re.search(pattern, lines[i]):
lines[i] = '!split\n' + lines[i]
filestr = '\n'.join(lines)
filestr = filestr.replace(title_replacement, title)
filestr = ref_and_label_commoncode(section_label2title, format, filestr)
# replace all references to sections:
for label in section_label2title:
filestr = filestr.replace('ref{%s}' % label, ':ref:`%s`' % label)
# Not of interest after sphinx got equation references:
#from common import ref2equations
#filestr = ref2equations(filestr)
# Replace remaining ref{x} as :ref:`x`
filestr = re.sub(r'ref\{(.+?)\}', ':ref:`\g<1>`', filestr)
return filestr