forked from ukosuagwu/python-nvd3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslator.py
More file actions
71 lines (50 loc) · 1.8 KB
/
Copy pathtranslator.py
File metadata and controls
71 lines (50 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
class Tag(object):
"""Tag class"""
def __init__(self, content=None):
self.content = content
self.attrs = ' '.join(['%s="%s"' % (attr, value)
for attr, value in self.attrs])
def __str__(self):
return '<%s%s>\n %s\n</%s>' % (self.name,
' ' + self.attrs if self.attrs else '',
self.content,
self.name)
class ScriptTag(Tag):
name = 'script'
attrs = (('type', 'text/javascript'),)
class AnonymousFunction(object):
def __init__(self, arguments, content):
self.arguments = arguments
self.content = content
def __str__(self):
return 'function(%s) { %s }' % (self.arguments, self.content)
class Function(object):
def __init__(self, name):
self.name = name
self._calls = []
def __str__(self):
operations = [self.name]
operations.extend(str(call) for call in self._calls)
return '%s' % ('.'.join(operations),)
def __getattr__(self, attr):
self._calls.append(attr)
return self
def __call__(self, *args):
if not args:
self._calls[-1] = self._calls[-1] + '()'
else:
arguments = ','.join([str(arg) for arg in args])
self._calls[-1] = self._calls[-1] + '(%s)' % (arguments,)
return self
class Assignment(object):
def __init__(self, key, value, scoped=True):
self.key = key
self.value = value
self.scoped = scoped
def __str__(self):
return '%s%s = %s;' % ('var ' if self.scoped else '', self.key, self.value)
def indent(func):
# TODO: Add indents to function str
return str(func)