1. Konrad Rymczak
  2. htsql-firebird


htsql-firebird / src / htsql_pgsql / tweak / inet / dump.py

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

from htsql.core.adapter import adapts
from htsql.core.domain import Domain, IntegerDomain, StringDomain
from htsql.core.tr.dump import DumpByDomain, DumpToDomain
from htsql.tweak.inet.domain import INetDomain

class DumpInet(DumpByDomain):


    def __call__(self):
        self.format("{value:literal}::INET", value=self.value)

class DumpToINet(DumpToDomain):

    adapts(Domain, INetDomain)

    def __call__(self):
        self.format("CAST({base} AS INET)", base=self.base)

class DumpIntegerToINet(DumpToDomain):

    adapts(IntegerDomain, INetDomain)

    def __call__(self):
        self.format("(''::INET + {base})", base=self.base)

class DumpINetToInteger(DumpToDomain):

    adapts(INetDomain, IntegerDomain)

    def __call__(self):
        self.format("({base} - ''::INET)", base=self.base)

class DumpINetToString(DumpToDomain):

    adapts(INetDomain, StringDomain)

    def __call__(self):
        self.format("HOST({base})", base=self.base)