Skip to content

Commit

Permalink
use new smart_str method instead of smart_text
Browse files Browse the repository at this point in the history
  • Loading branch information
baloola committed Jul 20, 2022
1 parent 513a1e6 commit 080f328
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from eoxserver.services.ows.wps.parameters import (
ComplexData, CDObject, CDTextBuffer, FormatText, FormatXML, FormatJSON,
)
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str

class TestProcess02(Component):
""" Test identity process (the outputs are copies of the inputs)
Expand Down Expand Up @@ -117,7 +117,7 @@ def execute(input00, output00, **kwarg):
filename=(output_filename_base + ".xml")
)
# text output also accepts Unicode strings
outputs['output01'] = smart_text(
outputs['output01'] = smart_str(
etree.tostring(
input00.data, encoding='utf-8', pretty_print=True
), 'utf-8'
Expand Down
10 changes: 5 additions & 5 deletions eoxserver/services/ows/wps/parameters/complexdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from lxml import etree
from .base import Parameter
from .formats import Format
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from django.utils.six import string_types, text_type, itervalues, binary_type

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -172,7 +172,7 @@ class CDTextBuffer(StringIO, CDBase):
"""
def __init__(self, data=u'', *args, **kwargs):
# NOTE: StringIO is an old-style class and super cannot be used!
StringIO.__init__(self, smart_text(data))
StringIO.__init__(self, smart_str(data))
CDBase.__init__(self, *args, **kwargs)
self.text_encoding = kwargs.get('text_encoding', None)

Expand All @@ -183,9 +183,9 @@ def data(self):

def write(self, data):
if self.text_encoding is None:
return StringIO.write(self, smart_text(data))
return StringIO.write(self, smart_str(data))
else:
return StringIO.write(self, smart_text(data, self.text_encoding))
return StringIO.write(self, smart_str(data, self.text_encoding))

def read(self, size=None):
if size is None:
Expand Down Expand Up @@ -532,7 +532,7 @@ def _unicode(data, encoding):
if isinstance(data, text_type):
return data
elif isinstance(data, bytes):
return smart_text(data, encoding)
return smart_str(data, encoding)
raise TypeError(
"Byte or Unicode string expected, %s received!" % type(data)
)
4 changes: 2 additions & 2 deletions eoxserver/services/ows/wps/parameters/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
asURL, fromURL, fromURN, fromShortCode, validateEPSGCode, parseEPSGCode,
)
from .data_types import BaseType
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str


class CRSType(BaseType):
Expand Down Expand Up @@ -66,7 +66,7 @@ def encode(cls, value):
if value == 0:
return u'ImageCRS'
elif validateEPSGCode(value):
return smart_text(asURL(value))
return smart_str(asURL(value))
raise ValueError("Invalid CRS %r!" % value)

@classmethod
Expand Down
20 changes: 10 additions & 10 deletions eoxserver/services/ows/wps/parameters/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from datetime import datetime, date, time, timedelta
from django.utils.dateparse import parse_date, parse_datetime, parse_time, utc
from django.utils.six import PY2, PY3, string_types
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from eoxserver.core.util.timetools import parse_duration

try:
Expand Down Expand Up @@ -68,7 +68,7 @@ def parse(cls, raw_value):
@classmethod
def encode(cls, value):
""" Encode value to a Unicode string."""
return smart_text(value)
return smart_str(value)

@classmethod
def get_diff_dtype(cls): # difference type - change if differs from the base
Expand Down Expand Up @@ -97,7 +97,7 @@ class Boolean(BaseType):
def parse(cls, raw_value):

if isinstance(raw_value, string_types):
raw_value = smart_text(raw_value.lower())
raw_value = smart_str(raw_value.lower())
if raw_value in ('1', 'true'):
return True
elif raw_value in ('0', 'false'):
Expand Down Expand Up @@ -130,7 +130,7 @@ class Integer(BaseType):
@classmethod
def encode(cls, value):
""" Encode value to a Unicode string."""
return smart_text(int(value))
return smart_str(int(value))

@classmethod
def as_number(cls, value):
Expand Down Expand Up @@ -176,9 +176,9 @@ class String(BaseType):
def encode(cls, value):
""" Encode value to a Unicode string."""
try:
return smart_text(value)
return smart_str(value)
except UnicodeDecodeError:
return smart_text(value, cls.encoding)
return smart_str(value, cls.encoding)

@classmethod
def parse(cls, raw_value):
Expand Down Expand Up @@ -228,7 +228,7 @@ def encode(cls, value):
elif seconds != 0:
items.append('%dS' % seconds)

return smart_text("".join(items))
return smart_str("".join(items))

@classmethod
def as_number(cls, value):
Expand Down Expand Up @@ -261,7 +261,7 @@ def parse(cls, raw_value):
@classmethod
def encode(cls, value):
if isinstance(value, cls.dtype):
return smart_text(value.isoformat())
return smart_str(value.isoformat())
raise ValueError("Invalid value type '%s'!" % type(value))

@classmethod
Expand Down Expand Up @@ -292,7 +292,7 @@ def parse(cls, raw_value):
@classmethod
def encode(cls, value):
if isinstance(value, cls.dtype):
return smart_text(value.isoformat())
return smart_str(value.isoformat())
raise ValueError("Invalid value type '%s'!" % type(value))

@classmethod
Expand Down Expand Up @@ -329,7 +329,7 @@ def parse(cls, raw_value):
@classmethod
def encode(cls, value):
if isinstance(value, cls.dtype):
return smart_text(cls._isoformat(value))
return smart_str(cls._isoformat(value))
raise ValueError("Invalid value type '%s'!" % type(value))

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions eoxserver/services/ows/wps/parameters/literaldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from .data_types import BaseType, String, DTYPES
from .allowed_values import BaseAllowed, AllowedAny, AllowedEnum
from .units import UnitOfMeasure, UnitLinear
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from django.utils.six import text_type


Expand Down Expand Up @@ -195,9 +195,9 @@ def parse(self, raw_value, uom=None, encoding="utf-8"):
if isinstance(raw_value, text_type):
_value = raw_value
elif isinstance(raw_value, str):
_value = smart_text(raw_value, encoding)
_value = smart_str(raw_value, encoding)
else:
_value = smart_text(raw_value)
_value = smart_str(raw_value)
_value = self._dtype.parse(raw_value)
_value = self.strip_uom(_value, uom or self.default_uom)
_value = self._allowed_values.verify(_value)
Expand Down
Loading

0 comments on commit 080f328

Please sign in to comment.