11
11
12
12
from __future__ import print_function
13
13
14
+ from uuid import uuid4 as uuid
14
15
from socket import gethostname
15
16
from optparse import OptionParser
16
17
from collections import defaultdict
17
- from socket import error as SocketError
18
18
from time import localtime , strftime , time
19
19
from datetime import date , datetime , timedelta
20
20
from os import environ , getcwd , makedirs , path
48
48
PIDFILE = path .join (path .dirname (__file__ ), "{0:s}.pid" .format (__name__ ))
49
49
50
50
51
+ def randnick ():
52
+ x = uuid ().hex
53
+ xs = map (str .isalpha , x )
54
+ i = xs .index (True )
55
+ return x [i :][:10 ]
56
+
57
+
51
58
def parse_options ():
52
59
parser = OptionParser (usage = USAGE , version = VERSION )
53
60
@@ -65,7 +72,7 @@ def parse_options():
65
72
66
73
parser .add_option (
67
74
"-n" , "--nick" ,
68
- action = "store" , default = environ [ "USER" ] , dest = "nick" ,
75
+ action = "store" , default = environ . get ( "USER" , randnick ()) , dest = "nick" ,
69
76
help = "Nickname to use"
70
77
)
71
78
@@ -212,10 +219,10 @@ def ready(self, component):
212
219
def keepalive (self ):
213
220
self .fire (write (b"\x00 " ))
214
221
215
- def error (self , etype , evalue , etraceback , handler = None ):
216
- if isinstance ( evalue , SocketError ):
217
- if not self .transport .connected :
218
- Timer (5 , connect (self .host , self .port )).register (self )
222
+ def error (self , * args ):
223
+ print ( "ERROR:" , args )
224
+ if not self .transport .connected :
225
+ Timer (5 , connect (self .host , self .port )).register (self )
219
226
220
227
def connected (self , host , port ):
221
228
"""Connected Event
0 commit comments