Package web2py :: Package gluon :: Package contrib :: Package pymysql :: Module converters |
[hide private]
[frames] | no frames]

# Module converters

source code

Functions | [hide private]
convert_bit(connection, field, b) | source code
convert_characters(connection, field, data) | source code
convert_date(connection, field, obj) Returns a DATE column as a date object: | source code
convert_datetime(connection, field, obj) Returns a DATETIME or TIMESTAMP column value as a datetime object: | source code
convert_decimal(connection, field, data) | source code
convert_float(connection, field, data) | source code
convert_int(connection, field, data) | source code
convert_long(connection, field, data) | source code
convert_mysql_timestamp(connection, field, timestamp) Convert a MySQL TIMESTAMP to a Timestamp object. | source code
convert_set(s) | source code
convert_time(connection, field, obj) Returns a TIME column as a time object: | source code
convert_timedelta(connection, field, obj) Returns a TIME column as a timedelta object: | source code
escape_None(value) | source code
escape_bool(value) | source code
escape_date(obj) | source code
escape_datetime(obj) | source code
escape_decimal(obj) | source code
escape_dict(val, charset) | source code
escape_float(value) | source code
escape_int(value) | source code
escape_item(val, charset) | source code
escape_long(value) | source code
escape_object(value) | source code
escape_sequence(val, charset) | source code
escape_set(val, charset) | source code
escape_string(value) | source code
escape_struct_time(obj) | source code
escape_time(obj) | source code
escape_timedelta(obj) | source code
escape_unicode(value) | source code

Variables | [hide private]
| ESCAPE_MAP = ``{``'``\x00``'``:` `'``\\0``'``,` `'``\n``'``:` `'``\\n``'``,` `'``\r``'``:` `'``\\r``'``,` `'``\x1a``'``:``...``
| ESCAPE_REGEX = `re.compile(r'`[`\x00\n\r\x1a\'"\\`]`')`
| conversions = ``{`0`:` <function convert_decimal at 0xd3ccf8>`,` 1`:` <`...``
| decoders = ``{`0`:` <function convert_decimal at 0xd3ccf8>`,` 1`:` <fun`...``
| encoders = ``{`<type 'bool'>`:` <function escape_bool at 0xd3c2a8>`,``...``

Function Details | [hide private]

### convert_date(connection, field, obj) | source code
Returns a DATE column as a date object:
    >>> date_or_None('2007-02-26')
    datetime.date(2007, 2, 26)
Illegal values are returned as None:
    >>> date_or_None('2007-02-31') is None
    True
    >>> date_or_None('0000-00-00') is None
    True

### convert_datetime(connection, field, obj) | source code
Returns a DATETIME or TIMESTAMP column value as a datetime object:
    >>> datetime_or_None('2007-02-25 23:06:20')
    datetime.datetime(2007, 2, 25, 23, 6, 20)
    >>> datetime_or_None('2007-02-25T23:06:20')
    datetime.datetime(2007, 2, 25, 23, 6, 20)
Illegal values are returned as None:
    >>> datetime_or_None('2007-02-31T23:06:20') is None
    True
    >>> datetime_or_None('0000-00-00 00:00:00') is None
    True

### convert_mysql_timestamp(connection, field, timestamp) | source code
Convert a MySQL TIMESTAMP to a Timestamp object. MySQL >= 4.1 returns TIMESTAMP in the same format as DATETIME:
    >>> mysql_timestamp_converter('2007-02-25 22:32:17')
    datetime.datetime(2007, 2, 25, 22, 32, 17)
MySQL < 4.1 uses a big string of numbers:
    >>> mysql_timestamp_converter('20070225223217')
    datetime.datetime(2007, 2, 25, 22, 32, 17)
Illegal values are returned as None:
    >>> mysql_timestamp_converter('2007-02-31 22:32:17') is None
    True
    >>> mysql_timestamp_converter('00000000000000') is None
    True

### convert_time(connection, field, obj) | source code
Returns a TIME column as a time object:
    >>> time_or_None('15:06:17')
    datetime.time(15, 6, 17)
Illegal values are returned as None:
    >>> time_or_None('-25:06:17') is None
    True
    >>> time_or_None('random crap') is None
    True
Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but can accept values as (+|-)DD HH:MM:SS. The latter format will not be parsed correctly by this function. Also note that MySQL's TIME column corresponds more closely to Python's timedelta and not time. However if you want TIME columns to be treated as time-of-day and not a time offset, then you can use set this function as the converter for FIELD_TYPE.TIME.

### convert_timedelta(connection, field, obj) | source code
Returns a TIME column as a timedelta object:
    >>> timedelta_or_None('25:06:17')
    datetime.timedelta(1, 3977)
    >>> timedelta_or_None('-25:06:17')
    datetime.timedelta(-2, 83177)
Illegal values are returned as None:
    >>> timedelta_or_None('random crap') is None
    True
Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but can accept values as (+|-)DD HH:MM:SS. The latter format will not be parsed correctly by this function.

Variables Details | [hide private]

  ### ESCAPE_MAP Value:
      {'\x00': '\\0',
       '''
      ''': '\\n',
       '\r': '\\r',
       '\x1a': '\\Z',
       '"': '\\"',
       '\'': '\\\'',
       '\\': '\\\\'}

  ### conversions Value:
      {0: <function convert_decimal at 0xd3ccf8>,
       1: <function convert_int at 0xd3cb90>,
       2: <function convert_int at 0xd3cb90>,
       3: <function convert_long at 0xd3cc08>,
       4: <function convert_float at 0xd3cc80>,
       5: <function convert_float at 0xd3cc80>,
       7: <function convert_mysql_timestamp at 0xd3c9b0>,
       8: <function convert_long at 0xd3cc08>,
      ...

  ### decoders Value:
      {0: <function convert_decimal at 0xd3ccf8>,
       1: <function convert_int at 0xd3cb90>,
       2: <function convert_int at 0xd3cb90>,
       3: <function convert_long at 0xd3cc08>,
       4: <function convert_float at 0xd3cc80>,
       5: <function convert_float at 0xd3cc80>,
       7: <function convert_mysql_timestamp at 0xd3c9b0>,
       8: <function convert_long at 0xd3cc08>,
      ...

  ### encoders Value:
      {<type 'bool'>: <function escape_bool at 0xd3c2a8>,
       <type 'float'>: <function escape_float at 0xd3c398>,
       <type 'int'>: <function escape_object at 0xd3c320>,
       <type 'list'>: <function escape_sequence at 0xd34c80>,
       <type 'long'>: <function escape_object at 0xd3c320>,
       <type 'dict'>: <function escape_dict at 0xd34a28>,
       <type 'NoneType'>: <function escape_None at 0xd3c500>,
       <type 'set'>: <function escape_sequence at 0xd34c80>,
      ...