Commits

Atsushi Odagiri committed 0d61dcd

run ``create`` command

Comments (0)

Files changed (5)

paste/script/command.py

 from paste.script import pluginlib
 from paste.script.compat import ConfigParser
 import getpass
-from paste.script.compat import print_
+from paste.script.compat import print_, input_
 try:
     import subprocess
 except ImportError:
         prompt += ': '
         while 1:
             if should_echo:
-                prompt_method = raw_input
+                prompt_method = input_
             else:
                 prompt_method = getpass.getpass
             response = prompt_method(prompt).strip()

paste/script/compat.py

     o = " ".join(out)
     sys.stdout.write(o)
     sys.stdout.write("\n")
+
 PY3 = sys.version_info[0] == 3
 
 if PY3:
     import urllib.parse as urlparse
     iteritems = lambda d: d.items()
 
+    input_ = input
+
     def reraise(t, e, tb):
         exec('raise e from tb', dict(e=e, tb=tb))
 else:
     import urlparse
     iteritems = lambda d: d.iteritems()
 
+    input_ = raw_input
+
     def reraise(t, e, tb):
         exec('raise t, e, tb', dict(t=t, e=e, tb=tb))
 
     if isinstance(s, binary_type):
         return s.decode(encoding, errors)
     return s # pragma: no cover
+
+def bytes_(s, encoding='latin-1', errors='strict'):
+    """ If ``s`` is an instance of ``text_type``, return
+    ``s.encode(encoding, errors)``, otherwise return ``s``"""
+    if isinstance(s, text_type): # pragma: no cover
+        return s.encode(encoding, errors)
+    return s

paste/script/copydir.py

 import cgi
 import urllib
 import re
-from paste.script.compat import print_
+from paste.script.compat import print_, text_, bytes_, input_
 
 Cheetah = None
 try:
             print_('%sCopying %s to %s' % (pad, os.path.basename(full), dest_full))
         if not simulate:
             f = open(dest_full, 'wb')
-            f.write(content)
+            f.write(bytes_(content))
             f.close()
         if svn_add and not already_exists:
             if not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(dest_full)), '.svn')):
 def query_interactive(src_fn, dest_fn, src_content, dest_content,
                       simulate):
     global all_answer
+    src_content = text_(src_content)
+    dest_content = text_(dest_content)
     from difflib import unified_diff, context_diff
     u_diff = list(unified_diff(
         dest_content.splitlines(),
     prompt = 'Overwrite %s [y/n/d/B/?] ' % dest_fn
     while 1:
         if all_answer is None:
-            response = raw_input(prompt).strip().lower()
+            response = input_(prompt).strip().lower()
         else:
             response = all_answer
         if not response or response[0] == 'b':
     if template_renderer is not None:
         return template_renderer(content, vars, filename=filename)
     if not use_cheetah:
-        tmpl = LaxTemplate(content)
+        tmpl = LaxTemplate(text_(content))
         try:
             return tmpl.substitute(TypeMapper(v))
         except Exception:
         else:
             value = eval(options[-1], dict(self.items()))
         if value is None:
-            return ''
+            return text_('')
         else:
-            return str(value)
+            return text_(value)
 
 def eval_with_catch(expr, vars):
     try:
 class LaxTemplate(string.Template):
     # This change of pattern allows for anything in braces, but
     # only identifiers outside of braces:
-    pattern = r"""
+    pattern = text_(r"""
     \$(?:
       (?P<escaped>\$)             |   # Escape sequence of two delimiters
       (?P<named>[_a-z][_a-z0-9]*) |   # delimiter and a Python identifier
       {(?P<braced>.*?)}           |   # delimiter and a braced identifier
       (?P<invalid>)                   # Other ill-formed delimiter exprs
     )
-    """
+    """)

paste/script/create_distro.py

         return self._entry_points
 
     def display_vars(self, vars):
-        vars = vars.items()
+        vars = list(vars.items())
         vars.sort()
         print_('Variables:')
         max_var = max([len(n) for n, v in vars])
                 print_('Warning: could not load entry point %s (%s: %s)' % (
                     entry.name, e.__class__.__name__, e))
         max_name = max([len(t.name) for t in templates])
-        templates.sort(lambda a, b: cmp(a.name, b.name))
+        templates.sort(key=lambda a: a.name)
         print_('Available templates:')
         for template in templates:
             # @@: Wrap description

paste/script/templates.py

 import tempita
 from paste.script import copydir
 from paste.script import command
-from paste.script.compat import print_, string_types
+from paste.script.compat import print_, string_types, text_
 
 def paste_script_template_renderer(content, vars, filename=None):
-    tmpl = tempita.Template(content, name=filename)
+    tmpl = tempita.Template(text_(content), name=filename)
     return tmpl.substitute(vars)
 
 class Template(object):