diff --git a/django/contrib/gis/geos/prototypes/errcheck.py b/django/contrib/gis/geos/prototypes/errcheck.py index e868891319..eb24ef2ecd 100644 --- a/django/contrib/gis/geos/prototypes/errcheck.py +++ b/django/contrib/gis/geos/prototypes/errcheck.py @@ -43,10 +43,9 @@ def check_minus_one(result, func, cargs): def check_predicate(result, func, cargs): "Error checking for unary/binary predicate functions." - val = ord(result) # getting the ordinal from the character - if val == 1: + if result == 1: return True - elif val == 0: + elif result == 0: return False else: raise GEOSException('Error encountered on GEOS C predicate function "%s".' % func.__name__) diff --git a/django/contrib/gis/geos/prototypes/io.py b/django/contrib/gis/geos/prototypes/io.py index 0c0946c7d8..5f0e945d81 100644 --- a/django/contrib/gis/geos/prototypes/io.py +++ b/django/contrib/gis/geos/prototypes/io.py @@ -1,5 +1,5 @@ import threading -from ctypes import POINTER, Structure, byref, c_char, c_char_p, c_int, c_size_t +from ctypes import POINTER, Structure, byref, c_byte, c_char_p, c_int, c_size_t from django.contrib.gis.geos.base import GEOSBase from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOSFuncFactory @@ -54,7 +54,7 @@ wkt_writer_set_outdim = GEOSFuncFactory( 'GEOSWKTWriter_setOutputDimension', argtypes=[WKT_WRITE_PTR, c_int] ) -wkt_writer_set_trim = GEOSFuncFactory('GEOSWKTWriter_setTrim', argtypes=[WKT_WRITE_PTR, c_char]) +wkt_writer_set_trim = GEOSFuncFactory('GEOSWKTWriter_setTrim', argtypes=[WKT_WRITE_PTR, c_byte]) wkt_writer_set_precision = GEOSFuncFactory('GEOSWKTWriter_setRoundingPrecision', argtypes=[WKT_WRITE_PTR, c_int]) # WKBReader routines @@ -106,8 +106,8 @@ wkb_writer_get_byteorder = WKBWriterGet('GEOSWKBWriter_getByteOrder') wkb_writer_set_byteorder = WKBWriterSet('GEOSWKBWriter_setByteOrder') wkb_writer_get_outdim = WKBWriterGet('GEOSWKBWriter_getOutputDimension') wkb_writer_set_outdim = WKBWriterSet('GEOSWKBWriter_setOutputDimension') -wkb_writer_get_include_srid = WKBWriterGet('GEOSWKBWriter_getIncludeSRID', restype=c_char) -wkb_writer_set_include_srid = WKBWriterSet('GEOSWKBWriter_setIncludeSRID', argtypes=[WKB_WRITE_PTR, c_char]) +wkb_writer_get_include_srid = WKBWriterGet('GEOSWKBWriter_getIncludeSRID', restype=c_byte) +wkb_writer_set_include_srid = WKBWriterSet('GEOSWKBWriter_setIncludeSRID', argtypes=[WKB_WRITE_PTR, c_byte]) # ### Base I/O Class ### @@ -194,7 +194,7 @@ class WKTWriter(IOBase): def trim(self, flag): if bool(flag) != self._trim: self._trim = bool(flag) - wkt_writer_set_trim(self.ptr, b'\x01' if flag else b'\x00') + wkt_writer_set_trim(self.ptr, self._trim) @property def precision(self): @@ -277,15 +277,11 @@ class WKBWriter(IOBase): # Property for getting/setting the include srid flag. @property def srid(self): - return bool(ord(wkb_writer_get_include_srid(self.ptr))) + return bool(wkb_writer_get_include_srid(self.ptr)) @srid.setter def srid(self, include): - if include: - flag = b'\x01' - else: - flag = b'\x00' - wkb_writer_set_include_srid(self.ptr, flag) + wkb_writer_set_include_srid(self.ptr, bool(include)) # `ThreadLocalIO` object holds instances of the WKT and WKB reader/writer diff --git a/django/contrib/gis/geos/prototypes/predicates.py b/django/contrib/gis/geos/prototypes/predicates.py index 9021fc71f3..d4681c1689 100644 --- a/django/contrib/gis/geos/prototypes/predicates.py +++ b/django/contrib/gis/geos/prototypes/predicates.py @@ -2,7 +2,7 @@ This module houses the GEOS ctypes prototype functions for the unary and binary predicate operations on geometries. """ -from ctypes import c_char, c_char_p, c_double +from ctypes import c_byte, c_char_p, c_double from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOSFuncFactory from django.contrib.gis.geos.prototypes.errcheck import check_predicate @@ -12,7 +12,7 @@ from django.contrib.gis.geos.prototypes.errcheck import check_predicate class UnaryPredicate(GEOSFuncFactory): "For GEOS unary predicate functions." argtypes = [GEOM_PTR] - restype = c_char + restype = c_byte errcheck = staticmethod(check_predicate) diff --git a/django/contrib/gis/geos/prototypes/prepared.py b/django/contrib/gis/geos/prototypes/prepared.py index 69715c0f99..52c31563d8 100644 --- a/django/contrib/gis/geos/prototypes/prepared.py +++ b/django/contrib/gis/geos/prototypes/prepared.py @@ -1,4 +1,4 @@ -from ctypes import c_char +from ctypes import c_byte from django.contrib.gis.geos.libgeos import ( GEOM_PTR, PREPGEOM_PTR, GEOSFuncFactory, @@ -13,7 +13,7 @@ prepared_destroy = GEOSFuncFactory('GEOSPreparedGeom_destroy', argtypes=[PREPGEO # Prepared geometry binary predicate support. class PreparedPredicate(GEOSFuncFactory): argtypes = [PREPGEOM_PTR, GEOM_PTR] - restype = c_char + restype = c_byte errcheck = staticmethod(check_predicate)