Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 37695d6
Showing
15 changed files
with
2,447 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.cs diff=csharp | ||
*.sln merge=union | ||
*.csproj merge=union | ||
*.vbproj merge=union | ||
*.fsproj merge=union | ||
*.dbproj merge=union | ||
|
||
# Standard to msysgit | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
################# | ||
## Eclipse | ||
################# | ||
|
||
*.pydevproject | ||
.project | ||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.classpath | ||
.settings/ | ||
.loadpath | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# CDT-specific | ||
.cproject | ||
|
||
# PDT-specific | ||
.buildpath | ||
|
||
|
||
################# | ||
## Visual Studio | ||
################# | ||
|
||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.sln.docstates | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Rr]elease/ | ||
*_i.c | ||
*_p.c | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.vspscc | ||
.builds | ||
*.dotCover | ||
|
||
## TODO: If you have NuGet Package Restore enabled, uncomment this | ||
#packages/ | ||
|
||
# Visual C++ cache files | ||
ipch/ | ||
*.aps | ||
*.ncb | ||
*.opensdf | ||
*.sdf | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
|
||
# ReSharper is a .NET coding add-in | ||
_ReSharper* | ||
|
||
# Installshield output folder | ||
[Ee]xpress | ||
|
||
# DocProject is a documentation generator add-in | ||
DocProject/buildhelp/ | ||
DocProject/Help/*.HxT | ||
DocProject/Help/*.HxC | ||
DocProject/Help/*.hhc | ||
DocProject/Help/*.hhk | ||
DocProject/Help/*.hhp | ||
DocProject/Help/Html2 | ||
DocProject/Help/html | ||
|
||
# Click-Once directory | ||
publish | ||
|
||
# Others | ||
[Bb]in | ||
[Oo]bj | ||
sql | ||
TestResults | ||
*.Cache | ||
ClientBin | ||
stylecop.* | ||
~$* | ||
*.dbmdl | ||
Generated_Code #added for RIA/Silverlight projects | ||
|
||
# Backup & report files from converting an old project file to a newer | ||
# Visual Studio version. Backup files are not needed, because we have git ;-) | ||
_UpgradeReport_Files/ | ||
Backup*/ | ||
UpgradeLog*.XML | ||
|
||
|
||
|
||
############ | ||
## Windows | ||
############ | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
|
||
############# | ||
## Python | ||
############# | ||
|
||
*.py[co] | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
|
||
#Translations | ||
*.mo | ||
|
||
#Mr Developer | ||
.mr.developer.cfg | ||
|
||
# Mac crap | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__all__ = [ | ||
'route', 'run', 'static_file', 'error','get', 'post', 'put', 'delete', 'Mole', | ||
'request', 'response', | ||
'abort', 'redirect', | ||
'DEBUG', 'HTTP_CODES', | ||
'__version__', | ||
] | ||
|
||
from mole import route, run, static_file, error,get, post, put, delete, Mole | ||
from mole import request, response | ||
from mole import abort, redirect | ||
from mole import DEBUG, HTTP_CODES | ||
|
||
__version__ = "1.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
import const | ||
from response import HeaderDict | ||
|
||
class MoleException(Exception): | ||
""" A base class for exceptions used by Mole. """ | ||
pass | ||
|
||
class HTTPResponse(MoleException): | ||
""" Used to break execution and immediately finish the response """ | ||
def __init__(self, output='', status=200, header=None): | ||
super(MoleException, self).__init__("HTTP Response %d" % status) | ||
self.status = int(status) | ||
self.output = output | ||
self.headers = HeaderDict(header) if header else None | ||
|
||
def apply(self, response): | ||
if self.headers: | ||
for key, value in self.headers.iterallitems(): | ||
response.headers[key] = value | ||
response.status = self.status | ||
|
||
class HTTPError(HTTPResponse): | ||
""" Used to generate an error page """ | ||
def __init__(self, code=500, output='Unknown Error', exception=None, traceback=None, header=None): | ||
super(HTTPError, self).__init__(output, code, header) | ||
self.exception = exception | ||
self.traceback = traceback | ||
|
||
def __repr__(self): | ||
from template import template | ||
return template(const.ERROR_PAGE_TEMPLATE, e=self) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
import httplib | ||
|
||
TEMPLATE_PATH = ['./', './templates/'] | ||
TEMPLATES = {} | ||
DEBUG = True | ||
MEMFILE_MAX = 1024*100 | ||
|
||
#: A dict to map HTTP status codes (e.g. 404) to phrases (e.g. 'Not Found') | ||
HTTP_CODES = httplib.responses | ||
HTTP_CODES[418] = "I'm a teapot" # RFC 2324 | ||
|
||
#: The default template used for error pages. Override with @error() | ||
ERROR_PAGE_TEMPLATE = """ | ||
%try: | ||
%from mole import DEBUG, HTTP_CODES, request | ||
%status_name = HTTP_CODES.get(e.status, 'Unknown').title() | ||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> | ||
<html> | ||
<head> | ||
<title>ops! Error {{e.status}}: {{status_name}}</title> | ||
<style type="text/css"> | ||
html {background-color: #eee; font-family: sans;} | ||
body {background-color: #fff; border: 1px solid #ddd; padding: 15px; margin: 15px;} | ||
pre {background-color: #eee; border: 1px solid #ddd; padding: 5px;} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>ops! Error {{e.status}}: {{status_name}}</h1> | ||
<p>Sorry, the requested URL <tt>{{request.url}}</tt> caused an error:</p> | ||
<pre>{{str(e.output)}}</pre> | ||
%if DEBUG and e.exception: | ||
<h2>Exception:</h2> | ||
<pre>{{repr(e.exception)}}</pre> | ||
%end | ||
%if DEBUG and e.traceback: | ||
<h2>Traceback:</h2> | ||
<pre>{{e.traceback}}</pre> | ||
%end | ||
</body> | ||
</html> | ||
%except ImportError: | ||
<b>ImportError:</b> Could not generate the error page. Please add mole to sys.path | ||
%end | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import base64 | ||
import hmac | ||
try: import cPickle as pickle | ||
except ImportError: # pragma: no cover | ||
import pickle | ||
|
||
|
||
from utils import tob,_lscmp | ||
|
||
def cookie_is_encoded(data): | ||
''' Return True if the argument looks like a encoded cookie.''' | ||
return bool(data.startswith(tob('!')) and tob('?') in data) | ||
|
||
def cookie_encode(data, key): | ||
''' Encode and sign a pickle-able object. Return a (byte) string ''' | ||
msg = base64.b64encode(pickle.dumps(data, -1)) | ||
sig = base64.b64encode(hmac.new(key, msg).digest()) | ||
return tob('!') + sig + tob('?') + msg | ||
|
||
|
||
def cookie_decode(data, key): | ||
''' Verify and decode an encoded string. Return an object or None.''' | ||
data = tob(data) | ||
if cookie_is_encoded(data): | ||
sig, msg = data.split(tob('?'), 1) | ||
if _lscmp(sig[1:], base64.b64encode(hmac.new(key, msg).digest())): | ||
return pickle.loads(base64.b64decode(msg)) | ||
return None |
Oops, something went wrong.