Completed
Push — master ( b34b71...1c0f48 )
by Andrii
12:24
created

REPP.get_greeting()   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 get_greeting(self):
19
        return self.greeting
20
21
    def request(self, xml):
22
        res = self.epp.request(xml)
23
        if not res:
24
            self.connect()
25
            res = self.epp.request(xml)
26
        return res
27
28
class EPP:
29
    def __init__(self, config):
30
        self.config = config
31
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
32
        self.socket.connect((self.config['host'], self.config['port']))
33
        self.ssl = ssl.wrap_socket(self.socket,
34
            keyfile  = self.config['keyfile'],
35
            certfile = self.config['certfile'],
36
            ca_certs = self.config['ca_certs'])
37
        self.greeting = self.read()
38
        self.config['start_time'] = datetime.now().isoformat(' ')
39
40
    def get_greeting(self):
41
        return self.greeting
42
43
    def request(self, xml):
44
        self.write(xml)
45
        return self.read()
46
47
    def write(self, xml):
48
        Net.write(self.ssl, xml)
49
50
    def read(self):
51
        return Net.read(self.ssl)
52
53