| 314 | """ |
| 315 | |
| 316 | class NumericCell(BaseCell): |
| 317 | |
| 318 | def __init__(self, value, fmt="%s", alignment=RIGHT): |
| 319 | assert isinstance(value, (int, float, complex)) |
| 320 | assert alignment in (LEFT, CENTER, RIGHT) |
| 321 | self.value = value |
| 322 | self.fmt = fmt |
| 323 | self.alignment = alignment |
| 324 | |
| 325 | def recalc(self, ns): |
| 326 | return self.value |
| 327 | |
| 328 | def format(self): |
| 329 | try: |
| 330 | text = self.fmt % self.value |
| 331 | except: |
| 332 | text = str(self.value) |
| 333 | return text, self.alignment |
| 334 | |
| 335 | def xml(self): |
| 336 | method = getattr(self, '_xml_' + type(self.value).__name__) |
| 337 | return '<value align="%s" format="%s">%s</value>' % ( |
| 338 | align2xml[self.alignment], |
| 339 | self.fmt, |
| 340 | method()) |
| 341 | |
| 342 | def _xml_int(self): |
| 343 | if -2**31 <= self.value < 2**31: |
| 344 | return '<int>%s</int>' % self.value |
| 345 | else: |
| 346 | return '<long>%s</long>' % self.value |
| 347 | |
| 348 | def _xml_float(self): |
| 349 | return '<double>%r</double>' % self.value |
| 350 | |
| 351 | def _xml_complex(self): |
| 352 | return '<complex>%r</complex>' % self.value |
| 353 | |
| 354 | class StringCell(BaseCell): |
| 355 |
no outgoing calls