Debian Codegraph @

extension_helpers/tests/py311_backports.py

raw
1 """
2 PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
3 --------------------------------------------
4
5 1. This LICENSE AGREEMENT is between the Python Software Foundation
6 ("PSF"), and the Individual or Organization ("Licensee") accessing and
7 otherwise using this software ("Python") in source or binary form and
8 its associated documentation.
9
10 2. Subject to the terms and conditions of this License Agreement, PSF hereby
11 grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
12 analyze, test, perform and/or display publicly, prepare derivative works,
13 distribute, and otherwise use Python alone or in any derivative version,
14 provided, however, that PSF's License Agreement and PSF's notice of copyright,
15 i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
16 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation;
17 All Rights Reserved" are retained in Python alone or in any derivative version
18 prepared by Licensee.
19
20 3. In the event Licensee prepares a derivative work that is based on
21 or incorporates Python or any part thereof, and wants to make
22 the derivative work available to others as provided herein, then
23 Licensee hereby agrees to include in any such work a brief summary of
24 the changes made to Python.
25
26 4. PSF is making Python available to Licensee on an "AS IS"
27 basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
28 IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
29 DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
30 FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
31 INFRINGE ANY THIRD PARTY RIGHTS.
32
33 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
34 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
35 A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
36 OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
37
38 6. This License Agreement will automatically terminate upon a material
39 breach of its terms and conditions.
40
41 7. Nothing in this License Agreement shall be deemed to create any
42 relationship of agency, partnership, or joint venture between PSF and
43 Licensee. This License Agreement does not grant permission to use PSF
44 trademarks or trade name in a trademark sense to endorse or promote
45 products or services of Licensee, or any third party.
46
47 8. By copying, installing or otherwise using Python, Licensee
48 agrees to be bound by the terms and conditions of this License
49 Agreement.
50 """
51
52 import os
53 from contextlib import AbstractContextManager
54
55
56 # this class is vendored from Python 3.11.0
57 class chdir(AbstractContextManager):
58 """Non thread-safe context manager to change the current working directory."""
59
60 def __init__(self, path):
61 self.path = path
62 self._old_cwd = []
63
64 def __enter__(self):
65 self._old_cwd.append(os.getcwd())
66 os.chdir(self.path)
67
68 def __exit__(self, *excinfo):
69 os.chdir(self._old_cwd.pop())