Package gavo :: Package base :: Module literals
[frames] | no frames]

Module literals

source code

Functions taking strings and returning python values.

All of them accept None and return None for Nullvalue processing.

All of them leave values alone if they already have the right type.

This is usually used in conjunction with base.typesystems.ToPythonCodeConverter.

Classes
  NumericRange
A `Range` suitable to pass Python numeric types to a PostgreSQL range.
Functions
 
parseSimpleSTCS(s) source code
 
parseDefaultDatetime(literal) source code
 
parseDefaultDate(literal) source code
 
parseDefaultTime(literal) source code
 
parseInt(literal)
returns an int from a literal, or None if literal is None or an empty string.
source code
 
parseFloat(literal)
returns a float from a literal, or None if literal is None or an empty string.
source code
 
parseBooleanLiteral(literal)
returns a python boolean from some string.
source code
 
parseUnicode(literal) source code
 
parseCooPair(soup)
returns a pair of RA, DEC floats if they can be made out in soup or raises a value error.
source code
 
parseSPoint(soup)
returns an ``SPoint`` for a coordinate pair.
source code
 
getDefaultValueParsers(*args)
returns a dict containing all exported names from this module.
source code
Function Details

parseInt(literal)

source code 

returns an int from a literal, or None if literal is None or an empty string.

>>> parseInt("32")
32
>>> parseInt("")
>>> parseInt(None)
Decorators:
  • @utils.document

parseFloat(literal)

source code 

returns a float from a literal, or None if literal is None or an empty string.

Temporarily, this includes a hack to work around a bug in psycopg2.

>>> parseFloat("   5e9 ")
5000000000.0
>>> parseFloat(None)
>>> parseFloat("  ")
>>> parseFloat("wobbadobba")
Traceback (most recent call last):
ValueError: could not convert string to float: wobbadobba
Decorators:
  • @utils.document

parseBooleanLiteral(literal)

source code 

returns a python boolean from some string.

Boolean literals are strings like True, false, on, Off, yes, No in some capitalization.

Decorators:
  • @utils.document

parseCooPair(soup)

source code 

returns a pair of RA, DEC floats if they can be made out in soup or raises a value error.

No range checking is done (yet), i.e., as long as two numbers can be made out, the function is happy.

>>> parseCooPair("23 12")
(23.0, 12.0)
>>> parseCooPair("23.5,-12.25")
(23.5, -12.25)
>>> parseCooPair("3.75 -12.125")
(3.75, -12.125)
>>> parseCooPair("3 25,-12 30")
(51.25, -12.5)
>>> map(str, parseCooPair("12 15 30.5 +52 18 27.5"))
['183.877083333', '52.3076388889']
>>> parseCooPair("3.39 -12 39")
Traceback (most recent call last):
ValueError: Invalid time with sepChar None: '3.39'
>>> parseCooPair("12 15 30.5 +52 18 27.5e")
Traceback (most recent call last):
ValueError: 12 15 30.5 +52 18 27.5e has no discernible position in it
>>> parseCooPair("QSO2230+44.3")
Traceback (most recent call last):
ValueError: QSO2230+44.3 has no discernible position in it

parseSPoint(soup)

source code 

returns an ``SPoint`` for a coordinate pair.

The coordinate pair can be formatted in a variety of ways; see the `function parseCooPair`_. Input is always in degrees.

getDefaultValueParsers(*args)

source code 

returns a dict containing all exported names from this module.

This is useful with typesystems.ToPythonCodeConverter; see rscdef.column.Parameter for an example.

This is always the same dict; thus, if you change it, copy it first.

Decorators:
  • @utils.memoized