Menu

Getting Started Explanation

SHMolyneaux

Getting Started Tutorial Explanation

SnakeCharmer receives requests from a client and returns a web page.

When SnakeCharmer processes a request it breaks up the URL. A URL such as https://192.168.0.13:8001/test/example would start at the storserv_data/Server/WebSites/_192_168_0_13 object, then on to the attribute test if it exists, and end up at example. Depending on the type of object example is, a couple different things can happen:

  • When a URL maps to an Object or Dict, SnakeCharmer looks for an index Object within it. If there is a Method named html within index, SnakeCharmer will execute that method.
  • When a URL maps to a Method, SnakeCharmer executes that method.
  • When a URL maps to a File, SnakeCharmer returns the file to the browser with an appropriate MIME type based on the file extension.

The req parameter sent to a method is a SnakeCharmerHandler class. The two members modified by our method in [Getting Started] are content and content_type. content is simply the raw text sent to the browser through SnakeCharmer; content_type is the MIME type sent to the browser that allows it to interpret the data it receives. In most cases content_type will be set as text/html, which is the default, but can also be used to send JavaScript, text/javascript; CSS, text/css; or plain text, text/plain, among others. Plain text is most useful for debugging because it preserves white space. JavaScript and CSS are useful when the respective information needs to be stored as strings in the database.

You may have noticed that the current directory in [stosh] is displayed with . between objects. This is because stosh and SnakeCharmer interact with the database using objects mirroring the functionality of python lists, dictionaries, and objects. The program storserv interacts directly with the database by processing requests from the pstorage library through a socket. This increases the security of the framework because everything manipulated by SnakeCharmer has to be done by a user with appropriate permissions through storserv, instead of the database being manipulated directly by SnakeCharmer itself.

The [Objects], [Dicts], and [Lists] can be interacted with in a similar way as standard python objects.

Attributes can be set in the following way:

  • Object: object.__setattr__( attribute_name, value ) or object.attribute_name = value
  • List: list.append( value ) or list[n] = value
  • Dict: dict[key] = value

Attributes can be accessed with the following:

  • Object: object.__getattribute__( attribute_name ) or object.attribute_name
  • List: list[n]
  • Dict: dict[key]

Related

Wiki: Dicts
Wiki: Getting Started
Wiki: Lists
Wiki: Objects
Wiki: Setting Up StorGUI Explanation
Wiki: stosh

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.