reportlab/lib/utils.py
author rgbecker
Thu, 24 Aug 2000 18:19:47 +0000
changeset 448 cb0c4d97e29b
parent 413 6312e8296c9b
child 452 6bb011a0d63e
permissions -rw-r--r--
Added _className func
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
413
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     1
###############################################################################
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     2
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     3
#	ReportLab Public License Version 1.0
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     4
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     5
#   Except for the change of names the spirit and intention of this
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     6
#   license is the same as that of Python
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     7
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     8
#	(C) Copyright ReportLab Inc. 1998-2000.
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
     9
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    10
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    11
# All Rights Reserved
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    12
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    13
# Permission to use, copy, modify, and distribute this software and its
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    14
# documentation for any purpose and without fee is hereby granted, provided
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    15
# that the above copyright notice appear in all copies and that both that
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    16
# copyright notice and this permission notice appear in supporting
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    17
# documentation, and that the name of ReportLab not be used
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    18
# in advertising or publicity pertaining to distribution of the software
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    19
# without specific, written prior permission. 
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    20
# 
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    21
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    22
# Disclaimer
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    23
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    24
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    25
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    26
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    27
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    28
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    29
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    30
# PERFORMANCE OF THIS SOFTWARE. 
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    31
#
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    32
###############################################################################
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    33
#	$Log: utils.py,v $
448
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    34
#	Revision 1.2  2000/08/24 18:19:47  rgbecker
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    35
#	Added _className func
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    36
#
413
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    37
#	Revision 1.1  2000/08/01 10:50:20  rgbecker
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    38
#	Initial version
448
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    39
#	
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    40
__version__=''' $Id: utils.py,v 1.2 2000/08/24 18:19:47 rgbecker Exp $ '''
413
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    41
from types import *
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    42
SeqTypes = (ListType,TupleType)
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    43
import string
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    44
try:
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    45
	#raise ImportError
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    46
	from reportlab.lib._rl_accel import fp_str
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    47
except ImportError:
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    48
	def fp_str(*a):
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    49
		if len(a)==1 and type(a[0]) in SeqTypes: a = a[0]
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    50
		s = []
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    51
		for i in a:
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    52
			s.append('%0.2f' % i)
6312e8296c9b Initial version
rgbecker
parents:
diff changeset
    53
		return string.join(s)
448
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    54
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    55
def _className(self):
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    56
	'''Return a shortened class name'''
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    57
	try:
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    58
		name = self.__class__.__name__
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    59
		i=string.rfind(name,'.')
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    60
		if i>=0: return name[i+1:]
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    61
		return name
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    62
	except AttributeError:
cb0c4d97e29b Added _className func
rgbecker
parents: 413
diff changeset
    63
		return str(self)