def test_to_str(self):
        b = bytes([1, 2, 3])
        s = to_str(b)
        self.assertIsInstance(s, str)

        some_str = 'hellp'
        s = to_str(some_str)
        self.assertIsInstance(s, str)
Beispiel #2
0
    def test_to_str(self):
        b = bytes([1, 2, 3])
        s = to_str(b)
        self.assertIsInstance(s, str)

        some_str = 'hellp'
        s = to_str(some_str)
        self.assertIsInstance(s, str)
Beispiel #3
0
    def post(self, name):
        schema = json.loads(to_str(self.request.body))
        schema_obj = dict(_id=name, schema=schema)
        with self.catch_db_errors:
            yield self.db.schemas.insert(schema_obj)

        self.set_status(http.client.CREATED)
        self.write(schema)
    def post(self, name):
        schema = json.loads(to_str(self.request.body))
        schema_obj = dict(
            _id=name,
            schema=schema
        )
        with self.catch_db_errors:
            yield self.db.schemas.insert(schema_obj)

        self.set_status(http.client.CREATED)
        self.write(schema)
    def fetch(self, url, method='GET', body=None, headers=None):
        request = HTTPRequest(
            url,
            method=method,
            headers=headers,
            body=self.prepare_body(body)
        )

        try:
            response = yield self.http_client.fetch(request)
        except HTTPError as e:
            return None, e.response

        if response.body:
            data = json.loads(utils.to_str(response.body))
        else:
            data = None

        return data, response
Beispiel #6
0
    def pop(self, timeout=0):
        r = redis_pool.get_redis()
        if timeout > 0:
            data = r.brpop(self.key, timeout)
            if isinstance(data, tuple):
                data = data[1]
        else:
            data = r.rpop(self.key)
        if data:
            data = to_str(data, redis_pool.get_redis_encoding())
            data = json.loads(data)
            time_out = data.get('time_out', '')
            if time_out:
                if time_out > int(time.time() - 10):
                    return data
                else:
                    self.pop()
            else:
                return data

        else:
            return None
Beispiel #7
0
 def _push(self,
           host,
           port,
           protocol='http',
           time_out=None,
           user=None,
           pwsd=None):
     if protocol not in ['http', 'https']:
         protocol = 'http'
     if not time_out:
         time_out = cfg.PROXY_MAX_TIMEOUT
     proxy = "%(protocol)s://%(host)s:%(port)s" % {
         "protocol": protocol,
         "host": host,
         "port": port,
     }
     data = {'proxy': proxy, 'proxy_name': self.name, 'time_out': time_out}
     if user and pwsd:
         proxy_user_pass = user + ":" + pwsd
         data['Proxy-Authorization'] = 'Basic ' + to_str(
             base64.b64encode(proxy_user_pass.encode('utf8')))
     self._queue_handle.push(json.dumps(data, ensure_ascii=False))