mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
4
python/pystache/pystache/commands/__init__.py
Normal file
4
python/pystache/pystache/commands/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"""
|
||||
TODO: add a docstring.
|
||||
|
||||
"""
|
||||
95
python/pystache/pystache/commands/render.py
Normal file
95
python/pystache/pystache/commands/render.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
# coding: utf-8
|
||||
|
||||
"""
|
||||
This module provides command-line access to pystache.
|
||||
|
||||
Run this script using the -h option for command-line help.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
try:
|
||||
import json
|
||||
except:
|
||||
# The json module is new in Python 2.6, whereas simplejson is
|
||||
# compatible with earlier versions.
|
||||
try:
|
||||
import simplejson as json
|
||||
except ImportError:
|
||||
# Raise an error with a type different from ImportError as a hack around
|
||||
# this issue:
|
||||
# http://bugs.python.org/issue7559
|
||||
from sys import exc_info
|
||||
ex_type, ex_value, tb = exc_info()
|
||||
new_ex = Exception("%s: %s" % (ex_type.__name__, ex_value))
|
||||
raise new_ex.__class__, new_ex, tb
|
||||
|
||||
# The optparse module is deprecated in Python 2.7 in favor of argparse.
|
||||
# However, argparse is not available in Python 2.6 and earlier.
|
||||
from optparse import OptionParser
|
||||
import sys
|
||||
|
||||
# We use absolute imports here to allow use of this script from its
|
||||
# location in source control (e.g. for development purposes).
|
||||
# Otherwise, the following error occurs:
|
||||
#
|
||||
# ValueError: Attempted relative import in non-package
|
||||
#
|
||||
from pystache.common import TemplateNotFoundError
|
||||
from pystache.renderer import Renderer
|
||||
|
||||
|
||||
USAGE = """\
|
||||
%prog [-h] template context
|
||||
|
||||
Render a mustache template with the given context.
|
||||
|
||||
positional arguments:
|
||||
template A filename or template string.
|
||||
context A filename or JSON string."""
|
||||
|
||||
|
||||
def parse_args(sys_argv, usage):
|
||||
"""
|
||||
Return an OptionParser for the script.
|
||||
|
||||
"""
|
||||
args = sys_argv[1:]
|
||||
|
||||
parser = OptionParser(usage=usage)
|
||||
options, args = parser.parse_args(args)
|
||||
|
||||
template, context = args
|
||||
|
||||
return template, context
|
||||
|
||||
|
||||
# TODO: verify whether the setup() method's entry_points argument
|
||||
# supports passing arguments to main:
|
||||
#
|
||||
# http://packages.python.org/distribute/setuptools.html#automatic-script-creation
|
||||
#
|
||||
def main(sys_argv=sys.argv):
|
||||
template, context = parse_args(sys_argv, USAGE)
|
||||
|
||||
if template.endswith('.mustache'):
|
||||
template = template[:-9]
|
||||
|
||||
renderer = Renderer()
|
||||
|
||||
try:
|
||||
template = renderer.load_template(template)
|
||||
except TemplateNotFoundError:
|
||||
pass
|
||||
|
||||
try:
|
||||
context = json.load(open(context))
|
||||
except IOError:
|
||||
context = json.loads(context)
|
||||
|
||||
rendered = renderer.render(template, context)
|
||||
print rendered
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
18
python/pystache/pystache/commands/test.py
Normal file
18
python/pystache/pystache/commands/test.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# coding: utf-8
|
||||
|
||||
"""
|
||||
This module provides a command to test pystache (unit tests, doctests, etc).
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from pystache.tests.main import main as run_tests
|
||||
|
||||
|
||||
def main(sys_argv=sys.argv):
|
||||
run_tests(sys_argv=sys_argv)
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue