-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadafruit_fakerequests.py
50 lines (35 loc) · 1.29 KB
/
adafruit_fakerequests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2020 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`adafruit_fakerequests`
================================================================================
Fake Network Requests helper that retrieves data from a local file.
* Author(s): Melissa LeBlanc-Williams
Implementation Notes
--------------------
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""
import json
try:
from typing import Any
except ImportError:
pass
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FakeRequests.git"
class Fake_Requests:
"""For faking 'requests' using a local file instead of the network."""
def __init__(self, filename: str) -> None:
self._filename = filename
def json(self) -> Any:
"""json parsed version for local requests."""
with open(self._filename, "r") as file:
return json.load(file)
@property
def text(self) -> str:
"""raw text version for local requests."""
with open(self._filename, "r") as file:
return file.read()