Controller

Application Server Controller of the Model View Controller external link

Contains the classes for the

  • Controller - Controls the flow of requests
  • EZContext - Information from the request
  • EZQuit - Stops the server

While under construction, Schemas can be stored on the browser using Local Storage

A valid Schema will be generated. It can be validated on Google Developers Structured Data Testing Tool external link

class controller.Controller(port)

The Controller class manages the flow of requests for Generating Schemas

run_this(environ, start_response)

Class method passed to the http demon

Here is where all GET and POST get treated

Here is where the Model is invoked

Here is where the View is invoked

Parameters:
  • environ – A mapping external link object representing the string environment concerning the request
  • start_response – Callable. Used to begin the HTTP response
Returns:

Requested page.

server_close()

Class method closes the http demon

class controller.EZContext(environ)

Class containing the information of the current request

The information can be accessed through the get() method

get(key)

Class method to obtain the key from the:

  • QUERY_STRING: if it’s a GET request
  • wsgi.input: if it’s a POST request

For security reasons, GET and POST methods cannot be used interchangeably.

Parameters:key
Returns:value or empty string if key not found
get_keys

Class method to obtain all the keys

Returns:all keys
class controller.EZQuit(httpd)

Shuts down the http demon

Nothing more, nothing less

Must be an independent thread

Starting the server at default port 8000

The Application Server can be started directly from the command line

computer:~$ ./controller.py

or

computer:~$ python3 controller.py

Starting the server at another port

A number of Application Servers can be started to serve at different ports.

computer:~$ ./controller.py 8001 &

or

computer:~$ python3 controller.py  8001 &

Shutting down the server

The server can be shut down from a browser.

http://localhost:port/quit

or using Python

from urllib.error import URLError
from urllib.request import urlopen

try:
    urlopen('http://localhost:{0}/quit'.format(port))
except URLError:
    pass

Restarting the server

The server can be shut down from a browser.

http://localhost:port/restart

or using Python

from urllib.error import URLError
from urllib.request import urlopen

try:
    urlopen('http://localhost:{0}/restart'.format(port))
except URLError:
    pass