This file contains hidden or 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
| # coding: utf-8 | |
| """ | |
| Example of how to deal with user objects that can implement either __unicode__ | |
| or __str__, and we don't know which - eg. exceptions, into which the user | |
| might've passed a bytes message or a unicode message. | |
| One function shows how to convert both cases to bytes (str), the other function | |
| shows how to convert both cases to unicode - depending what we need. | |
| BTW note that it is much better to always know if we're dealing with bytes or |
This file contains hidden or 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
| from twisted.internet.protocol import Factory | |
| class MyFactory(Factory): | |
| protocol = MyProtocol | |
| def __init__(self, queue): | |
| self._queue = queue | |
| def buildProtocol(self, addr): | |
| return self.protocol(self._queue) |
This file contains hidden or 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
| from klein import Klein | |
| app = Klein() | |
| @app.route('/') | |
| def index(request): | |
| return 'foo' | |
| # expose a 'resource' name for use with twistd web | |
| resource = app.resource |
This file contains hidden or 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
| from twisted.web.resource import Resource | |
| from twisted.web import server | |
| from flask import Flask, render_template_string | |
| from twisted.web.wsgi import WSGIResource | |
| from twisted.internet import reactor | |
| from twisted.internet.task import LoopingCall | |
| import json | |
| INDEX_TEMPLATE = """ |
This file contains hidden or 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
| from flask import Flask, abort | |
| app = Flask(__name__) | |
| @app.route('/') | |
| def foo(): | |
| abort(403) | |
| return 'this wont ever be returned' | |
| @app.errorhandler(403) |
This file contains hidden or 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
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>asd</title> | |
| <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> | |
| <script src="underscore.js"></script> | |
| <script src="backbone.js"></script> | |
| <script> |
This file contains hidden or 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
| from flask import Flask, Blueprint, current_app, request | |
| from collections import namedtuple | |
| class ConfigBlueprint(Blueprint): | |
| def register(self, app, options, first_registration): | |
| self.options = options | |
| super(ConfigBlueprint, self).register(app, options, first_registration) | |
This file contains hidden or 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
| This is free and unencumbered software released into the public domain. | |
| Anyone is free to copy, modify, publish, use, compile, sell, or | |
| distribute this software, either in source code form or as a compiled | |
| binary, for any purpose, commercial or non-commercial, and by any | |
| means. | |
| In jurisdictions that recognize copyright laws, the author or authors | |
| of this software dedicate any and all copyright interest in the | |
| software to the public domain. We make this dedication for the benefit |
NewerOlder