Skip to content

Commit

Permalink
Standalone pathlib._abc.
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 23, 2023
1 parent 9c3ddf3 commit c4961ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 7 additions & 6 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
import io
import ntpath
import posixpath
ntpath = object()
from . import _posixpath as posixpath
import sys
import warnings
from _collections_abc import Sequence
Expand Down Expand Up @@ -41,7 +41,7 @@ def _ignore_error(exception):
getattr(exception, 'winerror', None) in _IGNORED_WINERRORS)


@functools.cache
@functools.lru_cache(maxsize=256)
def _is_case_sensitive(pathmod):
return pathmod.normcase('Aa') == 'Aa'

Expand All @@ -58,13 +58,14 @@ def _compile_pattern(pat, sep, case_sensitive):
sensitivity)."""
global re, glob
if re is None:
import re, glob
import re
from . import _glob as glob

flags = re.NOFLAG if case_sensitive else re.IGNORECASE
flags = 0 if case_sensitive else re.IGNORECASE
regex = glob.translate(pat, recursive=True, include_hidden=True, seps=sep)
# The string representation of an empty path is a single dot ('.'). Empty
# paths shouldn't match wildcards, so we consume it with an atomic group.
regex = r'(\.\Z)?+' + regex
regex = r'(?=(?P<empty>\.\Z|))(?P=empty)' + regex
return re.compile(regex, flags=flags).match


Expand Down
13 changes: 9 additions & 4 deletions Lib/test/test_pathlib/test_pathlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
import stat
import unittest

from pathlib._abc import UnsupportedOperation, PurePathBase, PathBase
import posixpath
from pathlib_abc import UnsupportedOperation, PurePathBase, PathBase
from pathlib_abc import _posixpath as posixpath
import contextlib

from test.support import set_recursion_limit
from test.support.os_helper import TESTFN

@contextlib.contextmanager
def set_recursion_limit(limit):
yield

TESTFN = "TESTFN"


class UnsupportedOperationTest(unittest.TestCase):
Expand Down

0 comments on commit c4961ff

Please sign in to comment.