~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to addons/kate/pate/src/plugins/expand/text_x-python.expand

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
# kate: space-indent on; hl python;
3
 
 
4
 
def fori(s=None):
5
 
    if s is None:
6
 
        return 'for i in xrange(%{cursor}):\n\t'
7
 
    else:
8
 
        return '''for i in xrange({0}):\n\t%{{cursor}}'''.format(s)
9
 
 
10
 
# cannot define a function 'class' as class is a keyword
11
 
def _class(s=None):
12
 
    if s is None:
13
 
        return '''\
14
 
class %{cursor}:
15
 
\tdef __init__(self):
16
 
\t\t
17
 
'''
18
 
    else:
19
 
        print("** PYTHON CLASS EXPANDER: s="+repr(s))
20
 
        base, parents = [x.strip() for x in s.split(',', 1)]
21
 
        head = '%s(%s)' % (base, parents) if parents else base
22
 
        s = '''\
23
 
class {0}:
24
 
\tdef __init__(self%{{cursor}}):
25
 
\t\t'''.format(head)
26
 
        if parents:
27
 
            for parent in parents.split(','):
28
 
                parent = parent.strip()
29
 
                s += '%s.__init__(self)\n\t\t' % parent
30
 
        return s + '\n'
31
 
_class.__name__ = 'class'
32
 
 
33
 
 
34
 
def property(name):
35
 
    # cater for the most common case -- a get and a set property
36
 
    return '''\
37
 
def _get_{0}s(self):
38
 
\t%{{cursor}}
39
 
def _set_{0}s(self, {0}s):
40
 
\t
41
 
{0}s = property(_get_{0}s, _set_{0}s)'''.format(name)
42
 
 
43
 
 
44
 
def main():
45
 
    return '''def main():
46
 
\t%{cursor}
47
 
 
48
 
if __name__ == '__main__':
49
 
\tmain()
50
 
'''