How did Flask split a server name into host and port?
A lesson on Flask pull request #6096. Computing, work level.
A server name often holds a host and a port, like a street and a door number.
A colon sits between them.
Flask's run code split the name like this: sn_host, _, sn_port = server_name.partition(":").
The partition method cuts a string at the colon.
It gives back the part before the colon, the colon itself, and the part after.
Flask kept the first part as the host and the last part as the port.
Questions in this lesson
- A server name arrives as one piece of text, like "localhost:5000". You need the machine name and the door number apart. What is the most natural way to split it?
- In your own words, how did Flask turn a server name into a host and a port, and what happened to the colon in the middle?