Skip to content

Commit 1e59400

Browse files
committed
ch20: README.adoc
1 parent f7bf5b0 commit 1e59400

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

20-futures/getflags/README.adoc

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
11
= Experimenting with the `flags2*` examples
22

3+
== Install SSL Certificates (for MacOS)
4+
5+
On Macos, depending on how in installed Python you may need to manually run a command
6+
after Python's installer finishes, to install SSL certificates for HTTPS connections.
7+
8+
Using the Finder, open the `Python 3.X` folder inside `/Applications` folder
9+
and double-click "Install Certificates" or "Install Certificates.command".
10+
11+
Using the terminal, you can type for example:
12+
13+
[source, text]
14+
----
15+
$ open /Applications/Python 3.10/"Install Certificates.command"
16+
----
17+
18+
319
== Setting up a test server
420

521
If you don't already have a local HTTP server for testing,
6-
here are the steps to experiment using only Python ≥ 3.9—no external libraries:
22+
here are the steps to experiment using only Python ≥ 3.9:
723

8-
. Clone or download the https://github.com/fluentpython/example-code-2e[_Fluent Python 2e_ code repository].
9-
. Open your shell and go to the _20-futures/getflags/_ directory of your local copy of the repository.
24+
. Clone or download the https://github.com/fluentpython/example-code-2e[_Fluent Python 2e_ code repository] (this repo!).
25+
. Open your shell and go to the _20-futures/getflags/_ directory of your local copy of the repository (this directory!)
1026
. Unzip the _flags.zip_ file, creating a _flags_ directory at _20-futures/getflags/flags/_.
1127
. Open a second shell, go to the _20-futures/getflags/_ directory and run `python3 -m http.server`. This will start a `ThreadingHTTPServer` listening to port 8000, serving the local files. If you open the URL http://localhost:8000/flags/[http://localhost:8000/flags/] with your browser, you'll see a long list of directories named with two-letter country codes from `ad/` to `zw/`.
1228
. Now you can go back to the first shell and run the _flags2*.py_ examples with the default `--server LOCAL` option.
13-
. To test with the `--server DELAY` option, go to _20-futures/getflags/_ and run `python3 slow_server.py 8001`. This will add a .5s delay before each response.
14-
. To test with the `--server ERROR` option, go to _20-futures/getflags/_ and run `python3 slow_server.py 8002 --error-rate .25`. Each request will have a 25% probability of getting a https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418[418 I'm a teapot] response, and all responses will be delayed .5s.
29+
. To test with the `--server DELAY` option, go to _20-futures/getflags/_ and run `python3 slow_server.py`. This bind to port 8001 by default. It will add a .5s delay before each response.
30+
. To test with the `--server ERROR` option, go to _20-futures/getflags/_ and run `python3 slow_server.py 8002 --error-rate .25`.
31+
Each request will have a 25% probability of getting a
32+
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418[418 I'm a teapot] response,
33+
and all responses will be delayed .5s.
1534

1635
I wrote _slow_server.py_ reusing code from Python's
1736
https://github.com/python/cpython/blob/917eca700aa341f8544ace43b75d41b477e98b72/Lib/http/server.py[`http.server`] standard library module,
1837
which "is not recommended for production"—according to the
1938
https://docs.python.org/3/library/http.server.html[documentation].
20-
To set up a more reliable testing environment, I recommend configuring
39+
40+
[NOTE]
41+
====
42+
This is a simple testing environment that does nor require any external libraries or
43+
tools—apart from the libraries used in the `flags2*` scripts themselves, as discussed in the book.
44+
45+
For a more robust testing environment, I recommend configuring
2146
https://www.nginx.com/[NGINX] and
2247
https://github.com/shopify/toxiproxy[Toxiproxy] with equivalent parameters.
48+
====
2349

2450
== Running a `flags2*` script
2551

0 commit comments

Comments
 (0)