• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3<plist version="1.0">
4<dict>
5	<key>beforeRunningCommand</key>
6	<string>nop</string>
7	<key>command</key>
8	<string>#!/usr/bin/python
9"""Generate code to warn about a module's removal in Python 3.0.
10
11XXX Not supported:
12- Module's in a package do not have their full name generated.
13- Package's __init__ module; should detect and use the package's name instead.
14
15"""
16py_template = """from warnings import warnpy3k
17warnpy3k("the ${1:%s} module has been removed in Python 3.0", stacklevel=2)
18del warnpy3k$0"""
19
20c_template = """
21if (PyErr_WarnPy3k("the ${1:%s} module has been removed in "
22                   "Python 3.0", 2) &lt; 0)
23    return;$0"""
24
25
26import imp
27import os
28
29file_name = os.path.split(os.environ['TM_FILEPATH'])[1]
30
31py_suffixes = reversed(sorted((suffix[0] for suffix in imp.get_suffixes() if suffix[2] == imp.PY_SOURCE), key=len))
32c_suffixes = reversed(sorted((os.path.splitext(suffix[0])[0] + '.c'
33                                for suffix in imp.get_suffixes() if suffix[2] == imp.C_EXTENSION), key=len))
34
35pairings = ((py_suffixes, py_template), (c_suffixes, c_template))
36
37def create_template(suffixes, template):
38    for suffix in suffixes:
39        if not file_name.endswith(suffix):
40            continue
41        module_name = file_name[:-len(suffix)]
42        return template % module_name
43    else:
44        return None
45
46for template in (create_template(*pair) for pair in pairings):
47    if not template:
48        continue
49    print template,
50    break
51else:
52    print 'XXX Could not generate code.'</string>
53	<key>input</key>
54	<string>none</string>
55	<key>name</key>
56	<string>2 to 3 - Module Deletion</string>
57	<key>output</key>
58	<string>insertAsSnippet</string>
59	<key>tabTrigger</key>
60	<string>2to3moddel</string>
61	<key>uuid</key>
62	<string>9519C22B-6AB8-41A1-94F6-079E0B45C147</string>
63</dict>
64</plist>
65