@@ -49,6 +49,16 @@ def int_to_net(value, format_32):
49
49
50
50
#------------------------------------------------------------------------------
51
51
52
+ class EPPConnectionAlreadyClosedError (Exception ):
53
+ pass
54
+
55
+
56
+ class EPPResponseEmptyError (Exception ):
57
+ pass
58
+
59
+ #------------------------------------------------------------------------------
60
+
61
+
52
62
class EPPConnection :
53
63
54
64
def __init__ (self , host , port , user , password , verbose = False , raise_errors = False ):
@@ -63,7 +73,7 @@ def __init__(self, host, port, user, password, verbose=False, raise_errors=False
63
73
self .verbose = verbose
64
74
self .raise_errors = raise_errors
65
75
66
- def open (self , timeout = 2 ):
76
+ def open (self , timeout = 10 ):
67
77
self .socket = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
68
78
self .socket .settimeout (timeout )
69
79
try :
@@ -116,7 +126,7 @@ def close(self):
116
126
if self .raise_errors :
117
127
raise exc
118
128
if self .verbose :
119
- logger .exception ('connection was not properly connected ' )
129
+ logger .exception ('connection was not properly closed ' )
120
130
return False
121
131
if self .verbose :
122
132
logger .debug ('EPP connection closed' )
@@ -129,17 +139,20 @@ def read(self):
129
139
if length :
130
140
i = int_from_net (length , self .format_32 ) - 4
131
141
ret = self .ssl .read (i )
142
+ except (ssl .SSLEOFError , ssl .SSLZeroReturnError , ) as exc :
143
+ if self .verbose :
144
+ logger .exception ('EPP connection already closed' )
145
+ raise EPPConnectionAlreadyClosedError (exc )
132
146
except Exception as exc :
133
147
if self .raise_errors :
134
148
raise exc
135
149
if self .verbose :
136
150
logger .exception ('failed to receive EPP response' )
137
151
return None
138
152
if ret is None :
139
- if self .raise_errors :
140
- raise Exception ('nothing was received from EPP connection' )
141
153
if self .verbose :
142
154
logger .error ('nothing was received from EPP connection' )
155
+ raise EPPResponseEmptyError ()
143
156
return ret
144
157
145
158
def write (self , xml ):
@@ -150,6 +163,10 @@ def write(self, xml):
150
163
try :
151
164
self .ssl .send (length )
152
165
ret = self .ssl .send ((epp_as_string + "\r \n " ).encode ())
166
+ except (ssl .SSLEOFError , ssl .SSLZeroReturnError , ) as exc :
167
+ if self .verbose :
168
+ logger .exception ('EPP connection already closed' )
169
+ raise EPPConnectionAlreadyClosedError (exc )
153
170
except Exception as exc :
154
171
if self .raise_errors :
155
172
raise exc
@@ -178,9 +195,9 @@ def call(self, cmd, soup=False):
178
195
raise exc
179
196
if self .verbose :
180
197
logger .exception ('failed to read EPP response command' )
181
- return None
198
+ return ''
182
199
return soup
183
- return raw
200
+ return raw or ''
184
201
185
202
#------------------------------------------------------------------------------
186
203
@@ -235,88 +252,23 @@ def poll_ack(self, msg_id):
235
252
msgid = msg_id ,
236
253
))
237
254
238
- def domain_check (self , domain_name ):
239
- return self .call (cmd = commands .domain .check % dict (
240
- cltrid = make_cltrid (),
241
- domain_names = commands .domain .single % domain_name ,
242
- ))
243
-
244
- def domain_check_multiple (self , domains_list ):
245
- return self .call (cmd = commands .domain .check % dict (
246
- cltrid = make_cltrid (),
247
- domain_names = '\n ' .join ([
248
- commands .domain .single % d for d in domains_list
249
- ]),
250
- ))
251
-
252
- def domain_info (self , domain_name , auth_info = None ):
253
- return self .call (cmd = commands .domain .info % dict (
254
- cltrid = make_cltrid (),
255
- domain_name = domain_name ,
256
- auth_info = '' if not auth_info else commands .domain .auth_info % auth_info ,
257
- ))
258
-
259
- def domain_create (self , domain_name , registrant , nameservers = [], period = 1 , period_units = 'y' ,
260
- contact_admin = None , contact_billing = None , contact_tech = None , auth_info = None ):
261
- return self .call (cmd = commands .domain .create % dict (
262
- cltrid = make_cltrid (),
263
- domain_name = domain_name ,
264
- registrant = registrant ,
265
- nameservers = '\n ' .join ([
266
- commands .domain .single_nameserver % ns for ns in nameservers
267
- ]),
268
- period = '' if period is None else commands .domain .period % dict (value = period , units = period_units or 'y' ),
269
- contact_admin = '' if not contact_admin else commands .domain .single_contact % dict (type = 'admin' , id = contact_admin ),
270
- contact_billing = '' if not contact_billing else commands .domain .single_contact % dict (type = 'billing' , id = contact_billing ),
271
- contact_tech = '' if not contact_tech else commands .domain .single_contact % dict (type = 'tech' , id = contact_tech ),
272
- auth_info = '' if not auth_info else commands .domain .auth_info % auth_info ,
273
- ))
274
-
275
- def domain_renew (self , domain_name , cur_exp_date , period = 1 , period_units = 'y' ):
276
- return self .call (cmd = commands .domain .renew % dict (
255
+ def host_check (self , nameservers_list ):
256
+ return self .call (cmd = commands .nameserver .check % dict (
277
257
cltrid = make_cltrid (),
278
- domain_name = domain_name ,
279
- cur_exp_date = cur_exp_date ,
280
- period = '' if period is None else commands .domain .period % dict (value = period , units = period_units or 'y' ),
258
+ nameservers = '\n ' .join ([commands .nameserver .single % ns for ns in nameservers_list ]),
281
259
))
282
260
283
- def domain_update (self , domain_name , auth_info = None ,
284
- add_nameservers = [], remove_nameservers = [],
285
- add_contacts = [], remove_contacts = [], change_registrant = None ,
286
- rgp_restore = None , rgp_restore_report = None ):
287
- restore_extension = ''
288
- if rgp_restore :
289
- restore_extension = commands .domain .restore_request_extension
290
- if rgp_restore_report :
291
- restore_extension = commands .domain .restore_report_extension % rgp_restore_report
292
- return self .call (cmd = commands .domain .update % dict (
261
+ def host_info (self , nameserver ):
262
+ return self .call (cmd = commands .nameserver .info % dict (
293
263
cltrid = make_cltrid (),
294
- domain_name = domain_name ,
295
- auth_info = '' if not auth_info else commands .domain .auth_info % auth_info ,
296
- add_nameservers = '\n ' .join ([
297
- commands .domain .single_nameserver % ns for ns in add_nameservers
298
- ]),
299
- remove_nameservers = '\n ' .join ([
300
- commands .domain .single_nameserver % ns for ns in remove_nameservers
301
- ]),
302
- add_contacts = '\n ' .join ([
303
- commands .domain .single_contact % c for c in add_contacts
304
- ]),
305
- remove_contacts = '\n ' .join ([
306
- commands .domain .single_contact % c for c in remove_contacts
307
- ]),
308
- change_registrant = '' if not change_registrant else (
309
- commands .domain .single_registrant % change_registrant
310
- ),
311
- restore_extension = restore_extension ,
264
+ nameserver = nameserver ,
312
265
))
313
266
314
- def domain_transfer (self , domain_name , auth_info = None , period = None , period_units = None ):
315
- return self .call (cmd = commands .domain . transfer % dict (
267
+ def host_create (self , nameserver , ip_addresses_list ):
268
+ return self .call (cmd = commands .nameserver . create % dict (
316
269
cltrid = make_cltrid (),
317
- domain_name = domain_name ,
318
- auth_info = '' if not auth_info else commands .domain .auth_info % auth_info ,
319
- period = '' if period is None else commands .domain .period % dict (value = period , units = period_units or 'y' ),
270
+ nameserver = nameserver ,
271
+ ip_addresses = '\n ' .join ([commands .nameserver .ip_address % ipaddr for ipaddr in ip_addresses_list ])
320
272
))
321
273
322
274
def contact_check (self , contact ):
@@ -397,26 +349,91 @@ def contact_update(self, contact_id, voice=None, fax=None, email=None, contacts=
397
349
))
398
350
399
351
def contact_delete (self , contact_id ):
400
- return self .call (cmd = commands .contact .info % dict (
352
+ return self .call (cmd = commands .contact .delete % dict (
401
353
cltrid = make_cltrid (),
402
354
contact_id = contact_id ,
403
355
))
404
356
405
- def host_check (self , nameservers_list ):
406
- return self .call (cmd = commands .nameserver .check % dict (
357
+ def domain_check (self , domain_name ):
358
+ return self .call (cmd = commands .domain .check % dict (
407
359
cltrid = make_cltrid (),
408
- nameservers = ' \n ' . join ([ commands .nameserver .single % ns for ns in nameservers_list ]) ,
360
+ domain_names = commands .domain .single % domain_name ,
409
361
))
410
362
411
- def host_info (self , nameserver ):
412
- return self .call (cmd = commands .nameserver . info % dict (
363
+ def domain_check_multiple (self , domains_list ):
364
+ return self .call (cmd = commands .domain . check % dict (
413
365
cltrid = make_cltrid (),
414
- nameserver = nameserver ,
366
+ domain_names = '\n ' .join ([
367
+ commands .domain .single % d for d in domains_list
368
+ ]),
415
369
))
416
370
417
- def host_create (self , nameserver , ip_addresses_list ):
418
- return self .call (cmd = commands .nameserver . create % dict (
371
+ def domain_info (self , domain_name , auth_info = None ):
372
+ return self .call (cmd = commands .domain . info % dict (
419
373
cltrid = make_cltrid (),
420
- nameserver = nameserver ,
421
- ip_addresses = '\n ' .join ([commands .nameserver .ip_address % ipaddr for ipaddr in ip_addresses_list ])
374
+ domain_name = domain_name ,
375
+ auth_info = '' if not auth_info else commands .domain .auth_info % auth_info ,
376
+ ))
377
+
378
+ def domain_create (self , domain_name , registrant , nameservers = [], period = 1 , period_units = 'y' ,
379
+ contact_admin = None , contact_billing = None , contact_tech = None , auth_info = None ):
380
+ return self .call (cmd = commands .domain .create % dict (
381
+ cltrid = make_cltrid (),
382
+ domain_name = domain_name ,
383
+ registrant = registrant ,
384
+ nameservers = '\n ' .join ([
385
+ commands .domain .single_nameserver % ns for ns in nameservers
386
+ ]),
387
+ period = '' if period is None else commands .domain .period % dict (value = period , units = period_units or 'y' ),
388
+ contact_admin = '' if not contact_admin else commands .domain .single_contact1 % dict (type = 'admin' , id = contact_admin ),
389
+ contact_billing = '' if not contact_billing else commands .domain .single_contact1 % dict (type = 'billing' , id = contact_billing ),
390
+ contact_tech = '' if not contact_tech else commands .domain .single_contact1 % dict (type = 'tech' , id = contact_tech ),
391
+ auth_info = '' if not auth_info else commands .domain .auth_info % auth_info ,
392
+ ))
393
+
394
+ def domain_renew (self , domain_name , cur_exp_date , period = 1 , period_units = 'y' ):
395
+ return self .call (cmd = commands .domain .renew % dict (
396
+ cltrid = make_cltrid (),
397
+ domain_name = domain_name ,
398
+ cur_exp_date = cur_exp_date ,
399
+ period = '' if period is None else commands .domain .period % dict (value = period , units = period_units or 'y' ),
400
+ ))
401
+
402
+ def domain_update (self , domain_name , auth_info = None ,
403
+ add_nameservers = [], remove_nameservers = [],
404
+ add_contacts = [], remove_contacts = [], change_registrant = None ,
405
+ rgp_restore = None , rgp_restore_report = None ):
406
+ restore_extension = ''
407
+ if rgp_restore :
408
+ restore_extension = commands .domain .restore_request_extension
409
+ if rgp_restore_report :
410
+ restore_extension = commands .domain .restore_report_extension % rgp_restore_report
411
+ return self .call (cmd = commands .domain .update % dict (
412
+ cltrid = make_cltrid (),
413
+ domain_name = domain_name ,
414
+ auth_info = '' if not auth_info else commands .domain .auth_info2 % auth_info ,
415
+ add_nameservers = '\n ' .join ([
416
+ commands .domain .single_nameserver % ns for ns in add_nameservers
417
+ ]),
418
+ remove_nameservers = '\n ' .join ([
419
+ commands .domain .single_nameserver % ns for ns in remove_nameservers
420
+ ]),
421
+ add_contacts = '\n ' .join ([
422
+ commands .domain .single_contact2 % c for c in add_contacts
423
+ ]),
424
+ remove_contacts = '\n ' .join ([
425
+ commands .domain .single_contact2 % c for c in remove_contacts
426
+ ]),
427
+ change_registrant = '' if not change_registrant else (
428
+ commands .domain .single_registrant % change_registrant
429
+ ),
430
+ restore_extension = restore_extension ,
431
+ ))
432
+
433
+ def domain_transfer (self , domain_name , auth_info = None , period = None , period_units = None ):
434
+ return self .call (cmd = commands .domain .transfer % dict (
435
+ cltrid = make_cltrid (),
436
+ domain_name = domain_name ,
437
+ auth_info = '' if not auth_info else commands .domain .auth_info % auth_info ,
438
+ period = '' if period is None else commands .domain .period % dict (value = period , units = period_units or 'y' ),
422
439
))
0 commit comments