當前位置: 首頁>>代碼示例>>Python>>正文


Python psycopg2.Binary類代碼示例

本文整理匯總了Python中psycopg2.Binary的典型用法代碼示例。如果您正苦於以下問題:Python Binary類的具體用法?Python Binary怎麽用?Python Binary使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Binary類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: PostGISAdapter

class PostGISAdapter(object):
    def __init__(self, geom):
        "Initializes on the geometry."
        # Getting the WKB (in string form, to allow easy pickling of
        # the adaptor) and the SRID from the geometry.
        self.ewkb = bytes(geom.ewkb)
        self.srid = geom.srid
        self._adapter = Binary(self.ewkb)

    def __conform__(self, proto):
        # Does the given protocol conform to what Psycopg2 expects?
        if proto == ISQLQuote:
            return self
        else:
            raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?')

    def __eq__(self, other):
        if not isinstance(other, PostGISAdapter):
            return False
        return (self.ewkb == other.ewkb) and (self.srid == other.srid)

    def __str__(self):
        return self.getquoted()

    def prepare(self, conn):
        """
        This method allows escaping the binary in the style required by the
        server's `standard_conforming_string` setting.
        """
        self._adapter.prepare(conn)

    def getquoted(self):
        "Returns a properly quoted string for use in PostgreSQL/PostGIS."
        # psycopg will figure out whether to use E'\\000' or '\000'
        return str('ST_GeomFromEWKB(%s)' % self._adapter.getquoted().decode())
開發者ID:AndrewBloody,項目名稱:django,代碼行數:35,代碼來源:adapter.py

示例2: PostGISAdapter

class PostGISAdapter(object):
    def __init__(self, obj, geography=False):
        """
        Initialize on the spatial object.
        """
        self.is_geometry = isinstance(obj, (Geometry, PostGISAdapter))

        # Getting the WKB (in string form, to allow easy pickling of
        # the adaptor) and the SRID from the geometry or raster.
        if self.is_geometry:
            self.ewkb = bytes(obj.ewkb)
            self._adapter = Binary(self.ewkb)
        else:
            self.ewkb = to_pgraster(obj)

        self.srid = obj.srid
        self.geography = geography

    def __conform__(self, proto):
        # Does the given protocol conform to what Psycopg2 expects?
        if proto == ISQLQuote:
            return self
        else:
            raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?')

    def __eq__(self, other):
        if not isinstance(other, PostGISAdapter):
            return False
        return (self.ewkb == other.ewkb) and (self.srid == other.srid)

    def __hash__(self):
        return hash((self.ewkb, self.srid))

    def __str__(self):
        return self.getquoted()

    def prepare(self, conn):
        """
        This method allows escaping the binary in the style required by the
        server's `standard_conforming_string` setting.
        """
        if self.is_geometry:
            self._adapter.prepare(conn)

    def getquoted(self):
        """
        Return a properly quoted string for use in PostgreSQL/PostGIS.
        """
        if self.is_geometry:
            # Psycopg will figure out whether to use E'\\000' or '\000'.
            return str('%s(%s)' % (
                'ST_GeogFromWKB' if self.geography else 'ST_GeomFromEWKB',
                self._adapter.getquoted().decode())
            )
        else:
            # For rasters, add explicit type cast to WKB string.
            return "'%s'::raster" % self.ewkb
開發者ID:atlassian,項目名稱:django,代碼行數:57,代碼來源:adapter.py

示例3: get_db_prep_value

 def get_db_prep_value(self, value, connection, prepared=False):
     value = value if prepared else self.get_prep_value(value)
     if isinstance(value, unicode):
         value = Binary(value.encode("utf-8"))
     elif isinstance(value, str):
         value = Binary(value)
     elif isinstance(value, Binary):
         value = value
     else:
         raise ValueError("only str, unicode and bytea permited")
     return value
開發者ID:kenbolton,項目名稱:django-orm,代碼行數:11,代碼來源:bytea.py

示例4: get_db_prep_value

 def get_db_prep_value(self, value, connection, prepared=False):
     value = value if prepared else self.get_prep_value(value)
     if isinstance(value, unicode):
         value = Binary(value.encode('utf-8'))
     elif isinstance(value, str):
         value = Binary(value)
     elif isinstance(value, (psycopg_binary_class, types.NoneType)):
         value = value
     else:
         raise ValueError("Only str, unicode and bytea permited")
     return value
開發者ID:mattiaslinnap,項目名稱:pyshortcuts,代碼行數:11,代碼來源:fields.py

示例5: get_db_prep_value

 def get_db_prep_value(self, value, connection, prepared=False):
     value = value if prepared else self.get_prep_value(value)
     if isinstance(value, six.text_type):
         value = Binary(value.encode('utf-8'))
     elif isinstance(value, six.binary_type):
         value = Binary(value)
     elif isinstance(value, psycopg_binary_class) or value is None:
         value = value
     else:
         raise ValueError("only str and bytes permited")
     return value
開發者ID:kcphysics,項目名稱:djorm-ext-pgbytea,代碼行數:11,代碼來源:bytea.py

示例6: PatchedAdapter

class PatchedAdapter(PostGISAdapter):
    def __init__(self, *args, **kwargs):
        super(PatchedAdapter, self).__init__(*args, **kwargs)
        self._adapter = Binary(self.ewkb) 

    def prepare(self, conn):
        # Pass the connection to the adapter: this allows escaping the binary
        # in the style required by the server's standard_conforming_string setting.
        self._adapter.prepare(conn)

    def getquoted(self):
        "Returns a properly quoted string for use in PostgreSQL/PostGIS."
        # psycopg will figure out whether to use E'\\000' or '\000'
        return 'ST_GeomFromEWKB(%s)' % self._adapter.getquoted()
開發者ID:matthewwithanm,項目名稱:django-scspostgis,代碼行數:14,代碼來源:adapter.py

示例7: __init__

 def __init__(self, geom):
     "Initializes on the geometry."
     # Getting the WKB (in string form, to allow easy pickling of
     # the adaptor) and the SRID from the geometry.
     self.ewkb = bytes(geom.ewkb)
     self.srid = geom.srid
     self._adapter = Binary(self.ewkb)
開發者ID:percious,項目名稱:django,代碼行數:7,代碼來源:adapter.py

示例8: PostGISAdapter

class PostGISAdapter(object):
    def __init__(self, geom):
        "Initializes on the geometry."
        # Getting the WKB (in string form, to allow easy pickling of
        # the adaptor) and the SRID from the geometry.
        self.ewkb = str(geom.ewkb)
        self.srid = geom.srid
        self._adapter = Binary(self.ewkb)

    def __conform__(self, proto):
        # Does the given protocol conform to what Psycopg2 expects?
        if proto == ISQLQuote:
            return self
        else:
            m = 'Error implementing psycopg2 protocol. Is psycopg2 installed?'
            raise Exception(m)

    def __eq__(self, other):
        return (self.ewkb == other.ewkb) and (self.srid == other.srid)

    def __str__(self):
        return self.getquoted()

    def prepare(self, conn):
        # Pass the connection to the adapter: this allows escaping the binary
        # in the style required by the server's
        # standard_conforming_string setting
        self._adapter.prepare(conn)

    def getquoted(self):
        "Returns a properly quoted string for use in PostgreSQL/PostGIS."
        # psycopg will figure out whether to use E'\\000' or '\000'
        return 'ST_GeomFromEWKB(%s)' % self._adapter.getquoted()

    def prepare_database_save(self, unused):
        return self
開發者ID:ccnmtl,項目名稱:blackrock,代碼行數:36,代碼來源:adapter.py

示例9: __init__

    def __init__(self, obj, geography=False):
        """
        Initialize on the spatial object.
        """
        self.is_geometry = isinstance(obj, (Geometry, PostGISAdapter))

        # Getting the WKB (in string form, to allow easy pickling of
        # the adaptor) and the SRID from the geometry or raster.
        if self.is_geometry:
            self.ewkb = bytes(obj.ewkb)
            self._adapter = Binary(self.ewkb)
        else:
            self.ewkb = to_pgraster(obj)

        self.srid = obj.srid
        self.geography = geography
開發者ID:atlassian,項目名稱:django,代碼行數:16,代碼來源:adapter.py

示例10: __init__

 def __init__(self, *args, **kwargs):
     super(PatchedAdapter, self).__init__(*args, **kwargs)
     self._adapter = Binary(self.ewkb) 
開發者ID:matthewwithanm,項目名稱:django-scspostgis,代碼行數:3,代碼來源:adapter.py


注:本文中的psycopg2.Binary類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。