Created
January 2, 2014 19:52
-
-
Save iromli/8225482 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import rawes | |
class Elastic(object): | |
def __init__(self, app=None): | |
if app is not None: | |
self.init_app(app) | |
else: | |
self.app = None | |
def init_app(self, app): | |
app.config.setdefault('RAWES_URL', 'http://localhost:9200') | |
app.config.setdefault('RAWES_PATH', '') | |
app.config.setdefault('RAWES_TIMEOUT', 30) | |
if not hasattr(app, 'extensions'): | |
app.extensions = {} | |
app.extensions['elastic'] = rawes.Elastic( | |
url=app.config['RAWES_URL'], | |
path=app.config['RAWES_PATH'], | |
timeout=app.config['RAWES_TIMEOUT'], | |
) | |
self.app = app | |
def __getattr__(self, name): | |
if self.app is None: | |
raise RuntimeError( | |
'application not registered on elastic instance') | |
return getattr(self.app.extensions['elastic'], name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment