Completed
Push — develop ( f3eb03...f601c5 )
by Wu
10s
created

BaseEntry   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 4
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 1
c 4
b 1
f 0
dl 0
loc 4
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 3 1
1
# -*- coding: utf-8 -*-
2
from werobot.utils import to_text
3
4
5
class BaseEntry(object):
6
    def __init__(self, entry, default=None):
7
        self.entry = entry
8
        self.default = default
9
10
11
class IntEntry(BaseEntry):
12
    def __get__(self, instance, owner):
13
        try:
14
            v = int(instance.__dict__.get(self.entry, self.default))
15
        except TypeError:
16
            v = None
17
        return v
18
19
20
class FloatEntry(BaseEntry):
21
    def __get__(self, instance, owner):
22
        try:
23
            v = float(instance.__dict__.get(self.entry, self.default))
24
        except TypeError:
25
            v = None
26
        return v
27
28
29
class StringEntry(BaseEntry):
30
    def __get__(self, instance, owner):
31
        v = instance.__dict__.get(self.entry, self.default)
32
        if v is not None:
33
            return to_text(v)
34
        return v
35