Commits

egghead committed b404764

initial commit

  • Participants

Comments (0)

Files changed (23)

+0.0
+---
+
+-  Initial version
+include *.txt *.ini *.cfg *.rst
+recursive-include pyhook *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
+pyhook README
+
+run 'setup.py install develop' to install
+this pyramid app requires hookbox to be running
+hookbox will need to know about pyhooks host, port, and mount point
+pyhook will need to know about hookbox's host port and REST secret
+
+[app:pyhook]
+use = egg:pyhook
+reload_templates = true
+mako.directories = pyhook:templates
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = true
+default_locale_name = en
+
+[pipeline:main]
+pipeline =
+    egg:WebError#evalerror
+    pyhook
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 6543
+
+# Begin logging configuration
+
+[loggers]
+keys = root, pyhook
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = INFO
+handlers = console
+
+[logger_pyhook]
+level = DEBUG
+handlers =
+qualname = pyhook
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
+
+# End logging configuration
+[app:pyhook]
+use = egg:pyhook
+reload_templates = false
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = false
+default_locale_name = en
+
+[filter:weberror]
+use = egg:WebError#error_catcher
+debug = false
+;error_log = 
+;show_exceptions_in_wsgi_errors = true
+;smtp_server = localhost
+;error_email = janitor@example.com
+;smtp_username = janitor
+;smtp_password = "janitor's password"
+;from_address = paste@localhost
+;error_subject_prefix = "Pyramid Error"
+;smtp_use_tls =
+;error_message =
+
+[pipeline:main]
+pipeline =
+    weberror
+    pyhook
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 6543
+
+# Begin logging configuration
+
+[loggers]
+keys = root, pyhook
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = WARN
+handlers = console
+
+[logger_pyhook]
+level = WARN
+handlers =
+qualname = pyhook
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
+
+# End logging configuration

pyhook.egg-info/PKG-INFO

+Metadata-Version: 1.0
+Name: pyhook
+Version: 0.0
+Summary: pyhook
+Home-page: UNKNOWN
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: UNKNOWN
+Description: pyhook README
+        
+        
+        
+        
+        
+        0.0
+        ---
+        
+        -  Initial version
+        
+Keywords: web pyramid pylons
+Platform: UNKNOWN
+Classifier: Programming Language :: Python
+Classifier: Framework :: Pylons
+Classifier: Topic :: Internet :: WWW/HTTP
+Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application

pyhook.egg-info/SOURCES.txt

+CHANGES.txt
+MANIFEST.in
+README.txt
+development.ini
+production.ini
+setup.cfg
+setup.py
+pyhook/__init__.py
+pyhook/resources.py
+pyhook/tests.py
+pyhook/views.py
+pyhook.egg-info/PKG-INFO
+pyhook.egg-info/SOURCES.txt
+pyhook.egg-info/dependency_links.txt
+pyhook.egg-info/entry_points.txt
+pyhook.egg-info/not-zip-safe
+pyhook.egg-info/paster_plugins.txt
+pyhook.egg-info/requires.txt
+pyhook.egg-info/top_level.txt
+pyhook/templates/mytemplate.mak

pyhook.egg-info/dependency_links.txt

+

pyhook.egg-info/entry_points.txt

+      [paste.app_factory]
+      main = pyhook:main
+      

pyhook.egg-info/not-zip-safe

+

pyhook.egg-info/paster_plugins.txt

+pyramid

pyhook.egg-info/requires.txt

+pyramid
+WebError

pyhook.egg-info/top_level.txt

+pyhook

pyhook/__init__.py

+from pyramid.config import Configurator
+from pyhook.resources import Root
+
+def main(global_config, **settings):
+    """ This function returns a Pyramid WSGI application.
+    """
+    config = Configurator(root_factory=Root, settings=settings)
+    config.scan()
+    config.add_static_view('static', 'pyhook:static')
+    return config.make_wsgi_app()
+

pyhook/resources.py

+class Root(object):
+    def __init__(self, request):
+        self.request = request

pyhook/static/app.js

+// get name information for cookie
+var name = prompt("What is your name", "guest");
+var conn
+$.cookie("name", name);
+
+function hookup() {
+    conn = hookbox.connect('http://173.255.213.176:8083');
+    conn.onError = function(err) {
+    	alert('connection failed: ' + err.msg); 
+    };
+    var subscription = null;
+    conn.onSubscribed = function(chan, _sub) {
+        subscription = _sub;
+        subscription.onPublish = function(frame) {
+            if (frame.user) {
+                var _content = frame.user + ': ' + frame.payload;
+            } else { 
+                var _content = frame.payload;
+            };
+            $('.chats').prepend('<br><span>' + _content + '</span>')
+        };
+    };
+    conn.subscribe('test');
+    conn.publish('test', 'sucessfully connected');
+};
+hookup();
+
+// document.ready call
+$(function () {
+	$('#chat').submit(function () {
+		conn.publish('test', $("input:first").val());
+		$("input:first").attr('value', '');
+		return false;
+	});
+});

pyhook/templates/base.mak

+<!DOCTYPE html>
+<html lang='en'>
+<head>
+	<meta charset='utf-8'>
+	<title>${self.title()}</title>
+	${self.head_content()}
+</head>
+<body>
+	${self.body_content()}
+</body>
+</html>
+
+<%def name="title()">
+	base title
+</%def>
+
+<%def name="head_content()">
+	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+	<script src='http://173.255.213.176:8083/static/hookbox.js'></script>
+</%def>
+
+<%def name="body_content()">
+	base body
+</%def>

pyhook/templates/chat.mak

+<%inherit file="base.mak"/>
+
+<%def name="title()">
+	${page_title}
+</%def>
+
+<%def name="body_content()">
+	<script src='https://github.com/carhartl/jquery-cookie/raw/master/jquery.cookie.js'></script>
+	<form id='chat' action='#'>
+	<input>
+	<input type='submit' value='yup'>
+	</form>
+	<script src='/static/app.js'></script>
+	<div class='chats'>
+	</div>
+</%def>

pyhook/templates/login.mak

+<%inherit file="base.mak"/>
+
+<%def name="title()">
+	${page_title}
+</%def>
+
+<%def name="body_content()">
+	body content here
+</%def>
+import unittest
+
+from pyramid import testing
+
+class ViewTests(unittest.TestCase):
+    def setUp(self):
+        self.config = testing.setUp()
+
+    def tearDown(self):
+        testing.tearDown()
+
+    def test_my_view(self):
+        from pyhook.views import my_view
+        request = testing.DummyRequest()
+        info = my_view(request)
+        self.assertEqual(info['project'], 'pyhook')
+from pyramid.view import view_config
+from urllib import urlopen, quote_plus
+from urllib2 import unquote
+import json
+
+html_escape_table = {
+    "&": "&amp;",
+    '"': "&quot;",
+    "'": "&apos;",
+    ">": "&gt;",
+    "<": "&lt;",
+    }
+
+HOST = "http://127.0.0.1"
+PORT = "8083"
+SECRET = "yoyoyo"
+HOOKPATH = HOST + ":" + PORT + "/web/"
+
+def html_escape(text):
+    return ''.join(html_escape_table.get(c,c) for c in text)
+
+@view_config(renderer='chat.mak')
+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 = ''
+    try:
+        name = request.cookies['name']
+    except:
+        pass
+    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) 
+    urlopen(url)
+    return [True, {}]
+
+@view_config(name='publish', renderer='json')
+def publish(request):
+    payload = html_escape(json.loads(request.params['payload']))
+    return [True, {'override_payload':payload}]
+[nosetests]
+match = ^test
+nocapture = 1
+cover-package = pyhook
+with-coverage = 1
+cover-erase = 1
+
+[compile_catalog]
+directory = pyhook/locale
+domain = pyhook
+statistics = true
+
+[extract_messages]
+add_comments = TRANSLATORS:
+output_file = pyhook/locale/pyhook.pot
+width = 80
+
+[init_catalog]
+domain = pyhook
+input_file = pyhook/locale/pyhook.pot
+output_dir = pyhook/locale
+
+[update_catalog]
+domain = pyhook
+input_file = pyhook/locale/pyhook.pot
+output_dir = pyhook/locale
+previous = true
+import os
+
+from setuptools import setup, find_packages
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(here, 'README.txt')).read()
+CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
+
+requires = ['pyramid', 'WebError']
+
+setup(name='pyhook',
+      version='0.0',
+      description='pyhook',
+      long_description=README + '\n\n' +  CHANGES,
+      classifiers=[
+        "Programming Language :: Python",
+        "Framework :: Pylons",
+        "Topic :: Internet :: WWW/HTTP",
+        "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
+        ],
+      author='',
+      author_email='',
+      url='',
+      keywords='web pyramid pylons',
+      packages=find_packages(),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=requires,
+      tests_require=requires,
+      test_suite="pyhook",
+      entry_points = """\
+      [paste.app_factory]
+      main = pyhook:main
+      """,
+      paster_plugins=['pyramid'],
+      )
+