Skip to content

Commit

Permalink
Trying Python 3.12 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Jun 27, 2024
1 parent 452ea24 commit d060e12
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
8 changes: 4 additions & 4 deletions snovault/embed.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from copy import deepcopy
from posixpath import join
from pyramid.compat import (
native_,
unquote_bytes_to_wsgi,
)
from pyramid.httpexceptions import HTTPNotFound, HTTPServerError
import pyramid.request
from .crud_views import collection_add as sno_collection_add
from .interfaces import COLLECTIONS, CONNECTION
from .pyramid_compat import (
native_,
unquote_bytes_to_wsgi,
)
from .resources import Collection
from .schema_utils import validate_request
from dcicutils.misc_utils import check_true
Expand Down
23 changes: 23 additions & 0 deletions snovault/pyramid_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Not that pyramid.compat disappeared with pyramid 2.0.02 (during move to Python 3.12).

from urllib.parse import unquote_to_bytes

text_type = str


def ascii_native_(s):
if isinstance(s, text_type):
s = s.encode('ascii')
return str(s, 'ascii', 'strict')


def native_(s, encoding='latin-1', errors='strict'):
""" If ``s`` is an instance of ``text_type``, return
``s``, otherwise return ``str(s, encoding, errors)``"""
if isinstance(s, text_type):
return s
return str(s, encoding, errors)


def unquote_bytes_to_wsgi(bytestring):
return unquote_to_bytes(bytestring).decode('latin-1')
8 changes: 1 addition & 7 deletions snovault/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from base64 import b64encode
from jsonschema import Draft202012Validator
# from pyramid.compat import ascii_native_
from uuid import uuid4

from ..interfaces import TYPES
from ..pyramid_compat import ascii_native_
from ..util import mappings_use_nested

from .testing_views import (
Expand All @@ -19,12 +19,6 @@

TYPE_NAMES = ['TestingPostPutPatchSno', 'TestingDownload']

# pyramid.compat disappeared with pyramid 2.0.02 (during move to Python 3.12).
def ascii_native_(s):
if isinstance(s, str):
s = s.encode('ascii')
return str(s, 'ascii', 'strict')


def get_parameterized_names():
""" Get all item types from schema names """
Expand Down

0 comments on commit d060e12

Please sign in to comment.