Completed
Push — master ( 9a8d42...b34b71 )
by Andrii
23:21
created

EPP.read()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
#!/usr/bin/env python
2
3
import ssl
4
import socket
5
from datetime import datetime
6
7
from heppy import Net
8
9
class REPP:
10
    def __init__(self, config):
11
        self.config = config
12
        self.connect()
13
14
    def connect(self):
15
        self.epp = EPP(self.config)
16
        self.greeting = self.epp.greeting
17
18
    def command(self, xml):
19
        res = self.epp.command(xml)
20
        if not res:
21
            self.connect()
22
            res = self.epp.command(xml)
23
        return res
24
25
class EPP:
26
    def __init__(self, config):
27
        self.config = config
28
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
29
        self.socket.connect((self.config['host'], self.config['port']))
30
        self.ssl = ssl.wrap_socket(self.socket,
31
            keyfile  = self.config['keyfile'],
32
            certfile = self.config['certfile'],
33
            ca_certs = self.config['ca_certs'])
34
        self.greeting = self.read()
35
        self.config['start_time'] = datetime.now().isoformat(' ')
36
37
    def command(self, xml):
38
        self.write(xml)
39
        return self.read()
40
41
    def write(self, xml):
42
        Net.write(self.ssl, xml)
43
44
    def read(self):
45
        return Net.read(self.ssl)
46
47
48