forked from sopel-irc/sopel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
55 lines (47 loc) · 1.42 KB
/
tools.py
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
#!/usr/bin/env python
# coding=utf-8
"""
tools.py - Willie misc tools
Copyright 2008, Sean B. Palmer, inamidst.com
Copyright © 2012, Elad Alfassa <[email protected]>
Licensed under the Eiffel Forum License 2.
https://willie.dftba.net
"""
import sys
def deprecated(old):
def new(willie, input, old=old):
self = willie
origin = type('Origin', (object,), {
'sender': input.sender,
'nick': input.nick
})()
match = input.match
args = [input.bytes, input.sender, '@@']
old(self, origin, match, args)
new.__module__ = old.__module__
new.__name__ = old.__name__
return new
# from http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional-dictionaries-in-python/
# A simple class to make mutli dimensional dict easy to use
class Ddict(dict):
''' A simple multi dimensional dict '''
def __init__(self, default=None):
self.default = default
def __getitem__(self, key):
if not self.has_key(key):
self[key] = self.default()
return dict.__getitem__(self, key)
def try_print(string):
''' Try printing to terminal, ignore errors '''
try:
print string
except:
pass
def try_print_stderr(string):
''' Try printing to stderr, ignore errors '''
try:
print >> sys.stderr, string
except:
pass
if __name__ == '__main__':
print __doc__.strip()