Getting Started Explanation - shmolyneaux/SquareJam GitHub Wiki
When SnakeCharmer processes a request it breaks up the URL. A URL such as https://0.0.0.0:8001/test/example
would start at the _0_0_0_0
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
orDict
, SnakeCharmer looks for anindex
Object
within it. If there is aMethod
namedhtml
SnakeCharmer withinindex
, it 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 send to the 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 through a user with appropriate permissions through storserv, instead of the database being manipulated directly by SnakeCharmer itself.
The Object, Dict, and List objects can be interacted with in the same way as standard python objects.
Attributes can be set in the following way:
- Object:
object.__setattr__( attribute_name, value )
orobject.attribute_name = value
- List:
list.append( value )
orlist[n] = value
- Dict:
dict[key] = value
Attributes can be accessed using the following:
- Object:
object.__getattribute__( attribute_name )
orobject.attribute_name
- List:
list[n]
- Dict:
dict[key]