2222This module contains utilities that have been optimized in Cython
2323"""
2424
25- from cpython.pystate cimport PyThreadState_SetAsyncExc
26- from cpython.ref cimport PyObject
25+ import cython # pylint: disable=import-error
26+ from cython .cimports .cpython .pystate import PyThreadState_SetAsyncExc # pylint: disable=import-error
27+ from cython .cimports .cpython .ref import PyObject # pylint: disable=import-error
2728from ._signals import TerminateException
2829
2930
30- def url_directory_name (str url ):
31+ def url_directory_name (url : str ):
3132 """Normalizes a url into a directory name
3233
3334 Args:
@@ -36,8 +37,7 @@ def url_directory_name(str url):
3637 Returns:
3738 A string which can be used as a directory name
3839 """
39- return ' ' .join([_transl(x) for x in url])
40-
40+ return "" .join ([_transl (x ) for x in url ])
4141
4242
4343# terminate_thread()
@@ -47,8 +47,8 @@ def url_directory_name(str url):
4747# Args:
4848# thread_id (int): the thread id in which to throw the exception
4949#
50- def terminate_thread (long thread_id ):
51- res = PyThreadState_SetAsyncExc(thread_id, < PyObject* > TerminateException)
50+ def terminate_thread (thread_id : cython . long ):
51+ res = PyThreadState_SetAsyncExc (thread_id , cython . cast ( cython . pointer ( PyObject ), TerminateException ) )
5252 assert res == 1
5353
5454
@@ -60,9 +60,9 @@ def terminate_thread(long thread_id):
6060# Returns:
6161# (bool): True if all characters are valid, False otherwise.
6262#
63- def valid_chars_name (str name ):
64- cdef int char_value
65- cdef int forbidden_char
63+ def valid_chars_name (name : str ):
64+ char_value : cython . int
65+ forbidden_char : cython . int
6666
6767 for char_value in name :
6868 # 0-31 are control chars, 127 is DEL, and >127 means non-ASCII
@@ -96,7 +96,8 @@ def valid_chars_name(str name):
9696#
9797# This transforms the value to "_" if is it not a ascii letter, a digit or "%" or "_"
9898#
99- cdef Py_UNICODE _transl(Py_UNICODE x):
99+ @cython .cfunc
100+ def _transl (x : cython .Py_UNICODE ) -> cython .Py_UNICODE :
100101 if ("a" <= x <= "z" ) or ("A" <= x <= "Z" ) or ("0" <= x <= "9" ) or x == "%" :
101102 return x
102103 return "_"
0 commit comments