pyhook / pyhook /

from pyramid.view import view_config
from urllib import urlopen, quote_plus
from urllib2 import unquote
import json

html_escape_table = {
    "&": "&",
    '"': """,
    "'": "'",
    ">": ">",
    "<": "&lt;",

HOST = ""
PORT = "8083"
SECRET = "yoyoyo"
HOOKPATH = HOST + ":" + PORT + "/web/"

def html_escape(text):
    return ''.join(html_escape_table.get(c,c) for c in text)

def chat(request):
    request.headers['Cookie'] = 'dong=dong'
    return {'page_title':'pyhook chat'}

@view_config(name='login', renderer='login.mak')
def login(request):
    return {'page_title':'pyhook login'}

@view_config(name='connect', renderer='json')
def connect(request):
    name = ''
        name = request.cookies['name']
    if not name:
        name = 'guest'
    name = unquote(name)
    return [True, {'name':name}]

@view_config(name='disconnect', renderer='json')
def disconnect(request):
    return [True, {}]

@view_config(name='create_channel', renderer='json')
def create_channel(request):
    return [True, {'history_size':10,
                   'reflective': True,
                   'presenceful': True }]

@view_config(name='destroy_channel', renderer='json')
def destroy_channel(request):
    return [True, {}]

@view_config(name='subscribe', renderer='json')
def subscribe(request):
    return [True, {}]

@view_config(name='unsubscribe', renderer='json')
def unsubscribe(request):
    chan = request.params['channel_name']
    user = request.params['user']
    payload = quote_plus(json.dumps('%s has disconnected' % user))
    url = HOOKPATH + 'publish?security_token=%s&channel_name=%s&payload=%s' % (SECRET, chan, payload) 
    return [True, {}]

@view_config(name='publish', renderer='json')
def publish(request):
    payload = html_escape(json.loads(request.params['payload']))
    return [True, {'override_payload':payload}]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.