When you take an adventure in the world of Python and suddenly encounter a web monster, what weapon do you choose to deal with it? In terms of weapons, the following weapons are among the best:
- Zope, heavy gun. Weapons that appeared earlier. This weapon is very powerful, indestructible, and useless. It is also suitable for use in the military, and the combat effect of the group is better. However, it takes a long time to make good use of Zope. As the saying goes, it is difficult to use Zope for a lifetime.
- Turbogears, mighty knife. A must-have. Its creators are familiar with the rules of the rivers and lakes, and are quite familiar with the martial arts leaders. In case of such incidents, they usually pull groups, assign tasks, and decide not to take everything on their own.
- Django, the elegant sword. He is very restrained. It is said that the experts who use this weapon are usually Lone Ranger. Their motto is: What do you do if you have a sword in your hand?
- Web. py, a small dagger, and a favorite of the assassin. It is often used to execute special tasks.
- Pylons, a strange whip. It is rumored that rails in the ruby world is put on the coat of Python. Be careful when using it, because you don't know whether it will wrap your enemy's neck or your own neck.
However, what we are talking about today is not these weapons, but a way of thinking. After all, the use of weapons is just a "trick", while the mind method is the soul of the trick method, the mind method is one channel, and the trick is one hundred links. This is the "pipeline idea" created by Mario, which is called wsgi (Python web service Gateway Interface) in the western mainland ).
Mario is a plumber who has been studying martial arts through water pipes all the year round. Mario found that weapons do not matter. The most important thing is to look at the people who use the weapons and the objects you want to deal. The so-called one-inch long, a strong, such as Zope powerful, used to deal with large monsters is very suitable, but it is inevitable to lag heavy; while one-inch short, a risk, such as web. PY has its unique advantages in dealing with small and sensitive monsters. Therefore, simply commenting on the advantages and disadvantages of a weapon is an empty discussion. As a result, Mario had been thinking for more than ten years in the water pipe, and finally found a mental approach suitable for all weapons. You can use any weapons with ease. Since Mario was inspired by water pipes, he was named "pipeline idea ". The author of this article was lucky enough to find this method during the tour and spread it out in the "Heart seeking method. Legend has it that Douglas mcroy, the great god of the ancient times, once constructed a time-space singularity called pipeline when he was involved in the creation, to connect stdout and stdin. We do not know whether Mario was inspired by this, but the "pipeline mind" is indeed similar:
Wsgi is a connector found by Mario while exploring the pipeline. It is very simple. A start_response is provided at the entrance for backflow (callback, callback), and the entrance is connected to a function at the exit, the environ dictionary and start_response are passed as parameters, while the exit function calls start_response and passes status and header, and then returns content. Due to the fact that there are some tricks in this section, Mario demonstrated the only trick and declared that all moves can be evolved from this trick:
DefApplication (Environ, start_response ):
Status ='200 OK'
Response_headers = [('Content-Type','Text/plain')]
Start_response (status, response_headers)
Return['Hello']
Mario also found that wsgi can be connected in series. to distinguish between them, Mario calls the entrance of the sewer pipeWeb Server, Can only accept external requests and call the function of the next pipe fitting; the middle pipe fitting is calledMiddlewareCan receive the request from the previous pipe fittings and call the function of the next pipe fittings. the end point of the pipeline isWeb appCan only be called by the previous pipe fittings.
In order to avoid future misunderstandings, Mario finally stressed that weapons are dead. Good weapons can be used to maximize their power only in the hands of appropriate people. Disputes over the quality of weapons are meaningless.
Mario finally gave this mental approach to pep, which pep numbered 333.