[PythonReports-checkins] PythonReports/PythonReports datatypes.py, 1.2, 1.3
Brought to you by:
a1s
From: alexander s. <a1...@us...> - 2006-12-06 16:22:55
|
Update of /cvsroot/pythonreports/PythonReports/PythonReports In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26769 Modified Files: datatypes.py Log Message: sweep pylint warnings Index: datatypes.py =================================================================== RCS file: /cvsroot/pythonreports/PythonReports/PythonReports/datatypes.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** datatypes.py 3 Nov 2006 11:51:17 -0000 1.2 --- datatypes.py 6 Dec 2006 16:22:48 -0000 1.3 *************** *** 1,4 **** --- 1,5 ---- """Data types and element primitives, common for templates and printouts""" """History: + 05-dec-2006 [als] sweep pylint warnings 03-nov-2006 [als] ElementTree: string conversion returns full XML text 20-oct-2006 [als] added Structure *************** *** 27,34 **** 30-jun-2006 [als] created """ import binascii import bz2 - import codecs import cPickle as pickle import sys --- 28,36 ---- 30-jun-2006 [als] created """ + __version__ = "$Revision$"[11:-2] + __date__ = "$Date$"[7:-2] import binascii import bz2 import cPickle as pickle import sys *************** *** 50,60 **** import elementtree.ElementTree as ET except ImportError: # last resort; should always success in python2.5 and newer import xml.etree.ElementTree as ET - - __version__ = "$Revision$"[11:-2] - __date__ = "$Date$"[7:-2] - # export element factories from ElementTree Element = ET.Element --- 52,61 ---- import elementtree.ElementTree as ET except ImportError: + # pylint: disable-msg=E0611 + # E0611: No name 'etree' in module 'xml' - true for python <2.5 + # ... pylint still reports this error # last resort; should always success in python2.5 and newer import xml.etree.ElementTree as ET # export element factories from ElementTree Element = ET.Element *************** *** 221,227 **** element=element, path=path) ! # special value used instead of default in attribute declarations ! # to indicate that the attribute is required. ! class REQUIRED(object): pass # XXX should NOTHING be different from REQUIRED? REQUIRED = NOTHING = REQUIRED() --- 222,237 ---- element=element, path=path) ! class REQUIRED(object): ! ! """"Value is required" value ! ! The singleton instance of this class is a special value ! used instead of default in attribute declarations ! to indicate that the attribute is required. ! ! """ ! # pylint: disable-msg=R0903 ! # R0903: Too few public methods ! # XXX should NOTHING be different from REQUIRED? REQUIRED = NOTHING = REQUIRED() *************** *** 239,242 **** --- 249,254 ---- """ + # pylint: disable-msg=R0903 + # R0903: Too few public methods def __init__(self, **kwargs): *************** *** 335,338 **** --- 347,353 ---- class Number(float, _Value): + """Base class for fixed-point numeric classes, also used as integer number + """ + # number of digits in the fractional part PRECISION = 0 *************** *** 359,367 **** --- 374,390 ---- """ + # pylint: disable-msg=W0602 + # W0602: Using global for '_numeric_classes' but no assigment is done global _numeric_classes try: return _numeric_classes[precision] except KeyError: + # pylint: disable-msg=C0111,W0104 + # W0104: Statement seems to have no effect + # C0111: Missing docstring + # The statement has the effect of setting the docstring. + # and the above pylint hint doesn't help anyway. class _Number(Number): + """Fixed point number with %i decimal digits""" % precision PRECISION = precision _numeric_classes[precision] = _Number *************** *** 419,428 **** class _MetaColor(type): ! def __getitem__(self, name): ! return self.names[name.upper()] ! def __getattr__(self, name): try: ! return self.names[name.upper()] except KeyError: raise AttributeError, name --- 442,453 ---- class _MetaColor(type): ! """Implement access to named colors as class attributes or items""" ! def __getitem__(mcs, name): ! return mcs.names[name.upper()] ! ! def __getattr__(mcs, name): try: ! return mcs.names[name.upper()] except KeyError: raise AttributeError, name *************** *** 430,433 **** --- 455,460 ---- class Color(_Value): + """Color value""" + __metaclass__ = _MetaColor *************** *** 540,543 **** --- 567,571 ---- """ + super(Color, self).__init__() self.value = self.encode(color) *************** *** 570,576 **** """String value used in element attributes""" ! def __new__(cls, value, *args, **kwargs): try: ! return unicode.__new__(cls, value, *args, **kwargs) except (TypeError, ValueError): # note: unicode errors are subclasses of ValueError --- 598,607 ---- """String value used in element attributes""" ! # pylint: disable-msg=R0904 ! # R0904: Too many public methods (39) - most come from unicode. ! ! def __new__(cls, value): try: ! return unicode.__new__(cls, value) except (TypeError, ValueError): # note: unicode errors are subclasses of ValueError *************** *** 583,586 **** --- 614,620 ---- class Expression(String): + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class + """Python expressions used in PRT element attributes""" # This is same as String, put to separate class just to make things clearer *************** *** 592,595 **** --- 626,632 ---- """String value from a domain of allowed values""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class + # list of allowed values for this class # must be overridden in subclasses *************** *** 609,612 **** --- 646,651 ---- """Horizontal alignment type""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("left", "center", "right") *************** *** 615,618 **** --- 654,659 ---- """Vertical alignment type""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("top", "center", "bottom") *************** *** 621,624 **** --- 662,667 ---- """Bar Code type""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("Code128", "Code39", "2of5i") *************** *** 627,630 **** --- 670,675 ---- """Bitmap scale type""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("cut", "fill", "grow") *************** *** 633,636 **** --- 678,683 ---- """Bitmap image format""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class # TODO: list all supported image types *************** *** 640,643 **** --- 687,692 ---- """Calculation type for report variables""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("count", "sum", "avg", "min", "max", "std", "var", "first") *************** *** 646,649 **** --- 695,700 ---- """Compression for 'data' elements""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("zlib", "bz2") *************** *** 652,655 **** --- 703,708 ---- """Type of 'eject' elements""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("page", "column") *************** *** 658,661 **** --- 711,716 ---- """Binary value encoding for 'data' elements""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("base64", "uu", "qp") *************** *** 663,666 **** --- 718,725 ---- class PageSize(_Codes): + """Standard paper size names, evaluating to page dimensions""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class + DIMENSIONS = { # ISO216 paper sizes *************** *** 717,720 **** --- 776,781 ---- """ + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("dot", "dash", "dashdot") *************** *** 722,725 **** --- 783,787 ---- @classmethod def fromValue(cls, value): + """Return Dimension or type code or None""" try: return Dimension.fromValue(value) *************** *** 730,733 **** --- 792,797 ---- """Alignment type for text fields""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("left", "center", "right", "justified") *************** *** 736,739 **** --- 800,805 ---- """Iteration/Reset type for report variables""" + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class VALUES = ("report", "page", "column", "group", "detail") *************** *** 764,767 **** --- 830,836 ---- """ + # pylint: disable-msg=R0903 + # R0903: Too few public methods + def __init__(self, attrname, collection_name=None): """Initialize uniqueness validator *************** *** 777,782 **** if collection_name is None: # e.g. "report groups" for attrname=="groups" ! collection_name = "report %s" % attrname ! self.collection_name = collection_name def __call__(self, tree, element, path): --- 846,852 ---- if collection_name is None: # e.g. "report groups" for attrname=="groups" ! self.collection_name = "report %s" % attrname ! else: ! self.collection_name = collection_name def __call__(self, tree, element, path): *************** *** 832,835 **** --- 902,906 ---- self.attributes = {} self.children = children + # W0612: Unused variable '_restrict' self.child_validators = dict([(_validator.tag, _validator) for (_validator, _restrict) in children]) *************** *** 870,874 **** _value = _cls.fromValue(_attrib[_name]) except: ! (_exc_type, _err, _tb) = sys.exc_info() raise AttributeConversionError(_name, _value, _err, element, path), None, _tb --- 941,945 ---- _value = _cls.fromValue(_attrib[_name]) except: ! (_err, _tb) = sys.exc_info()[1:] raise AttributeConversionError(_name, _value, _err, element, path), None, _tb *************** *** 912,916 **** for (_name, _val) in sorted(element.items()): try: ! (_cls, _default) = self.attributes[_name] except KeyError: # ignore undeclared attributes --- 983,987 ---- for (_name, _val) in sorted(element.items()): try: ! _default = self.attributes[_name][1] except KeyError: # ignore undeclared attributes *************** *** 1033,1059 **** return _elem if attrib.get("pickle"): ! data = pickle.dumps(data, pickle.HIGHEST_PROTOCOL) elif data is None: # don't encode data return _elem _compress = attrib.get("compress") if _compress == "zlib": ! data = zlib.compress(data) elif _compress == "bz2": ! data = bz2.compress(data) _encoding = attrib.get("encoding") if _encoding == "base64": ! data = binascii.b2a_base64(data) ! data = "\n".join([""] + [data[_ii:_ii+76] ! for _ii in xrange(0, len(data), 76)]) elif _encoding == "uu": ! data = "".join(["\n"] + [binascii.b2a_uu(data[_ii:_ii+45]) ! for _ii in xrange(0, len(data), 45)]) elif _encoding == "qp": ! data = "\n" + binascii.b2a_qp(data, True, False) + "\n" else: # encoded data is ASCII. non-encoded must be unicode. ! data = unicode(data) ! _elem.text = data return _elem --- 1104,1133 ---- return _elem if attrib.get("pickle"): ! _data = pickle.dumps(data, pickle.HIGHEST_PROTOCOL) elif data is None: # don't encode data return _elem + else: + # start with plaintext contents + _data = data _compress = attrib.get("compress") if _compress == "zlib": ! _data = zlib.compress(_data) elif _compress == "bz2": ! _data = bz2.compress(_data) _encoding = attrib.get("encoding") if _encoding == "base64": ! _data = binascii.b2a_base64(_data) ! _data = "\n".join([""] + [_data[_ii:_ii+76] ! for _ii in xrange(0, len(_data), 76)]) elif _encoding == "uu": ! _data = "".join(["\n"] + [binascii.b2a_uu(_data[_ii:_ii+45]) ! for _ii in xrange(0, len(_data), 45)]) elif _encoding == "qp": ! _data = "\n" + binascii.b2a_qp(_data, True, False) + "\n" else: # encoded data is ASCII. non-encoded must be unicode. ! _data = unicode(_data) ! _elem.text = _data return _elem *************** *** 1101,1108 **** """ ! # must not add blank spaces to non-encoded values if element.get("encoding"): _indent2 = indent else: _indent2 = "" # there are no children for this element, just text --- 1175,1185 ---- """ ! # pylint: disable-msg=W0613 ! # W0613: Unused argument 'addindent' - API comes from Validator, ! # but there are no child elements in the data element if element.get("encoding"): _indent2 = indent else: + # must not add blank spaces to non-encoded values _indent2 = "" # there are no children for this element, just text *************** *** 1128,1135 **** """ # FIXME: this instantiation seems to be obsolete if isinstance(validator, type): ! validator = validator() ! self.root_validator = validator ET.ElementTree.__init__(self, element=element, file=file) --- 1205,1218 ---- """ + # pylint: disable-msg=W0231,W0622 + # W0231: __init__ method from base class 'ElementTree' is not called + # - ain't it? + # W0622: Redefining built-in 'file' - the name comes from base class + # FIXME: this instantiation seems to be obsolete if isinstance(validator, type): ! self.root_validator = validator() ! else: ! self.root_validator = validator ET.ElementTree.__init__(self, element=element, file=file) *************** *** 1156,1159 **** --- 1239,1245 ---- """ + # pylint: disable-msg=C0103,W0622 + # C0103: Invalid names "file", "encoding" - fancy defaults + # W0622: Redefining built-in 'file' - the name comes from base class assert self._root is not None if not hasattr(file, "write"): *************** *** 1371,1374 **** --- 1457,1462 ---- """ + # pylint: disable-msg=C0103 + # C0103: Invalid name "scale_y" - fancy default if scale_y == None: scale_y = scale_x *************** *** 1384,1391 **** # export constants and all non-private callables and constants __all__ = ["REQUIRED", "NOTHING", "Data", "Font"] + [ ! _name for (_name, _item) in globals().items() ! if callable(_item) and not _name.startswith("_") ] ! del _name, _item # vim: set et sts=4 sw=4 : --- 1472,1479 ---- # export constants and all non-private callables and constants __all__ = ["REQUIRED", "NOTHING", "Data", "Font"] + [ ! _global_name for (_global_name, _global_item) in globals().items() ! if callable(_global_item) and not _global_name.startswith("_") ] ! del _global_name, _global_item # vim: set et sts=4 sw=4 : |