我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用psycopg2.extras.Inet()。
def test_inet_conform(self): from psycopg2.extras import Inet i = Inet("192.168.1.0/24") a = psycopg2.extensions.adapt(i) a.prepare(self.conn) self.assertEqual( filter_scs(self.conn, b("E'192.168.1.0/24'::inet")), a.getquoted()) # adapts ok with unicode too i = Inet(u"192.168.1.0/24") a = psycopg2.extensions.adapt(i) a.prepare(self.conn) self.assertEqual( filter_scs(self.conn, b("E'192.168.1.0/24'::inet")), a.getquoted())
def test_inet_conform(self): from psycopg2.extras import Inet i = Inet("192.168.1.0/24") a = psycopg2.extensions.adapt(i) a.prepare(self.conn) self.assertEqual( filter_scs(self.conn, b"E'192.168.1.0/24'::inet"), a.getquoted()) # adapts ok with unicode too i = Inet("192.168.1.0/24") a = psycopg2.extensions.adapt(i) a.prepare(self.conn) self.assertEqual( filter_scs(self.conn, b"E'192.168.1.0/24'::inet"), a.getquoted())
def testINET(self): with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) psycopg2.extras.register_inet() i = psycopg2.extras.Inet("192.168.1.0/24") s = self.execute("SELECT %s AS foo", (i,)) self.assertTrue(i.addr == s.addr) # must survive NULL cast to inet s = self.execute("SELECT NULL::inet AS foo") self.assertTrue(s is None)
def testINETARRAY(self): with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) psycopg2.extras.register_inet() i = psycopg2.extras.Inet("192.168.1.0/24") s = self.execute("SELECT %s AS foo", ([i],)) self.assertTrue(i.addr == s[0].addr) # must survive NULL cast to inet s = self.execute("SELECT NULL::inet[] AS foo") self.assertTrue(s is None)
def test_inet_conform(self): from psycopg2.extras import Inet i = Inet("192.168.1.0/24") a = psycopg2.extensions.adapt(i) a.prepare(self.conn) self.assertQuotedEqual(a.getquoted(), b"'192.168.1.0/24'::inet") # adapts ok with unicode too i = Inet("192.168.1.0/24") a = psycopg2.extensions.adapt(i) a.prepare(self.conn) self.assertQuotedEqual(a.getquoted(), b"'192.168.1.0/24'::inet")
def testINET(self): with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) psycopg2.extras.register_inet() i = psycopg2.extras.Inet("192.168.1.0/24") s = self.execute("SELECT %s AS foo", (i,)) self.failUnless(i.addr == s.addr) # must survive NULL cast to inet s = self.execute("SELECT NULL::inet AS foo") self.failUnless(s is None)
def testINETARRAY(self): with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) psycopg2.extras.register_inet() i = psycopg2.extras.Inet("192.168.1.0/24") s = self.execute("SELECT %s AS foo", ([i],)) self.failUnless(i.addr == s[0].addr) # must survive NULL cast to inet s = self.execute("SELECT NULL::inet[] AS foo") self.failUnless(s is None)
def adapt_ipaddressfield_value(self, value): if value: return Inet(value) return None
def testINET(self): psycopg2.extras.register_inet() i = psycopg2.extras.Inet("192.168.1.0/24") s = self.execute("SELECT %s AS foo", (i,)) self.failUnless(i.addr == s.addr) # must survive NULL cast to inet s = self.execute("SELECT NULL::inet AS foo") self.failUnless(s is None)
def testINETARRAY(self): psycopg2.extras.register_inet() i = psycopg2.extras.Inet("192.168.1.0/24") s = self.execute("SELECT %s AS foo", ([i],)) self.failUnless(i.addr == s[0].addr) # must survive NULL cast to inet s = self.execute("SELECT NULL::inet[] AS foo") self.failUnless(s is None)
def value_to_db_ipaddress(self, value): if value: return Inet(value) return None
def test_inet_conform(self): from psycopg2.extras import Inet i = Inet("192.168.1.0/24") a = psycopg2.extensions.adapt(i) a.prepare(self.conn) self.assertQuotedEqual(a.getquoted(), b"'192.168.1.0/24'::inet") # adapts ok with unicode too i = Inet(u"192.168.1.0/24") a = psycopg2.extensions.adapt(i) a.prepare(self.conn) self.assertQuotedEqual(a.getquoted(), b"'192.168.1.0/24'::inet")
def testINET(self): psycopg2.extras.register_inet() i = psycopg2.extras.Inet("192.168.1.0/24") s = self.execute("SELECT %s AS foo", (i,)) self.assertTrue(i.addr == s.addr) # must survive NULL cast to inet s = self.execute("SELECT NULL::inet AS foo") self.assertTrue(s is None)
def testINETARRAY(self): psycopg2.extras.register_inet() i = psycopg2.extras.Inet("192.168.1.0/24") s = self.execute("SELECT %s AS foo", ([i],)) self.assertTrue(i.addr == s[0].addr) # must survive NULL cast to inet s = self.execute("SELECT NULL::inet[] AS foo") self.assertTrue(s is None)