Skip to content

Commit

Permalink
Dropped python 3.5 and below.
Browse files Browse the repository at this point in the history
  • Loading branch information
akornatskyy committed Nov 7, 2020
1 parent db1e571 commit 45505a7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 78 deletions.
44 changes: 0 additions & 44 deletions src/wheezy/html/boost.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@

#include <Python.h>

#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
#endif

#if PY_VERSION_HEX < 0x02060000
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#endif

static PyObject*
escape_html_unicode(PyUnicodeObject *s)
{
Expand Down Expand Up @@ -86,23 +78,15 @@ escape_html_unicode(PyUnicodeObject *s)
static PyObject*
escape_html_string(PyObject *s)
{
#if PY_MAJOR_VERSION < 3
const Py_ssize_t s_size = PyString_GET_SIZE(s);
#else
const Py_ssize_t s_size = PyBytes_GET_SIZE(s);
#endif
if (s_size == 0)
{
Py_INCREF(s);
return (PyObject*)s;
}

Py_ssize_t count = 0;
#if PY_MAJOR_VERSION < 3
char *start = PyString_AS_STRING(s);
#else
char *start = PyBytes_AS_STRING(s);
#endif
const char *end = start + s_size;
char *p = start;
while(p < end)
Expand All @@ -127,22 +111,14 @@ escape_html_string(PyObject *s)
return (PyObject*)s;
}

#if PY_MAJOR_VERSION < 3
PyObject *result = PyString_FromStringAndSize(NULL, s_size + count);
#else
PyObject *result = PyBytes_FromStringAndSize(NULL, s_size + count);
#endif
if (! result)
{
return NULL;
}

p = start;
#if PY_MAJOR_VERSION < 3
char *r = PyString_AS_STRING(result);
#else
char *r = PyBytes_AS_STRING(result);
#endif
while(p < end)
{
char ch = *p++;
Expand Down Expand Up @@ -186,21 +162,13 @@ escape_html(PyObject *self, PyObject *args)
return escape_html_unicode((PyUnicodeObject*)s);
}

#if PY_MAJOR_VERSION < 3
if (PyString_CheckExact(s))
#else
if (PyBytes_CheckExact(s))
#endif
{
return escape_html_string(s);
}

if (s == Py_None) {
#if PY_MAJOR_VERSION < 3
return PyString_FromStringAndSize(NULL, 0);
#else
return PyUnicode_FromStringAndSize(NULL, 0);
#endif
}

PyErr_Format(PyExc_TypeError,
Expand All @@ -217,16 +185,6 @@ static PyMethodDef module_methods[] = {
};


#if PY_MAJOR_VERSION < 3

PyMODINIT_FUNC
initboost(void)
{
Py_InitModule("wheezy.html.boost", module_methods);
}

#else

static struct PyModuleDef module_definition = {
PyModuleDef_HEAD_INIT,
"wheezy.html.boost",
Expand All @@ -240,5 +198,3 @@ PyInit_boost(void)
{
return PyModule_Create(&module_definition);
}

#endif
26 changes: 0 additions & 26 deletions src/wheezy/html/comp.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/wheezy/html/ext/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import re

from wheezy.html.comp import xrange
from wheezy.html.ext.lexer import (
InlinePreprocessor,
Preprocessor,
Expand Down Expand Up @@ -133,7 +132,7 @@ class WidgetExtension(object):


def whitespace_postprocessor(tokens):
for i in xrange(len(tokens)):
for i in range(len(tokens)):
lineno, token, value = tokens[i]
if token == "markup":
value = whitespace_preprocessor(value)
Expand Down
10 changes: 4 additions & 6 deletions src/wheezy/html/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from datetime import date, datetime

from wheezy.html.comp import str_type


def escape_html(s):
"""Escapes a string so it is valid within HTML. Converts `None`
Expand Down Expand Up @@ -66,7 +64,7 @@ def my_formatter(value, format_spec):
>>> format_value([])
()
If format provider is unknown apply str_type.
If format provider is unknown apply str.
>>> str(format_value({}))
'{}'
Expand All @@ -87,12 +85,12 @@ def my_formatter(value, format_spec):
if formatter_name in format_providers:
format_provider = format_providers[formatter_name]
else:
return str_type(value)
return str(value)
return format_provider(value, format_spec)


def str_format_provider(value, format_spec):
return str_type(value)
return str(value)


min_date = date(1900, 1, 1)
Expand Down Expand Up @@ -138,7 +136,7 @@ def datetime_format_provider(value, format_spec=None):


format_providers = {
"str": lambda value, format_spec: html_escape(str_type(value)),
"str": lambda value, format_spec: html_escape(str(value)),
"unicode": lambda value, format_spec: html_escape(value),
"int": str_format_provider,
"Decimal": str_format_provider,
Expand Down

0 comments on commit 45505a7

Please sign in to comment.