• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python psycopg2.Binary类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python errorcodes.lookup函数代码示例发布时间:2022-05-25
下一篇:
Python psycopg2.connect函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap