htsql-firebird / src / htsql / core / tr /

# Copyright (c) 2006-2012, Prometheus Research, LLC
# See `LICENSE` for license information, `AUTHORS` for the list of authors.

from ..adapter import Adapter, adapts, adapts_many
from ..domain import (UntypedDomain, BooleanDomain, IntegerDomain, FloatDomain,
                      DecimalDomain, DateDomain, TimeDomain, DateTimeDomain)
from .binding import LiteralRecipe, SelectionRecipe
import types
import datetime
import decimal

class Embed(Adapter):


    def __init__(self, value):
        self.value = value

    def __call__(self):
        raise ValueError("unable to embed a value of type %s"
                         % type(self.value))

class EmbedUntyped(Embed):

    adapts_many(str, unicode)

    def __call__(self):
        value = self.value
        if isinstance(value, str):
                value = value.decode('utf-8')
            except UnicodeDecodeError:
                raise ValueError("a string is expected to be encoded in UTF-8:"
                                 " %s" % repr(value))
        if u"\0" in value:
            raise ValueError("a string should not contain a NIL character:"
                             " %s" % repr(value))
        return LiteralRecipe(value, UntypedDomain())

class EmbedNull(Embed):


    def __call__(self):
        return LiteralRecipe(None, UntypedDomain())

class EmbedBoolean(Embed):


    def __call__(self):
        return LiteralRecipe(self.value, BooleanDomain())

class EmbedInteger(Embed):

    adapts_many(int, long)

    def __call__(self):
        return LiteralRecipe(self.value, IntegerDomain())

class EmbedFloat(Embed):


    def __call__(self):
        return LiteralRecipe(self.value, FloatDomain())

class EmbedDecimal(Embed):


    def __call__(self):
        return LiteralRecipe(self.value, DecimalDomain())

class EmbedDate(Embed):


    def __call__(self):
        return LiteralRecipe(self.value, DateDomain())

class EmbedTime(Embed):


    def __call__(self):
        return LiteralRecipe(self.value, TimeDomain())

class EmbedDateTime(Embed):


    def __call__(self):
        return LiteralRecipe(self.value, DateTimeDomain())

class EmbedList(Embed):

    adapts_many(list, tuple)

    def __call__(self):
        recipes = []
        for value in self.value:
            recipe = embed(value)
        return SelectionRecipe(recipes)

def embed(value):
    embed = Embed(value)
    return embed()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.