import gevent.pool
import time

from restkit import request
from restkit.globals import set_manager
from restkit.manager.mgevent import GeventManager


url = 'http://127.0.0.1/index.html'

N = 1000
C = 10

manager = GeventManager(timeout=300, max_conn=C, reap_connections=True)
set_manager(manager)


def run():
    response = request(url)
    response.body_string()
    assert response.status_int == 200


group = gevent.pool.Pool(size=C)

now = time.time()
for _ in xrange(N):
    group.spawn(run)
group.join()
Пример #2
0
from bottle import route
import bottle

import logging
from pprint import pprint
import inspect

import sys
from restkit import Resource
import restkit

from restkit.globals import set_manager, get_manager
from restkit.manager.mgevent import GeventManager

# set the gevent connection manager
set_manager(GeventManager())

# logging
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)


# zu webdav
#
# für beispiel '207 Multi-Status' siehe
#   http://tools.ietf.org/html/rfc4437#page-13
#
# Header
#   Apply-To-Redirect-Ref Request Header
#
# apache kennt folgende methoden
Пример #3
0
# see https://twimg0-a.akamaihd.net/profile_background_images/25029373/http-headers-status.gif
import re
import json
import urllib
import logging
from restkit import Resource
from restkit.errors import ResourceNotFound
from restkit.forms import multipart_form_encode
from restkit.datastructures import MultiDict
from restkit.globals import set_manager, get_manager
try:
    import eventlet
    eventlet.monkey_patch()
    from restkit.manager.meventlet import EventletManager
    set_manager(EventletManager(timeout=60))
except ImportError:
    from restkit import Manager
    set_manager(Manager(max_conn=10))
from .exceptions import SoundcloudException
from .auth import (
    PublicAuth,
    PrivateAuth,
)

logger = logging.getLogger('soundcloudapi')

BASEURI = 'https://api.soundcloud.com'
FILTER = 'filter'
USERID = 'id'
BOUNDARY = '---xxThIs_Is_tHe_bouNdaRY_f0r_ThE_s0uNdC10uDxx--'
SECRET_TOKEN_TPL = "%{stream_url}s?secret_token=%{secret_token}s/client_id=" + \
Пример #4
0
#received ALERT: PRINTER PAUSED [ZBR3913909] :: ('192.168.0.85', 3972)
#received ERROR CLEARED: HEAD OPEN [ZBR3913909] :: ('192.168.0.85', 3973)
#received ALERT CLEARED: PRINTER PAUSED [ZBR3913909] :: ('192.168.0.85', 3974)
import celeryconfig
from restkit import Resource, request
from restkit.manager.mgevent import GeventManager

def identify_printer(address,printers):
    for k,v in printers.items():
        if address[0] == v['ip_address']:
            return v['resource_uri']
    return None

printers= {}

set_manager(GeventManager(timeout=60))

def zebra_alert_handler(socket, address):
    try:
        fileobj = socket.makefile()

        while True:
            line = fileobj.readline()
            if not line:
                break
            fileobj.write(line)
            fileobj.flush()
            raw_msg = line.strip()
            message_split = raw_msg.split(':')
            if message_split[0] == 'ALERT' or message_split[0] == 'ERROR CONDITION':
                #it's an alert/error,
Пример #5
0
import timeit

import eventlet
eventlet.monkey_patch()

from restkit import *
from restkit.globals import set_manager, get_manager
from restkit.manager.meventlet import EventletManager

#set_logging("debug")

print "Manager was: %s" % type(get_manager())
set_manager(EventletManager())
print "Manager is set to: %s" % type(get_manager())

pool = eventlet.GreenPool()

urls = [
    "http://yahoo.fr", "http://google.com", "http://friendpaste.com",
    "http://benoitc.io", "http://couchdb.apache.org"
]

allurls = []
for i in range(10):
    allurls.extend(urls)


def fetch(u):
    r = request(u, follow_redirect=True)
    print "RESULT: %s: %s (%s)" % (u, r.status, len(r.body_string()))
Пример #6
0
import timeit

import eventlet 
eventlet.monkey_patch()

from restkit import *
from restkit.globals import set_manager, get_manager
from restkit.manager.meventlet import EventletManager

#set_logging("debug")

print "Manager was: %s" % type(get_manager())
set_manager(EventletManager())
print"Manager is set to: %s" %type(get_manager())

pool = eventlet.GreenPool()

urls = [
        "http://yahoo.fr",
        "http://google.com", 
        "http://friendpaste.com", 
        "http://benoitc.io", 
        "http://couchdb.apache.org"]

allurls = []
for i in range(10):
    allurls.extend(urls)

def fetch(u):
    r = request(u, follow_redirect=True)
    print "RESULT: %s: %s (%s)" % (u, r.status, len(r.body_string()))
Пример #7
0
monkey.patch_all()

import gevent.pool
import time

from restkit import request
from restkit.globals import set_manager
from restkit.manager.mgevent import GeventManager

url = 'http://127.0.0.1/index.html'

N = 1000
C = 10

manager = GeventManager(timeout=300, max_conn=C, reap_connections=True)
set_manager(manager)


def run():
    response = request(url)
    response.body_string()
    assert response.status_int == 200


group = gevent.pool.Pool(size=C)

now = time.time()
for _ in xrange(N):
    group.spawn(run)
group.join()
Пример #8
0
import timeit

from gevent import monkey
monkey.patch_all()
import gevent

from restkit import *
from restkit.globals import set_manager, get_manager
from restkit.manager.mgevent import GeventManager

set_logging("debug")

print "Manager was: %s" % type(get_manager())
set_manager(GeventManager())
print "Manager is set to: %s" % type(get_manager())

urls = [
    "http://yahoo.fr", "http://google.com", "http://friendpaste.com",
    "http://benoitc.io", "http://couchdb.apache.org"
]

allurls = []
for i in range(10):
    allurls.extend(urls)


def fetch(u):
    r = request(u, follow_redirect=True)
    print "RESULT: %s: %s (%s)" % (u, r.status, len(r.body_string()))

Пример #9
0
# see https://twimg0-a.akamaihd.net/profile_background_images/25029373/http-headers-status.gif
import re
import json
import urllib
import logging
from restkit import Resource
from restkit.errors import ResourceNotFound
from restkit.forms import multipart_form_encode
from restkit.datastructures import MultiDict
from restkit.globals import set_manager, get_manager
try:
    import eventlet
    eventlet.monkey_patch()
    from restkit.manager.meventlet import EventletManager
    set_manager(EventletManager(timeout=60))
except ImportError:
    from restkit import Manager
    set_manager(Manager(max_conn=10))
from .exceptions import SoundcloudException
from .auth import (
    PublicAuth,
    PrivateAuth,
)

logger = logging.getLogger('soundcloudapi')

BASEURI = 'https://api.soundcloud.com'
FILTER = 'filter'
USERID = 'id'
BOUNDARY = '---xxThIs_Is_tHe_bouNdaRY_f0r_ThE_s0uNdC10uDxx--'
SECRET_TOKEN_TPL = "%{stream_url}s?secret_token=%{secret_token}s/client_id=" + \