Improve pylint score to above 9 for most gen.lib objects
This commit is contained in:
parent
e013122afc
commit
b8a38cd5e5
@ -28,7 +28,7 @@ AttributeRootBase class for Gramps.
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from .attribute import Attribute
|
||||
from .attribute import Attribute, AttributeRoot
|
||||
from .srcattribute import SrcAttribute
|
||||
from .const import IDENTICAL, EQUAL
|
||||
|
||||
@ -41,7 +41,7 @@ class AttributeRootBase(object):
|
||||
"""
|
||||
Base class for attribute-aware objects.
|
||||
"""
|
||||
_CLASS = None
|
||||
_CLASS = AttributeRoot
|
||||
|
||||
def __init__(self, source=None):
|
||||
"""
|
||||
|
@ -182,9 +182,9 @@ def _start_of_year(year):
|
||||
molad_day = molad_day + (molad_halakim // _HBR_HALAKIM_PER_DAY)
|
||||
molad_halakim = molad_halakim % _HBR_HALAKIM_PER_DAY
|
||||
|
||||
pTishri1 = _tishri1(metonic_year, molad_day, molad_halakim)
|
||||
ptishri1 = _tishri1(metonic_year, molad_day, molad_halakim)
|
||||
|
||||
return (metonic_cycle, metonic_year, molad_day, molad_halakim, pTishri1)
|
||||
return (metonic_cycle, metonic_year, molad_day, molad_halakim, ptishri1)
|
||||
|
||||
def hebrew_sdn(year, month, day):
|
||||
"""Convert a Jewish calendar date to an SDN number."""
|
||||
@ -225,16 +225,16 @@ def hebrew_sdn(year, month, day):
|
||||
molad_day, molad_halakim, tishri1_after) = _start_of_year(year+1)
|
||||
|
||||
if _HBR_MONTHS_PER_YEAR[(year - 1) % 19] == 12:
|
||||
length_of_adarI_andII = 29
|
||||
length_of_adar_1and2 = 29
|
||||
else:
|
||||
length_of_adarI_andII = 59
|
||||
length_of_adar_1and2 = 59
|
||||
|
||||
if month == 4:
|
||||
sdn = tishri1_after + day - length_of_adarI_andII - 237
|
||||
sdn = tishri1_after + day - length_of_adar_1and2 - 237
|
||||
elif month == 5:
|
||||
sdn = tishri1_after + day - length_of_adarI_andII - 208
|
||||
sdn = tishri1_after + day - length_of_adar_1and2 - 208
|
||||
else:
|
||||
sdn = tishri1_after + day - length_of_adarI_andII - 178
|
||||
sdn = tishri1_after + day - length_of_adar_1and2 - 178
|
||||
else:
|
||||
# It is Adar II or later - don't need the year length.
|
||||
(metonic_cycle, metonic_year,
|
||||
@ -565,7 +565,7 @@ def swedish_ymd(sdn):
|
||||
elif 2342042 <= sdn < 2346425:
|
||||
return julian_ymd(sdn+1)
|
||||
# Gregorian Calendar (1753-03-01)
|
||||
elif 2361390 <= sdn:
|
||||
elif sdn >= 2361390:
|
||||
return gregorian_ymd(sdn)
|
||||
else:
|
||||
return julian_ymd(sdn)
|
||||
|
@ -125,14 +125,14 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
|
||||
"""
|
||||
Return labels.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def get_schema(cls):
|
||||
"""
|
||||
Return schema.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def get_label(cls, field, _):
|
||||
|
@ -105,7 +105,7 @@ class SecondaryObject(BaseObject):
|
||||
"""
|
||||
Return labels.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
return {}
|
||||
|
||||
def get_label(self, field, _):
|
||||
"""
|
||||
|
@ -53,19 +53,3 @@ class SrcAttribute(AttributeRoot):
|
||||
else:
|
||||
self.type = SrcAttributeType()
|
||||
self.value = ""
|
||||
|
||||
|
||||
def get_text_data_list(self):
|
||||
"""
|
||||
Return the list of all textual attributes of the object.
|
||||
|
||||
:returns: Returns the list of all textual attributes of the object.
|
||||
:rtype: list
|
||||
"""
|
||||
sat = SrcAttributeType()
|
||||
if self.type == sat.SRCTYPE:
|
||||
#we convert to the native language if possible
|
||||
if self.value and self.value in sat.E2I_SRCTYPEMAP:
|
||||
return [sat.I2S_SRCTYPEMAP[sat.E2I_SRCTYPEMAP[self.value]]]
|
||||
return [self.value]
|
||||
|
||||
|
@ -88,8 +88,11 @@ class StyledText(object):
|
||||
|
||||
# special methods
|
||||
|
||||
def __str__(self): return self._string.__str__()
|
||||
def __repr__(self): return self._string.__repr__()
|
||||
def __str__(self):
|
||||
return self._string.__str__()
|
||||
|
||||
def __repr__(self):
|
||||
return self._string.__repr__()
|
||||
|
||||
def __add__(self, other):
|
||||
"""Implement '+' operation on the class.
|
||||
@ -104,12 +107,12 @@ class StyledText(object):
|
||||
|
||||
if isinstance(other, StyledText):
|
||||
# need to join strings and merge tags
|
||||
for tag in other._tags:
|
||||
for tag in other.tags:
|
||||
tag.ranges = [(start + offset, end + offset)
|
||||
for (start, end) in tag.ranges]
|
||||
|
||||
return self.__class__("".join([self._string, other._string]),
|
||||
self._tags + other._tags)
|
||||
return self.__class__("".join([self._string, other.string]),
|
||||
self._tags + other.tags)
|
||||
elif isinstance(other, str):
|
||||
# tags remain the same, only text becomes longer
|
||||
return self.__class__("".join([self._string, other]), self._tags)
|
||||
@ -118,13 +121,13 @@ class StyledText(object):
|
||||
self._tags)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self._string == other._string and self._tags == other._tags
|
||||
return self._string == other.string and self._tags == other.tags
|
||||
|
||||
def __ne__(self, other):
|
||||
return self._string != other._string or self._tags != other._tags
|
||||
return self._string != other.string or self._tags != other.tags
|
||||
|
||||
def __lt__(self, other):
|
||||
return self._string < other._string
|
||||
return self._string < other.string
|
||||
|
||||
def __le__(self, other):
|
||||
return self.__lt__(other) or self.__eq__(other)
|
||||
@ -138,24 +141,25 @@ class StyledText(object):
|
||||
def __mod__(self, other):
|
||||
"""Implement '%' operation on the class."""
|
||||
|
||||
# test whether the formatting operation is valid at all
|
||||
# This will raise an exception if the formatting operation is invalid
|
||||
self._string % other
|
||||
|
||||
result = self.__class__(self._string, self._tags)
|
||||
|
||||
i0 = 0
|
||||
start = 0
|
||||
while True:
|
||||
i1 = result._string.find('%', i0)
|
||||
if i1 < 0:
|
||||
idx1 = result.string.find('%', start)
|
||||
if idx1 < 0:
|
||||
break
|
||||
if result._string[i1+1] == '(':
|
||||
i2 = result._string.find(')', i1+3)
|
||||
param_name = result._string[i1+2:i2]
|
||||
if result.string[idx1+1] == '(':
|
||||
idx2 = result.string.find(')', idx1+3)
|
||||
param_name = result.string[idx1+2:idx2]
|
||||
else:
|
||||
i2 = i1
|
||||
idx2 = idx1
|
||||
param_name = None
|
||||
for i3 in range(i2+1, len(result._string)):
|
||||
if result._string[i3] in 'diouxXeEfFgGcrs%':
|
||||
end = idx2 + 1
|
||||
for end in range(idx2+1, len(result.string)):
|
||||
if result.string[end] in 'diouxXeEfFgGcrs%':
|
||||
break
|
||||
if param_name is not None:
|
||||
param = other[param_name]
|
||||
@ -165,10 +169,12 @@ class StyledText(object):
|
||||
else:
|
||||
param = other
|
||||
if not isinstance(param, StyledText):
|
||||
param = StyledText('%' + result._string[i2+1:i3+1] % param)
|
||||
(before, after) = result.split(result._string[i1:i3+1], 1)
|
||||
result = before + param + after
|
||||
i0 = i3 + 1
|
||||
param_type = '%' + result.string[idx2+1:end+1]
|
||||
param = StyledText(param_type % param)
|
||||
parts = result.split(result.string[idx1:end+1], 1)
|
||||
if len(parts) == 2:
|
||||
result = parts[0] + param + parts[1]
|
||||
start = end + 1
|
||||
|
||||
return result
|
||||
|
||||
@ -194,7 +200,7 @@ class StyledText(object):
|
||||
|
||||
for text in seq:
|
||||
if isinstance(text, StyledText):
|
||||
for tag in text._tags:
|
||||
for tag in text.tags:
|
||||
tag.ranges = [(start + offset, end + offset)
|
||||
for (start, end) in tag.ranges]
|
||||
new_tags += [tag]
|
||||
|
@ -78,6 +78,55 @@ class TableObject(BaseObject):
|
||||
self.handle = None
|
||||
self.change = 0
|
||||
|
||||
def serialize(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in this object to a structure (eg,
|
||||
struct) that represents all the data elements.
|
||||
|
||||
This method is used to recursively convert the object into a
|
||||
self-documenting form that can easily be used for various
|
||||
purposes, including diffs and queries.
|
||||
|
||||
These structures may be primitive Python types (string,
|
||||
integer, boolean, etc.) or complex Python types (lists,
|
||||
tuples, or dicts). If the return type is a dict, then the keys
|
||||
of the dict match the fieldname of the object. If the return
|
||||
struct (or value of a dict key) is a list, then it is a list
|
||||
of structs. Otherwise, the struct is just the value of the
|
||||
attribute.
|
||||
|
||||
:returns: Returns a struct containing the data of the object.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def from_struct(self, struct):
|
||||
"""
|
||||
Given a struct data representation, return an object of this type.
|
||||
|
||||
These structures may be primitive Python types (string,
|
||||
integer, boolean, etc.) or complex Python types (lists,
|
||||
tuples, or dicts). If the return type is a dict, then the keys
|
||||
of the dict match the fieldname of the object. If the return
|
||||
struct (or value of a dict key) is a list, then it is a list
|
||||
of structs. Otherwise, the struct is just the value of the
|
||||
attribute.
|
||||
|
||||
:returns: Returns an object of this type.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_change_time(self):
|
||||
"""
|
||||
Return the time that the data was last changed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user