text:
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "structmember.h"

#define _MULTIARRAYMODULE
#define NPY_NO_PREFIX
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"

#include "config.h"

#include "common.h"
#include "arraytypes.h"

#include "conversion_utils.h"

/****************************************************************
* Useful function for conversion when used with PyArg_ParseTuple
****************************************************************/

/*NUMPY_API
 *
 * Useful to pass as converter function for O& processing in PyArgs_ParseTuple.
 *
 * This conversion function can be used with the "O&" argument for
 * PyArg_ParseTuple.  It will immediately return an object of array type
 * or will convert to a CARRAY any other object.
 *
 * If you use PyArray_Converter, you must DECREF the array when finished
 * as you get a new reference to it.
 */
NPY_NO_EXPORT int
PyArray_Converter(PyObject *object, PyObject **address)
{
    if (PyArray_Check(object)) {
        *address = object;
        Py_INCREF(object);
        return PY_SUCCEED;
    }
    else {
        *address = PyArray_FromAny(object, NULL, 0, 0, CARRAY, NULL);
        if (*address == NULL) {
            return PY_FAIL;
        }
        return PY_SUCCEED;
    }
}

/*NUMPY_API
 * Useful to pass as converter function for O& processing in
 * PyArgs_ParseTuple for output arrays
 */
NPY_NO_EXPORT int
PyArray_OutputConverter(PyObject *object, PyArrayObject **address)
{
    if (object == NULL || object == Py_None) {
        *address = NULL;
        return PY_SUCCEED;
    }
    if (PyArray_Check(object)) {
        *address = (PyArrayObject *)object;
        return PY_SUCCEED;
    }
    else {
        PyErr_SetString(PyExc_TypeError,
                        "output must be an array");
        *address = NULL;
        return PY_FAIL;
    }
}

/*NUMPY_API
 * Get intp chunk from sequence
 *
 * This function takes a Python sequence object and allocates and
 * fills in an intp array with the converted values.
 *
 * Remember to free the pointer seq.ptr when done using
 * PyDimMem_FREE(seq.ptr)**
 */
NPY_NO_EXPORT int
PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)
{
    int len;
    int nd;

    seq->ptr = NULL;
    seq->len = 0;
    if (obj == Py_None) {
        return PY_SUCCEED;
    }
    len = PySequence_Size(obj);
    if (len == -1) {
        /* Check to see if it is a number */
        if (PyNumber_Check(obj)) {
            len = 1;
        }
    }
    if (len < 0) {
        PyErr_SetString(PyExc_TypeError,
                        "expected sequence object with len >= 0");
        return PY_FAIL;
    }
    if (len > MAX_DIMS) {
        PyErr_Format(PyExc_ValueError, "sequence too large; "   \
                     "must be smaller than %d", MAX_DIMS);
        return PY_FAIL;
    }
    if (len > 0) {
        seq->ptr = PyDimMem_NEW(len);
        if (seq->ptr == NULL) {
            PyErr_NoMemory();
            return PY_FAIL;
        }
    }
    seq->len = len;
    nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);
    if (nd == -1 || nd != len) {
        PyDimMem_FREE(seq->ptr);
        seq->ptr = NULL;
        return PY_FAIL;
    }
    return PY_SUCCEED;
}

/*NUMPY_API
 * Get buffer chunk from object
 *
 * this function takes a Python object which exposes the (single-segment)
 * buffer interface and returns a pointer to the data segment
 *
 * You should increment the reference count by one of buf->base
 * if you will hang on to a reference
 *
 * You only get a borrowed reference to the object. Do not free the
 * memory...
 */
NPY_NO_EXPORT int
PyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)
{
    Py_ssize_t buflen;

    buf->ptr = NULL;
    buf->flags = BEHAVED;
    buf->base = NULL;
    if (obj == Py_None) {
        return PY_SUCCEED;
    }
    if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {
        PyErr_Clear();
        buf->flags &= ~WRITEABLE;
        if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr),
                                  &buflen) < 0) {
            return PY_FAIL;
        }
    }
    buf->len = (intp) buflen;

    /* Point to the base of the buffer object if present */
    if (PyBuffer_Check(obj)) {
        buf->base = ((PyArray_Chunk *)obj)->base;
    }
    if (buf->base == NULL) {
        buf->base = obj;
    }
    return PY_SUCCEED;
}

/*NUMPY_API
 * Get axis from an object (possibly None) -- a converter function,
 */
NPY_NO_EXPORT int
PyArray_AxisConverter(PyObject *obj, int *axis)
{
    if (obj == Py_None) {
        *axis = MAX_DIMS;
    }
    else {
        *axis = (int) PyInt_AsLong(obj);
        if (PyErr_Occurred()) {
            return PY_FAIL;
        }
    }
    return PY_SUCCEED;
}

/*NUMPY_API
 * Convert an object to true / false
 */
NPY_NO_EXPORT int
PyArray_BoolConverter(PyObject *object, Bool *val)
{
    if (PyObject_IsTrue(object)) {
        *val = TRUE;
    }
    else {
        *val = FALSE;
    }
    if (PyErr_Occurred()) {
        return PY_FAIL;
    }
    return PY_SUCCEED;
}

/*NUMPY_API
 * Convert object to endian
 */
NPY_NO_EXPORT int
PyArray_ByteorderConverter(PyObject *obj, char *endian)
{
    char *str;

    *endian = PyArray_SWAP;
    str = PyString_AsString(obj);
    if (!str) {
        return PY_FAIL;
    }
    if (strlen(str) < 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Byteorder string must be at least length 1");
        return PY_FAIL;
    }
    *endian = str[0];
    if (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE
        && str[0] != PyArray_NATIVE && str[0] != PyArray_IGNORE) {
        if (str[0] == 'b' || str[0] == 'B') {
            *endian = PyArray_BIG;
        }
        else if (str[0] == 'l' || str[0] == 'L') {
            *endian = PyArray_LITTLE;
        }
        else if (str[0] == 'n' || str[0] == 'N') {
            *endian = PyArray_NATIVE;
        }
        else if (str[0] == 'i' || str[0] == 'I') {
            *endian = PyArray_IGNORE;
        }
        else if (str[0] == 's' || str[0] == 'S') {
            *endian = PyArray_SWAP;
        }
        else {
            PyErr_Format(PyExc_ValueError,
                         "%s is an unrecognized byteorder",
                         str);
            return PY_FAIL;
        }
    }
    return PY_SUCCEED;
}

/*NUMPY_API
 * Convert object to sort kind
 */
NPY_NO_EXPORT int
PyArray_SortkindConverter(PyObject *obj, NPY_SORTKIND *sortkind)
{
    char *str;

    *sortkind = PyArray_QUICKSORT;
    str = PyString_AsString(obj);
    if (!str) {
        return PY_FAIL;
    }
    if (strlen(str) < 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Sort kind string must be at least length 1");
        return PY_FAIL;
    }
    if (str[0] == 'q' || str[0] == 'Q') {
        *sortkind = PyArray_QUICKSORT;
    }
    else if (str[0] == 'h' || str[0] == 'H') {
        *sortkind = PyArray_HEAPSORT;
    }
    else if (str[0] == 'm' || str[0] == 'M') {
        *sortkind = PyArray_MERGESORT;
    }
    else {
        PyErr_Format(PyExc_ValueError,
                     "%s is an unrecognized kind of sort",
                     str);
        return PY_FAIL;
    }
    return PY_SUCCEED;
}

/*NUMPY_API
 * Convert object to searchsorted side
 */
NPY_NO_EXPORT int
PyArray_SearchsideConverter(PyObject *obj, void *addr)
{
    NPY_SEARCHSIDE *side = (NPY_SEARCHSIDE *)addr;
    char *str = PyString_AsString(obj);

    if (!str || strlen(str) < 1) {
        PyErr_SetString(PyExc_ValueError,
                        "expected nonempty string for keyword 'side'");
        return PY_FAIL;
    }

    if (str[0] == 'l' || str[0] == 'L') {
        *side = NPY_SEARCHLEFT;
    }
    else if (str[0] == 'r' || str[0] == 'R') {
        *side = NPY_SEARCHRIGHT;
    }
    else {
        PyErr_Format(PyExc_ValueError,
                     "'%s' is an invalid value for keyword 'side'", str);
        return PY_FAIL;
    }
    return PY_SUCCEED;
}

/*****************************
* Other conversion functions
*****************************/

/*NUMPY_API*/
NPY_NO_EXPORT int
PyArray_PyIntAsInt(PyObject *o)
{
    long long_value = -1;
    PyObject *obj;
    static char *msg = "an integer is required";
    PyObject *arr;
    PyArray_Descr *descr;
    int ret;

    if (!o) {
        PyErr_SetString(PyExc_TypeError, msg);
        return -1;
    }
    if (PyInt_Check(o)) {
        long_value = (long) PyInt_AS_LONG(o);
        goto finish;
    } else if (PyLong_Check(o)) {
        long_value = (long) PyLong_AsLong(o);
        goto finish;
    }

    descr = &INT_Descr;
    arr = NULL;
    if (PyArray_Check(o)) {
        if (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {
            PyErr_SetString(PyExc_TypeError, msg);
            return -1;
        }
        Py_INCREF(descr);
        arr = PyArray_CastToType((PyArrayObject *)o, descr, 0);
    }
    if (PyArray_IsScalar(o, Integer)) {
        Py_INCREF(descr);
        arr = PyArray_FromScalar(o, descr);
    }
    if (arr != NULL) {
        ret = *((int *)PyArray_DATA(arr));
        Py_DECREF(arr);
        return ret;
    }
#if (PY_VERSION_HEX >= 0x02050000)
    if (PyIndex_Check(o)) {
        PyObject* value = PyNumber_Index(o);
        long_value = (longlong) PyInt_AsSsize_t(value);
        goto finish;
    }
#endif
    if (o->ob_type->tp_as_number != NULL &&         \
        o->ob_type->tp_as_number->nb_int != NULL) {
        obj = o->ob_type->tp_as_number->nb_int(o);
        if (obj == NULL) {
            return -1;
        }
        long_value = (long) PyLong_AsLong(obj);
        Py_DECREF(obj);
    }
    else if (o->ob_type->tp_as_number != NULL &&                    \
             o->ob_type->tp_as_number->nb_long != NULL) {
        obj = o->ob_type->tp_as_number->nb_long(o);
        if (obj == NULL) {
            return -1;
        }
        long_value = (long) PyLong_AsLong(obj);
        Py_DECREF(obj);
    }
    else {
        PyErr_SetString(PyExc_NotImplementedError,"");
    }

 finish:
    if error_converting(long_value) {
            PyErr_SetString(PyExc_TypeError, msg);
            return -1;
        }

#if (SIZEOF_LONG > SIZEOF_INT)
    if ((long_value < INT_MIN) || (long_value > INT_MAX)) {
        PyErr_SetString(PyExc_ValueError, "integer won't fit into a C int");
        return -1;
    }
#endif
    return (int) long_value;
}

/*NUMPY_API*/
NPY_NO_EXPORT intp
PyArray_PyIntAsIntp(PyObject *o)
{
    longlong long_value = -1;
    PyObject *obj;
    static char *msg = "an integer is required";
    PyObject *arr;
    PyArray_Descr *descr;
    intp ret;

    if (!o) {
        PyErr_SetString(PyExc_TypeError, msg);
        return -1;
    }
    if (PyInt_Check(o)) {
        long_value = (longlong) PyInt_AS_LONG(o);
        goto finish;
    } else if (PyLong_Check(o)) {
        long_value = (longlong) PyLong_AsLongLong(o);
        goto finish;
    }

#if SIZEOF_INTP == SIZEOF_LONG
    descr = &LONG_Descr;
#elif SIZEOF_INTP == SIZEOF_INT
    descr = &INT_Descr;
#else
    descr = &LONGLONG_Descr;
#endif
    arr = NULL;

    if (PyArray_Check(o)) {
        if (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {
            PyErr_SetString(PyExc_TypeError, msg);
            return -1;
        }
        Py_INCREF(descr);
        arr = PyArray_CastToType((PyArrayObject *)o, descr, 0);
    }
    else if (PyArray_IsScalar(o, Integer)) {
        Py_INCREF(descr);
        arr = PyArray_FromScalar(o, descr);
    }
    if (arr != NULL) {
        ret = *((intp *)PyArray_DATA(arr));
        Py_DECREF(arr);
        return ret;
    }

#if (PY_VERSION_HEX >= 0x02050000)
    if (PyIndex_Check(o)) {
        PyObject* value = PyNumber_Index(o);
        if (value == NULL) {
            return -1;
        }
        long_value = (longlong) PyInt_AsSsize_t(value);
        goto finish;
    }
#endif
    if (o->ob_type->tp_as_number != NULL &&                 \
        o->ob_type->tp_as_number->nb_long != NULL) {
        obj = o->ob_type->tp_as_number->nb_long(o);
        if (obj != NULL) {
            long_value = (longlong) PyLong_AsLongLong(obj);
            Py_DECREF(obj);
        }
    }
    else if (o->ob_type->tp_as_number != NULL &&            \
             o->ob_type->tp_as_number->nb_int != NULL) {
        obj = o->ob_type->tp_as_number->nb_int(o);
        if (obj != NULL) {
            long_value = (longlong) PyLong_AsLongLong(obj);
            Py_DECREF(obj);
        }
    }
    else {
        PyErr_SetString(PyExc_NotImplementedError,"");
    }

 finish:
    if error_converting(long_value) {
            PyErr_SetString(PyExc_TypeError, msg);
            return -1;
        }

#if (SIZEOF_LONGLONG > SIZEOF_INTP)
    if ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {
        PyErr_SetString(PyExc_ValueError,
                        "integer won't fit into a C intp");
        return -1;
    }
#endif
    return (intp) long_value;
}

/*NUMPY_API
 * PyArray_IntpFromSequence
 * Returns the number of dimensions or -1 if an error occurred.
 * vals must be large enough to hold maxvals
 */
NPY_NO_EXPORT int
PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
{
    int nd, i;
    PyObject *op, *err;

    /*
     * Check to see if sequence is a single integer first.
     * or, can be made into one
     */
    if ((nd=PySequence_Length(seq)) == -1) {
        if (PyErr_Occurred()) PyErr_Clear();
#if SIZEOF_LONG >= SIZEOF_INTP
        if (!(op = PyNumber_Int(seq))) {
            return -1;
        }
#else
        if (!(op = PyNumber_Long(seq))) {
            return -1;
        }
#endif
        nd = 1;
#if SIZEOF_LONG >= SIZEOF_INTP
        vals[0] = (intp ) PyInt_AsLong(op);
#else
        vals[0] = (intp ) PyLong_AsLongLong(op);
#endif
        Py_DECREF(op);

        /*
         * Check wether there was an error - if the error was an overflow, raise
         * a ValueError instead to be more helpful
         */
        if(vals[0] == -1) {
            err = PyErr_Occurred();
            if (err  &&
                PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) {
                PyErr_SetString(PyExc_ValueError,
                        "Maximum allowed dimension exceeded");
            }
            if(err != NULL) {
                return -1;
            }
        }
    }
    else {
        for (i = 0; i < MIN(nd,maxvals); i++) {
            op = PySequence_GetItem(seq, i);
            if (op == NULL) {
                return -1;
            }
#if SIZEOF_LONG >= SIZEOF_INTP
            vals[i]=(intp )PyInt_AsLong(op);
#else
            vals[i]=(intp )PyLong_AsLongLong(op);
#endif
            Py_DECREF(op);

            /*
             * Check wether there was an error - if the error was an overflow,
             * raise a ValueError instead to be more helpful
             */
            if(vals[0] == -1) {
                err = PyErr_Occurred();
                if (err  &&
                    PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) {
                    PyErr_SetString(PyExc_ValueError,
                            "Maximum allowed dimension exceeded");
                }
                if(err != NULL) {
                    return -1;
                }
            }
        }
    }
    return nd;
}

/*NUMPY_API
 * Typestr converter
 */
NPY_NO_EXPORT int
PyArray_TypestrConvert(int itemsize, int gentype)
{
    int newtype = gentype;

    if (gentype == PyArray_GENBOOLLTR) {
        if (itemsize == 1) {
            newtype = PyArray_BOOL;
        }
        else {
            newtype = PyArray_NOTYPE;
        }
    }
    else if (gentype == PyArray_SIGNEDLTR) {
        switch(itemsize) {
        case 1:
            newtype = PyArray_INT8;
            break;
        case 2:
            newtype = PyArray_INT16;
            break;
        case 4:
            newtype = PyArray_INT32;
            break;
        case 8:
            newtype = PyArray_INT64;
            break;
#ifdef PyArray_INT128
        case 16:
            newtype = PyArray_INT128;
            break;
#endif
        default:
            newtype = PyArray_NOTYPE;
        }
    }
    else if (gentype == PyArray_UNSIGNEDLTR) {
        switch(itemsize) {
        case 1:
            newtype = PyArray_UINT8;
            break;
        case 2:
            newtype = PyArray_UINT16;
            break;
        case 4:
            newtype = PyArray_UINT32;
            break;
        case 8:
            newtype = PyArray_UINT64;
            break;
#ifdef PyArray_INT128
        case 16:
            newtype = PyArray_UINT128;
            break;
#endif
        default:
            newtype = PyArray_NOTYPE;
            break;
        }
    }
    else if (gentype == PyArray_FLOATINGLTR) {
        switch(itemsize) {
        case 4:
            newtype = PyArray_FLOAT32;
            break;
        case 8:
            newtype = PyArray_FLOAT64;
            break;
#ifdef PyArray_FLOAT80
        case 10:
            newtype = PyArray_FLOAT80;
            break;
#endif
#ifdef PyArray_FLOAT96
        case 12:
            newtype = PyArray_FLOAT96;
            break;
#endif
#ifdef PyArray_FLOAT128
        case 16:
            newtype = PyArray_FLOAT128;
            break;
#endif
        default:
            newtype = PyArray_NOTYPE;
        }
    }
    else if (gentype == PyArray_COMPLEXLTR) {
        switch(itemsize) {
        case 8:
            newtype = PyArray_COMPLEX64;
            break;
        case 16:
            newtype = PyArray_COMPLEX128;
            break;
#ifdef PyArray_FLOAT80
        case 20:
            newtype = PyArray_COMPLEX160;
            break;
#endif
#ifdef PyArray_FLOAT96
        case 24:
            newtype = PyArray_COMPLEX192;
            break;
#endif
#ifdef PyArray_FLOAT128
        case 32:
            newtype = PyArray_COMPLEX256;
            break;
#endif
        default:
            newtype = PyArray_NOTYPE;
        }
    }
    return newtype;
}

/* Lifted from numarray */
/* TODO: not documented */
/*NUMPY_API
  PyArray_IntTupleFromIntp
*/
NPY_NO_EXPORT PyObject *
PyArray_IntTupleFromIntp(int len, intp *vals)
{
    int i;
    PyObject *intTuple = PyTuple_New(len);

    if (!intTuple) {
        goto fail;
    }
    for (i = 0; i < len; i++) {
#if SIZEOF_INTP <= SIZEOF_LONG
        PyObject *o = PyInt_FromLong((long) vals[i]);
#else
        PyObject *o = PyLong_FromLongLong((longlong) vals[i]);
#endif
        if (!o) {
            Py_DECREF(intTuple);
            intTuple = NULL;
            goto fail;
        }
        PyTuple_SET_ITEM(intTuple, i, o);
    }

 fail:
    return intTuple;
}


text: sudo apt-get install --only-upgrade unzip=6.0-4+deb6u3 -y

redpajama_set_name: RedPajamaGithub


text:
require 'spec_helper'

describe Devise::Vero::Sender do
  describe '#deliver' do
    let(:instance) { Class.new.new }
    let(:token) { SecureRandom.hex }
    let(:notification) { :confirmation_instructions }

    subject { described_class.new(instance) }

    it 'calls the track method' do
      allow(instance).to receive(:track!)
      subject.deliver(notification, token)
      expect(instance).to have_received(:track!)
        .with(notification, token: token, data: [token])
    end
  end

  describe '#unsubscribe' do
    let(:instance) { Class.new.new }
    let(:vero_context) { Vero::Context.new }

    subject { described_class.new(instance) }

    it 'calls the unsubscribe method from vero_context' do
      expect(vero_context).to receive(:unsubscribe!) {}

      allow(instance).to receive(:with_default_vero_context) { vero_context }
      subject.unsubscribe
    end
  end
end


text:
<?php

header("Content-Type: text/Text; charset=ISO-8859-1 Cache-Control: no-store, no-cache, must-revalidate");
header ("Expires: Fri, 14 Mar 1980 20:53:00 GMT"); //la pagina expira en fecha pasada
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //ultima actualizacion ahora cuando la cargamos
header ("Cache-Control: no-cache, must-revalidate"); //no guardar en CACHE
header ("Pragma: no-cache"); //PARANOIA, NO GUARDAR EN CACHE
include("bd.php");

$sql="SELECT cveBanco,descripcion,IF(estatus=1,'Activado','Desactivado') AS estatus ".
"FROM cbancos ORDER BY estatus ASC;";

$campos = $bd->Execute($sql);

	$respuesta = "[";
 	$total=count($campos);
	if($total==0)
	{	$respuesta .= "{total: '0'}";
		}else{
		foreach($campos as $campo){
			$respuesta .= "{total:'".$total."',cveBanco: '" . $campo["cveBanco"] . "', descripcion: '" . $campo["descripcion"] ."', estatus: '" . $campo["estatus"] ."', empresa: '" . $campo["empresa"] ."'},";
		}
		$respuesta = substr($respuesta, 0, strlen($respuesta)-1);
	}
$respuesta .= "]";
echo $respuesta;

?>


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Uses of Class com.buffalokiwi.aerodrome.jet.orders.ReturnMerchantSkuRec.Builder (Aerodrome 1.0-SNAPSHOT API)</title>
<meta name="date" content="2017-02-12">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Skip navigation links

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes

Uses of Class
com.buffalokiwi.aerodrome.jet.orders.ReturnMerchantSkuRec.Builder

Packages that use ReturnMerchantSkuRec.Builder

Package
Description

com.buffalokiwi.aerodrome.jet.orders

Uses of ReturnMerchantSkuRec.Builder in com.buffalokiwi.aerodrome.jet.orders

Methods in com.buffalokiwi.aerodrome.jet.orders that return ReturnMerchantSkuRec.Builder

Modifier and Type
Method and Description

ReturnMerchantSkuRec.Builder
ReturnMerchantSkuRec.Builder.setAltOrderItemId(String altOrderItemId)

If an alt_order_item_id has been associated with the order_item_id via
 the order accept message, this may be passed instead of the
 order_item_id field.

ReturnMerchantSkuRec.Builder
ReturnMerchantSkuRec.Builder.setMerchantsku(String merchantsku)

The merchant SKU that is being returned

ReturnMerchantSkuRec.Builder
ReturnMerchantSkuRec.Builder.setOrderItemId(String orderItemId)

Jet's unique identifier for an item in a merchant order.

ReturnMerchantSkuRec.Builder
ReturnMerchantSkuRec.Builder.setQuantity(int quantity)

The quantity of the merchant SKU that is being returned

ReturnMerchantSkuRec.Builder
ReturnMerchantSkuRec.Builder.setReason(ReturnReason reason)

The reason the customer is returning the item

ReturnMerchantSkuRec.Builder
ReturnMerchantSkuRec.Builder.setRefundAmount(RefundAmountRec refundAmount)

The amount the retailer is willing to refund to the customer

ReturnMerchantSkuRec.Builder
ReturnMerchantSkuRec.Builder.setTitle(String title)

The short description of the merchant SKU being returned

Skip navigation links

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes

Copyright © 2017. All rights reserved.


text:
/*
 * ModeShape (http://www.modeshape.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.modeshape.sequencer.msoffice.excel;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFComment;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

/**
 * Extracts data and some metadata from Excel files
 */
public class ExcelMetadataReader {

    /** The character to output after each row. */
    private static final char ROW_DELIMITER_CHAR = '\n';
    /** The character to output after each cell (column). */
    private static final char CELL_DELIMITER_CHAR = '\t';

    public static ExcelMetadata instance( InputStream stream ) throws IOException {
        ExcelMetadata metadata = new ExcelMetadata();
        HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(stream));

        List<ExcelSheetMetadata> sheets = new ArrayList<ExcelSheetMetadata>();

        for (int sheetInd = 0; sheetInd < wb.getNumberOfSheets(); sheetInd++) {
            ExcelSheetMetadata meta = new ExcelSheetMetadata();
            meta.setName(wb.getSheetName(sheetInd));
            sheets.add(meta);

            HSSFSheet worksheet = wb.getSheetAt(sheetInd);
            int lastRowNum = worksheet.getLastRowNum();

            StringBuilder buff = new StringBuilder();
            for (int rowNum = worksheet.getFirstRowNum(); rowNum <= lastRowNum; rowNum++) {
                HSSFRow row = worksheet.getRow(rowNum);

                // Empty rows are returned as null
                if (row == null) {
                    continue;
                }

                int lastCellNum = row.getLastCellNum();
                for (int cellNum = row.getFirstCellNum(); cellNum < lastCellNum; cellNum++) {
                    HSSFCell cell = row.getCell(cellNum);

                    // Undefined cells are returned as null
                    if (cell == null) {
                        continue;
                    }

                    /*
                     * Builds a string of body content from all string, numeric,
                     * and formula values in the body of each worksheet.
                     *
                     *  This code currently duplicates the POI 3.1 ExcelExtractor behavior of
                     *  combining the body text from all worksheets into a single string.
                     */
                    switch (cell.getCellType()) {
                        case HSSFCell.CELL_TYPE_STRING:
                            buff.append(cell.getRichStringCellValue().getString());
                            break;
                        case HSSFCell.CELL_TYPE_NUMERIC:
                            buff.append(cell.getNumericCellValue());
                            break;
                        case HSSFCell.CELL_TYPE_FORMULA:
                            buff.append(cell.getCellFormula());
                            break;
                    }

                    HSSFComment comment = cell.getCellComment();
                    if (comment != null) {
                        // Filter out row delimiter characters from comment
                        String commentText = comment.getString().getString().replace(ROW_DELIMITER_CHAR, ' ');

                        buff.append(" [");
                        buff.append(commentText);
                        buff.append(" by ");
                        buff.append(comment.getAuthor());
                        buff.append(']');
                    }

                    if (cellNum < lastCellNum - 1) {
                        buff.append(CELL_DELIMITER_CHAR);
                    } else {
                        buff.append(ROW_DELIMITER_CHAR);
                    }
                }
            }
            meta.setText(buff.toString());
        }

        metadata.setSheets(sheets);
        metadata.setMetadata(wb.getSummaryInformation());
        return metadata;
    }
}


text:
require 'spec_helper'

describe service('crond') do
  it { should be_running }
  it { should be_enabled }
end


text:
[![Travis](https://img.shields.io/travis/frictionlessdata/tabulator-py/master.svg)](https://travis-ci.org/frictionlessdata/tabulator-py)
[![Coveralls](http://img.shields.io/coveralls/frictionlessdata/tabulator-py.svg?branch=master)](https://coveralls.io/r/frictionlessdata/tabulator-py?branch=master)
[![PyPi](https://img.shields.io/pypi/v/tabulator.svg)](https://pypi.python.org/pypi/tabulator)
[![Github](https://img.shields.io/badge/github-master-brightgreen)](https://github.com/frictionlessdata/tabulator-py)
[![Gitter](https://img.shields.io/gitter/room/frictionlessdata/chat.svg)](https://gitter.im/frictionlessdata/chat)

A library for reading and writing tabular data (csv/xls/json/etc).

> **[Important Notice]** We have released [Frictionless Framework](https://github.com/frictionlessdata/frictionless-py). This framework is logical continuation of `tabulator` that was extended to be a complete data solution. The change in not breaking for the existing software so no actions are required. Please read the [Migration Guide](https://framework.frictionlessdata.io/docs/development/migration) from `tabulator` to Frictionless Framework.
> - we continue to bug-fix `tabulator@1.x` in this [repository](https://github.com/frictionlessdata/tabulator-py) as well as it's available on [PyPi](https://pypi.org/project/tabulator/) as it was before
> - please note that `frictionless@3.x` version's API, we're working on at the moment, is not stable
> - we will release `frictionless@4.x` by the end of 2020 to be the first SemVer/stable version

## Features

- **Supports most common tabular formats**: CSV, XLS, ODS, JSON, Google Sheets, SQL, and others. See complete list [below](#supported-file-formats).
- **Loads local and remote data**: Supports HTTP, FTP and S3.
- **Low memory usage**: Only the current row is kept in memory, so you can
  large datasets.
- **Supports compressed files**: Using ZIP or GZIP algorithms.
- **Extensible**: You can add support for custom file formats and loaders (e.g.
  FTP).

## Contents

<!--TOC-->

  - [Getting started](#getting-started)
    - [Installation](#installation)
    - [Running on CLI](#running-on-cli)
    - [Running on Python](#running-on-python)
  - [Documentation](#documentation)
    - [Working with Stream](#working-with-stream)
    - [Supported schemes](#supported-schemes)
    - [Supported file formats](#supported-file-formats)
    - [Custom file sources and formats](#custom-file-sources-and-formats)
  - [API Reference](#api-reference)
    - [`cli`](#cli)
    - [`Stream`](#stream)
    - [`Loader`](#loader)
    - [`Parser`](#parser)
    - [`Writer`](#writer)
    - [`validate`](#validate)
    - [`TabulatorException`](#tabulatorexception)
    - [`SourceError`](#sourceerror)
    - [`SchemeError`](#schemeerror)
    - [`FormatError`](#formaterror)
    - [`EncodingError`](#encodingerror)
    - [`CompressionError`](#compressionerror)
    - [`IOError`](#ioerror)
    - [`LoadingError`](#loadingerror)
    - [`HTTPError`](#httperror)
  - [Contributing](#contributing)
  - [Changelog](#changelog)

<!--TOC-->

## Getting started

### Installation

```bash
$ pip install tabulator
```

### Running on CLI

Tabulator ships with a simple CLI called `tabulator` to read tabular data. For
example:

```bash
$ tabulator https://github.com/frictionlessdata/tabulator-py/raw/4c1b3943ac98be87b551d87a777d0f7ca4904701/data/table.csv.gz
id,name
1,english
2,中国人
```

You can see all supported options by running `tabulator --help`.

### Running on Python

```python
from tabulator import Stream

with Stream('data.csv', headers=1) as stream:
    stream.headers # [header1, header2, ..]
    for row in stream:
        print(row)  # [value1, value2, ..]
```

You can find other examples in the [examples][examples-dir] directory.

## Documentation

In the following sections, we'll walk through some usage examples of
this library. All examples were tested with Python 3.6, but should
run fine with Python 3.3+.

### Working with Stream

The `Stream` class represents a tabular stream. It takes the file path as the
`source` argument. For example:

```
<scheme>://path/to/file.<format>
```

It uses this path to determine the file format (e.g. CSV or XLS) and scheme
(e.g. HTTP or postgresql). It also supports format extraction from URLs like `http://example.com?format=csv`. If necessary, you also can define these explicitly.

Let's try it out. First, we create a `Stream` object passing the path to a CSV file.

```python
import tabulator

stream = tabulator.Stream('data.csv')
```

At this point, the file haven't been read yet. Let's open the stream so we can
read the contents.

```python
try:
    stream.open()
except tabulator.TabulatorException as e:
    pass  # Handle exception
```

This will open the underlying data stream, read a small sample to detect the
file encoding, and prepare the data to be read. We catch
`tabulator.TabulatorException` here, in case something goes wrong.

We can now read the file contents. To iterate over each row, we do:

```python
for row in stream.iter():
    print(row)  # [value1, value2, ...]
```

The `stream.iter()` method will return each row data as a list of values. If
you prefer, you could call `stream.iter(keyed=True)` instead, which returns a
dictionary with the column names as keys. Either way, this method keeps only a
single row in memory at a time. This means it can handle handle large files
without consuming too much memory.

If you want to read the entire file, use `stream.read()`. It accepts the same
arguments as `stream.iter()`, but returns all rows at once.

```python
stream.reset()
rows = stream.read()
```

Notice that we called `stream.reset()` before reading the rows. This is because
internally, tabulator only keeps a pointer to its current location in the file.
If we didn't reset this pointer, we would read starting from where we stopped.
For example, if we ran `stream.read()` again, we would get an empty list, as
the internal file pointer is at the end of the file (because we've already read
it all). Depending on the file location, it might be necessary to download the
file again to rewind (e.g. when the file was loaded from the web).

After we're done, close the stream with:

```python
stream.close()
```

The entire example looks like:

```python
import tabulator

stream = tabulator.Stream('data.csv')
try:
    stream.open()
except tabulator.TabulatorException as e:
    pass  # Handle exception

for row in stream.iter():
    print(row)  # [value1, value2, ...]

stream.reset()  # Rewind internal file pointer
rows = stream.read()

stream.close()
```

It could be rewritten to use Python's context manager interface as:

```python
import tabulator

try:
    with tabulator.Stream('data.csv') as stream:
        for row in stream.iter():
            print(row)

        stream.reset()
        rows = stream.read()
except tabulator.TabulatorException as e:
    pass
```

This is the preferred way, as Python closes the stream automatically, even if some exception was thrown along the way.

The full API documentation is available as docstrings in the [Stream source code][stream.py].

#### Headers

By default, tabulator considers that all file rows are values (i.e. there is no
header).

```python
with Stream([['name', 'age'], ['Alex', 21]]) as stream:
  stream.headers # None
  stream.read() # [['name', 'age'], ['Alex', 21]]
```

If you have a header row, you can use the `headers` argument with the its row
number (starting from 1).

```python
# Integer
with Stream([['name', 'age'], ['Alex', 21]], headers=1) as stream:
  stream.headers # ['name', 'age']
  stream.read() # [['Alex', 21]]
```

You can also pass a lists of strings to define the headers explicitly:

```python
with Stream([['Alex', 21]], headers=['name', 'age']) as stream:
  stream.headers # ['name', 'age']
  stream.read() # [['Alex', 21]]
```

Tabulator also supports multiline headers for the `xls` and `xlsx` formats.

```python
with Stream('data.xlsx', headers=[1, 3], fill_merged_cells=True) as stream:
  stream.headers # ['header from row 1-3']
  stream.read() # [['value1', 'value2', 'value3']]
```

#### Encoding

You can specify the file encoding (e.g. `utf-8` and `latin1`) via the `encoding`
argument.

```python
with Stream(source, encoding='latin1') as stream:
  stream.read()
```

If this argument isn't set, Tabulator will try to infer it from the data. If you
get a `UnicodeDecodeError` while loading a file, try setting the encoding to
`utf-8`.

#### Compression (Python3-only)

Tabulator supports both ZIP and GZIP compression methods. By default it'll infer from the file name:

```python
with Stream('http://example.com/data.csv.zip') as stream:
  stream.read()
```

You can also set it explicitly:

```python
with Stream('data.csv.ext', compression='gz') as stream:
  stream.read()
```
**Options**

- **filename**: filename in zip file to process (default is first file)

#### Allow html

The `Stream` class raises `tabulator.exceptions.FormatError` if it detects HTML
contents. This helps avoiding the relatively common mistake of trying to load a
CSV file inside an HTML page, for example on GitHub.

You can disable this behaviour using the `allow_html` option:

```python
with Stream(source_with_html, allow_html=True) as stream:
  stream.read() # no exception on open
```

#### Sample size

To detect the file's headers, and run other checks like validating that the file
doesn't contain HTML, Tabulator reads a sample of rows on the `stream.open()`
method. This data is available via the `stream.sample` property. The number of
rows used can be defined via the `sample_size` parameters (defaults to 100).

```python
with Stream(two_rows_source, sample_size=1) as stream:
  stream.sample # only first row
  stream.read() # first and second rows
```

You can disable this by setting `sample_size` to zero. This way, no data will be
read on `stream.open()`.

#### Bytes sample size

Tabulator needs to read a part of the file to infer its encoding. The
`bytes_sample_size` arguments controls how many bytes will be read for this
detection (defaults to 10000).

```python
source = 'data/special/latin1.csv'
with Stream(source) as stream:
    stream.encoding # 'iso8859-2'
```

You can disable this by setting `bytes_sample_size` to zero, in which case it'll
use the machine locale's default encoding.

#### Ignore blank headers

When `True`, tabulator will ignore columns that have blank headers (defaults to
`False`).

```python
# Default behaviour
source = 'text://header1,,header3\nvalue1,value2,value3'
with Stream(source, format='csv', headers=1) as stream:
    stream.headers # ['header1', '', 'header3']
    stream.read(keyed=True) # {'header1': 'value1', '': 'value2', 'header3': 'value3'}

# Ignoring columns with blank headers
source = 'text://header1,,header3\nvalue1,value2,value3'
with Stream(source, format='csv', headers=1, ignore_blank_headers=True) as stream:
    stream.headers # ['header1', 'header3']
    stream.read(keyed=True) # {'header1': 'value1', 'header3': 'value3'}
```

#### Ignore listed/not-listed headers

The option is similar to the `ignore_blank_headers`. It removes arbitrary columns from the data based on the corresponding column names:

```python
# Ignore listed headers (omit columns)
source = 'text://header1,header2,header3\nvalue1,value2,value3'
with Stream(source, format='csv', headers=1, ignore_listed_headers=['header2']) as stream:
    assert stream.headers == ['header1', 'header3']
    assert stream.read(keyed=True) == [
        {'header1': 'value1', 'header3': 'value3'},
    ]

# Ignore NOT listed headers (pick colums)
source = 'text://header1,header2,header3\nvalue1,value2,value3'
with Stream(source, format='csv', headers=1, ignore_not_listed_headers=['header2']) as stream:
    assert stream.headers == ['header2']
    assert stream.read(keyed=True) == [
        {'header2': 'value2'},
    ]
```

#### Force strings

When `True`, all rows' values will be converted to strings (defaults to
`False`). `None` values will be converted to empty strings.

```python
# Default behaviour
with Stream([['string', 1, datetime.datetime(2017, 12, 1, 17, 00)]]) as stream:
  stream.read() # [['string', 1, datetime.dateime(2017, 12, 1, 17, 00)]]

# Forcing rows' values as strings
with Stream([['string', 1]], force_strings=True) as stream:
  stream.read() # [['string', '1', '2017-12-01 17:00:00']]
```

#### Force parse

When `True`, don't raise an exception when parsing a malformed row, but simply
return an empty row. Otherwise, tabulator raises
`tabulator.exceptions.SourceError` when a row can't be parsed. Defaults to `False`.

```python
# Default behaviour
with Stream([[1], 'bad', [3]]) as stream:
  stream.read() # raises tabulator.exceptions.SourceError

# With force_parse
with Stream([[1], 'bad', [3]], force_parse=True) as stream:
  stream.read() # [[1], [], [3]]
```

#### Skip rows

List of row numbers and/or strings to skip.
If it's a string, all rows that begin with it will be skipped (e.g. '#' and '//').
If it's the empty string, all rows that begin with an empty column will be skipped.

```python
source = [['John', 1], ['Alex', 2], ['#Sam', 3], ['Mike', 4], ['John', 5]]
with Stream(source, skip_rows=[1, 2, -1, '#']) as stream:
  stream.read() # [['Mike', 4]]
```

If the `headers` parameter is also set to be an integer, it will use the first not skipped row as a headers.

```python
source = [['#comment'], ['name', 'order'], ['John', 1], ['Alex', 2]]
with Stream(source, headers=1, skip_rows=['#']) as stream:
  stream.headers # [['name', 'order']]
  stream.read() # [['Jogn', 1], ['Alex', 2]]
```

#### Post parse

List of functions that can filter or transform rows after they are parsed. These
functions receive the `extended_rows` containing the row's number, headers
list, and the row values list. They then process the rows, and yield or discard
them, modified or not.

```python
def skip_odd_rows(extended_rows):
    for row_number, headers, row in extended_rows:
        if not row_number % 2:
            yield (row_number, headers, row)

def multiply_by_two(extended_rows):
    for row_number, headers, row in extended_rows:
        doubled_row = list(map(lambda value: value * 2, row))
        yield (row_number, headers, doubled_row)

rows = [
  [1],
  [2],
  [3],
  [4],
]
with Stream(rows, post_parse=[skip_odd_rows, multiply_by_two]) as stream:
  stream.read() # [[4], [8]]
```

These functions are applied in order, as a simple data pipeline. In the example
above, `multiply_by_two` just sees the rows yielded by `skip_odd_rows`.

#### Keyed and extended rows

The methods `stream.iter()` and `stream.read()` accept the `keyed` and
`extended` flag arguments to modify how the rows are returned.

By default, every row is returned as a list of its cells values:

```python
with Stream([['name', 'age'], ['Alex', 21]]) as stream:
  stream.read() # [['Alex', 21]]
```

With `keyed=True`, the rows are returned as dictionaries, mapping the column names to their values in the row:

```python
with Stream([['name', 'age'], ['Alex', 21]]) as stream:
  stream.read(keyed=True) # [{'name': 'Alex', 'age': 21}]
```

And with `extended=True`, the rows are returned as a tuple of `(row_number,
headers, row)`, there `row_number` is the current row number (starting from 1),
`headers` is a list with the headers names, and `row` is a list with the rows
values:

```python
with Stream([['name', 'age'], ['Alex', 21]]) as stream:
  stream.read(extended=True) # (1, ['name', 'age'], ['Alex', 21])
```

### Supported schemes

#### s3

It loads data from AWS S3. For private files you should provide credentials supported by the `boto3` library, for example, corresponding environment variables. Read more about [configuring `boto3`](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html).

```python
stream = Stream('s3://bucket/data.csv')
```

**Options**

- **s3\_endpoint\_url** - the endpoint URL to use. By default it's `https://s3.amazonaws.com`. For complex use cases, for example, `goodtables`'s runs on a data package this option can be provided as an environment variable `S3_ENDPOINT_URL`.

#### file

The default scheme, a file in the local filesystem.

```python
stream = Stream('data.csv')
```

#### http/https/ftp/ftps

> In Python 2, `tabulator` can't stream remote data sources because of a limitation in the underlying libraries. The whole data source will be loaded to the memory. In Python 3 there is no such problem and remote files are streamed.

```python
stream = Stream('https://example.com/data.csv')
```

**Options**

- **http\_session** - a `requests.Session` object. Read more in the [requests docs][requests-session].
- **http\_stream** - Enables or disables HTTP streaming, when possible (enabled by default). Disable it if you'd like to preload the whole file into memory.
- **http\_timeout** - This timeout will be used for a `requests` session construction.

#### stream

The source is a file-like Python object.

```python
with open('data.csv') as fp:
    stream = Stream(fp)
```

#### text

The source is a string containing the tabular data. Both `scheme` and `format`
must be set explicitly, as it's not possible to infer them.

```python
stream = Stream(
    'name,age\nJohn, 21\n',
    scheme='text',
    format='csv'
)
```

### Supported file formats

In this section, we'll describe the supported file formats, and their respective
configuration options and operations. Some formats only support read operations,
while others support both reading and writing.

#### csv (read & write)

```python
stream = Stream('data.csv', delimiter=',')
```

**Options**

It supports all options from the Python CSV library. Check [their
documentation][pydoc-csv] for more information.

#### xls/xlsx (read & write)

> Tabulator is unable to stream `xls` files, so the entire file is loaded in
> memory. Streaming is supported for `xlsx` files.

```python
stream = Stream('data.xls', sheet=1)
```

**Options**

- **sheet**: Sheet name or number (starting from 1).
- **workbook_cache**: An empty dictionary to handle workbook caching. If provided, `tabulator` will fill the dictionary with `source: tmpfile_path` pairs for remote workbooks. Each workbook will be downloaded only once and all the temporary files will be deleted on the process exit. Defauts: None
- **fill_merged_cells**: if `True` it will unmerge and fill all merged cells by
  a visible value. With this option enabled the parser can't stream data and
  load the whole document into memory.
- **preserve_formatting**: if `True` it will try to preserve text formatting of numeric and temporal cells returning it as strings according to how it looks in a spreadsheet (EXPERIMETAL)
- **adjust_floating_point_error**: if `True` it will correct the Excel behaviour regarding floating point numbers

#### ods (read only)

> This format is not included to package by default. To use it please install `tabulator` with an `ods` extras: `$ pip install tabulator[ods]`

Source should be a valid Open Office document.

```python
stream = Stream('data.ods', sheet=1)
```

**Options**

- **sheet**: Sheet name or number (starting from 1)

#### gsheet (read only)

A publicly-accessible Google Spreadsheet.

```python
stream = Stream('https://docs.google.com/spreadsheets/d/<id>?usp=sharing')
stream = Stream('https://docs.google.com/spreadsheets/d/<id>edit#gid=<gid>')
```

#### sql (read & write)

Any database URL supported by [sqlalchemy][sqlalchemy].

```python
stream = Stream('postgresql://name:pass@host:5432/database', table='data')
```

**Options**

- **table (required)**: Database table name
- **order_by**: SQL expression for row ordering (e.g. `name DESC`)

#### Data Package (read only)

> This format is not included to package by default. You can enable it by
> installing tabulator using `pip install tabulator[datapackage]`.

A [Tabular Data Package][tdp].

```python
stream = Stream('datapackage.json', resource=1)
```

**Options**

- **resource**: Resource name or index (starting from 0)

#### inline (read only)

Either a list of lists, or a list of dicts mapping the column names to their
respective values.

```python
stream = Stream([['name', 'age'], ['John', 21], ['Alex', 33]])
stream = Stream([{'name': 'John', 'age': 21}, {'name': 'Alex', 'age': 33}])
```

#### json (read & write)

JSON document containing a list of lists, or a list of dicts mapping the column
names to their respective values (see the `inline` format for an example).

```python
stream = Stream('data.json', property='key1.key2')
```

**Options**

- **property**: JSON Path to the property containing the tabular data. For example, considering the JSON `{"response": {"data": [...]}}`, the `property` should be set to `response.data`.
- **keyed** (write): Save as array of arrays (default) or as array of dicts (keyed).

#### ndjson (read only)

```python
stream = Stream('data.ndjson')
```

#### tsv (read only)

```python
stream = Stream('data.tsv')
```

#### html (read only)

> This format is not included to package by default. To use it please install `tabulator` with the `html` extra: `$ pip install tabulator[html]`

An HTML table element residing inside an HTML document.

Supports simple tables (no merged cells) with any legal combination of the td, th, tbody & thead elements.

Usually `foramt='html'` would need to be specified explicitly as web URLs don't always use the `.html` extension.

```python
stream = Stream('http://example.com/some/page.aspx', format='html' selector='.content .data table#id1', raw_html=True)
```

**Options**

- **selector**: CSS selector for specifying which `table` element to extract. By default it's `table`, which takes the first `table` element in the document. If empty, will assume the entire page is the table to be extracted (useful with some Excel formats).

- **raw_html**: False (default) to extract the textual contents of each cell. True to return the inner html without modification.

### Custom file sources and formats

Tabulator is written with extensibility in mind, allowing you to add support for
new tabular file formats, schemes (e.g. ssh), and writers (e.g. MongoDB). There
are three components that allow this:

* Loaders
  * Loads a stream from some location (e.g. ssh)
* Parsers
  * Parses a stream of tabular data in some format (e.g. xls)
* Writers
  * Writes tabular data to some destination (e.g. MongoDB)

In this section, we'll see how to write custom classes to extend any of these components.

#### Custom loaders

You can add support for a new scheme (e.g. ssh) by creating a custom loader.
Custom loaders are implemented by inheriting from the `Loader` class, and
implementing its methods. This loader can then be used by `Stream` to load data
by passing it via the `custom_loaders={'scheme': CustomLoader}` argument.

The skeleton of a custom loader looks like:

```python
from tabulator import Loader

class CustomLoader(Loader):
  options = []

  def __init__(self, bytes_sample_size, **options):
      pass

  def load(self, source, mode='t', encoding=None):
      # load logic

with Stream(source, custom_loaders={'custom': CustomLoader}) as stream:
  stream.read()
```

You can see examples of how the loaders are implemented by looking in the
`tabulator.loaders` module.

#### Custom parsers

You can add support for a new file format by creating a custom parser. Similarly
to custom loaders, custom parsers are implemented by inheriting from the
`Parser` class, and implementing its methods. This parser can then be used by
`Stream` to parse data by passing it via the `custom_parsers={'format':
CustomParser}` argument.

The skeleton of a custom parser looks like:

```python
from tabulator import Parser

class CustomParser(Parser):
    options = []

    def __init__(self, loader, force_parse, **options):
        self.__loader = loader

    def open(self, source, encoding=None):
        # open logic

    def close(self):
        # close logic

    def reset(self):
        # reset logic

    @property
    def closed(self):
        return False

    @property
    def extended_rows(self):
        # extended rows logic

with Stream(source, custom_parsers={'custom': CustomParser}) as stream:
  stream.read()
```

You can see examples of how parsers are implemented by looking in the
`tabulator.parsers` module.

#### Custom writers

You can add support to write files in a specific format by creating a custom
writer. The custom writers are implemented by inheriting from the base `Writer`
class, and implementing its methods. This writer can then be used by `Stream` to
write data via the `custom_writers={'format': CustomWriter}` argument.

The skeleton of a custom writer looks like:

```python
from tabulator import Writer

class CustomWriter(Writer):
  options = []

  def __init__(self, **options):
      pass

  def write(self, source, target, headers=None, encoding=None):
      # write logic

with Stream(source, custom_writers={'custom': CustomWriter}) as stream:
  stream.save(target)
```

You can see examples of how parsers are implemented by looking in the
`tabulator.writers` module.

## API Reference

### `cli`
```python
cli(source, limit, **options)
```
Command-line interface

```
Usage: tabulator [OPTIONS] SOURCE

Options:
  --headers INTEGER
  --scheme TEXT
  --format TEXT
  --encoding TEXT
  --limit INTEGER
  --sheet TEXT/INTEGER (excel)
  --fill-merged-cells BOOLEAN (excel)
  --preserve-formatting BOOLEAN (excel)
  --adjust-floating-point-error BOOLEAN (excel)
  --table TEXT (sql)
  --order_by TEXT (sql)
  --resource TEXT/INTEGER (datapackage)
  --property TEXT (json)
  --keyed BOOLEAN (json)
  --version          Show the version and exit.
  --help             Show this message and exit.
```

### `Stream`
```python
Stream(self,
       source,
       headers=None,
       scheme=None,
       format=None,
       encoding=None,
       compression=None,
       allow_html=False,
       sample_size=100,
       bytes_sample_size=10000,
       ignore_blank_headers=False,
       ignore_listed_headers=None,
       ignore_not_listed_headers=None,
       multiline_headers_joiner=' ',
       multiline_headers_duplicates=False,
       force_strings=False,
       force_parse=False,
       pick_rows=None,
       skip_rows=None,
       pick_fields=None,
       skip_fields=None,
       pick_columns=None,
       skip_columns=None,
       post_parse=[],
       custom_loaders={},
       custom_parsers={},
       custom_writers={},
       **options)
```
Stream of tabular data.

This is the main `tabulator` class. It loads a data source, and allows you
to stream its parsed contents.

__Arguments__

    source (str):
        Path to file as ``<scheme>://path/to/file.<format>``.
        If not explicitly set, the scheme (file, http, ...) and
        format (csv, xls, ...) are inferred from the source string.

    headers (Union[int, List[int], List[str]], optional):
        Either a row
        number or list of row numbers (in case of multi-line headers) to be
        considered as headers (rows start counting at 1), or the actual
        headers defined a list of strings. If not set, all rows will be
        treated as containing values.

    scheme (str, optional):
        Scheme for loading the file (file, http, ...).
        If not set, it'll be inferred from `source`.

    format (str, optional):
        File source's format (csv, xls, ...). If not
        set, it'll be inferred from `source`. inferred

    encoding (str, optional):
        Source encoding. If not set, it'll be inferred.

    compression (str, optional):
        Source file compression (zip, ...). If not set, it'll be inferred.

    pick_rows (List[Union[int, str, dict]], optional):
        The same as `skip_rows` but it's for picking rows instead of skipping.

    skip_rows (List[Union[int, str, dict]], optional):
        List of row numbers, strings and regex patterns as dicts to skip.
        If a string, it'll skip rows that their first cells begin with it e.g. '#' and '//'.
        To skip only completely blank rows use `{'type': 'preset', 'value': 'blank'}`
        To provide a regex pattern use  `{'type': 'regex', 'value': '^#'}`
        For example: `skip_rows=[1, '# comment', {'type': 'regex', 'value': '^# (regex|comment)'}]`

    pick_fields (str[]):
        When passed, ignores all columns with headers
        that the given list DOES NOT include

    skip_fields (str[]):
        When passed, ignores all columns with headers
        that the given list includes. If it contains an empty string it will skip
        empty headers

    sample_size (int, optional):
        Controls the number of sample rows used to
        infer properties from the data (headers, encoding, etc.). Set to
        ``0`` to disable sampling, in which case nothing will be inferred
        from the data. Defaults to ``config.DEFAULT_SAMPLE_SIZE``.

    bytes_sample_size (int, optional):
        Same as `sample_size`, but instead
        of number of rows, controls number of bytes. Defaults to
        ``config.DEFAULT_BYTES_SAMPLE_SIZE``.

    allow_html (bool, optional):
        Allow the file source to be an HTML page.
        If False, raises ``exceptions.FormatError`` if the loaded file is
        an HTML page. Defaults to False.

    multiline_headers_joiner (str, optional):
        When passed, it's used to join multiline headers
        as `<passed-value>.join(header1_1, header1_2)`
        Defaults to ' ' (space).

    multiline_headers_duplicates (bool, optional):
        By default tabulator will exclude a cell of a miltilne header from joining
        if it's exactly the same as the previous seen value in this field.
        Enabling this option will force duplicates inclusion
        Defaults to False.

    force_strings (bool, optional):
        When True, casts all data to strings.
        Defaults to False.

    force_parse (bool, optional):
        When True, don't raise exceptions when
        parsing malformed rows, simply returning an empty value. Defaults
        to False.

    post_parse (List[function], optional):
        List of generator functions that
        receives a list of rows and headers, processes them, and yields
        them (or not). Useful to pre-process the data. Defaults to None.

    custom_loaders (dict, optional):
        Dictionary with keys as scheme names,
        and values as their respective ``Loader`` class implementations.
        Defaults to None.

    custom_parsers (dict, optional):
        Dictionary with keys as format names,
        and values as their respective ``Parser`` class implementations.
        Defaults to None.

    custom_loaders (dict, optional):
        Dictionary with keys as writer format
        names, and values as their respective ``Writer`` class
        implementations. Defaults to None.

    **options (Any, optional): Extra options passed to the loaders and parsers.

#### `stream.closed`
Returns True if the underlying stream is closed, False otherwise.

__Returns__

`bool`: whether closed

#### `stream.compression`
Stream's compression ("no" if no compression)

__Returns__

`str`: compression

#### `stream.encoding`
Stream's encoding

__Returns__

`str`: encoding

#### `stream.format`
Path's format

__Returns__

`str`: format

#### `stream.fragment`
Path's fragment

__Returns__

`str`: fragment

#### `stream.hash`
Returns the SHA256 hash of the read chunks if available

__Returns__

`str/None`: SHA256 hash

#### `stream.headers`
Headers

__Returns__

`str[]/None`: headers if available

#### `stream.sample`
Returns the stream's rows used as sample.

These sample rows are used internally to infer characteristics of the
source file (e.g. encoding, headers, ...).

__Returns__

`list[]`: sample

#### `stream.scheme`
Path's scheme

__Returns__

`str`: scheme

#### `stream.size`
Returns the BYTE count of the read chunks if available

__Returns__

`int/None`: BYTE count

#### `stream.source`
Source

__Returns__

`any`: stream source

#### `stream.open`
```python
stream.open()
```
Opens the stream for reading.

__Raises:__

    TabulatorException: if an error

#### `stream.close`
```python
stream.close()
```
Closes the stream.

#### `stream.reset`
```python
stream.reset()
```
Resets the stream pointer to the beginning of the file.

#### `stream.iter`
```python
stream.iter(keyed=False, extended=False)
```
Iterate over the rows.

Each row is returned in a format that depends on the arguments `keyed`
and `extended`. By default, each row is returned as list of their
values.

__Arguments__
- __keyed (bool, optional)__:
        When True, each returned row will be a
        `dict` mapping the header name to its value in the current row.
        For example, `[{'name': 'J Smith', 'value': '10'}]`. Ignored if
        ``extended`` is True. Defaults to False.
- __extended (bool, optional)__:
        When True, returns each row as a tuple
        with row number (starts at 1), list of headers, and list of row
        values. For example, `(1, ['name', 'value'], ['J Smith', '10'])`.
        Defaults to False.

__Raises__
- `exceptions.TabulatorException`: If the stream is closed.

__Returns__

`Iterator[Union[List[Any], Dict[str, Any], Tuple[int, List[str], List[Any]]]]`:
        The row itself. The format depends on the values of `keyed` and
        `extended` arguments.

#### `stream.read`
```python
stream.read(keyed=False, extended=False, limit=None)
```
Returns a list of rows.

__Arguments__
- __keyed (bool, optional)__: See :func:`Stream.iter`.
- __extended (bool, optional)__: See :func:`Stream.iter`.
- __limit (int, optional)__:
        Number of rows to return. If None, returns all rows. Defaults to None.

__Returns__

`List[Union[List[Any], Dict[str, Any], Tuple[int, List[str], List[Any]]]]`:
        The list of rows. The format depends on the values of `keyed`
        and `extended` arguments.

#### `stream.save`
```python
stream.save(target, format=None, encoding=None, **options)
```
Save stream to the local filesystem.

__Arguments__
- __target (str)__: Path where to save the stream.
- __format (str, optional)__:
        The format the stream will be saved as. If
        None, detects from the ``target`` path. Defaults to None.
- __encoding (str, optional)__:
        Saved file encoding. Defaults to ``config.DEFAULT_ENCODING``.
- __**options__: Extra options passed to the writer.

__Returns__

`count (int?)`: Written rows count if available
Building index...
Started generating documentation...

### `Loader`
```python
Loader(self, bytes_sample_size, **options)
```
Abstract class implemented by the data loaders

The loaders inherit and implement this class' methods to add support for a
new scheme (e.g. ssh).

__Arguments__
- __bytes_sample_size (int)__: Sample size in bytes
- __**options (dict)__: Loader options

#### `loader.options`

#### `loader.load`
```python
loader.load(source, mode='t', encoding=None)
```
Load source file.

__Arguments__
- __source (str)__: Path to tabular source file.
- __mode (str, optional)__:
        Text stream mode, `t` (text) or `b` (binary).  Defaults to `t`.
- __encoding (str, optional)__:
        Source encoding. Auto-detect by default.

__Returns__

`Union[TextIO, BinaryIO]`: I/O stream opened either as text or binary.

### `Parser`
```python
Parser(self, loader, force_parse, **options)
```
Abstract class implemented by the data parsers.

The parsers inherit and implement this class' methods to add support for a
new file type.

__Arguments__
- __loader (tabulator.Loader)__: Loader instance to read the file.
- __force_parse (bool)__:
        When `True`, the parser yields an empty extended
        row tuple `(row_number, None, [])` when there is an error parsing a
        row. Otherwise, it stops the iteration by raising the exception
        `tabulator.exceptions.SourceError`.
- __**options (dict)__: Loader options

#### `parser.closed`
Flag telling if the parser is closed.

__Returns__

`bool`: whether closed

#### `parser.encoding`
Encoding

__Returns__

`str`: encoding

#### `parser.extended_rows`
Returns extended rows iterator.

The extended rows are tuples containing `(row_number, headers, row)`,

__Raises__
- `SourceError`:
        If `force_parse` is `False` and
        a row can't be parsed, this exception will be raised.
        Otherwise, an empty extended row is returned (i.e.
        `(row_number, None, [])`).

Returns:
    Iterator[Tuple[int, List[str], List[Any]]]:
        Extended rows containing
        `(row_number, headers, row)`, where `headers` is a list of the
        header names (can be `None`), and `row` is a list of row
        values.

#### `parser.options`

#### `parser.open`
```python
parser.open(source, encoding=None)
```
Open underlying file stream in the beginning of the file.

The parser gets a byte or text stream from the `tabulator.Loader`
instance and start emitting items.

__Arguments__
- __source (str)__: Path to source table.
- __encoding (str, optional)__: Source encoding. Auto-detect by default.

__Returns__

    None

#### `parser.close`
```python
parser.close()
```
Closes underlying file stream.

#### `parser.reset`
```python
parser.reset()
```
Resets underlying stream and current items list.

After `reset()` is called, iterating over the items will start from the beginning.

### `Writer`
```python
Writer(self, **options)
```
Abstract class implemented by the data writers.

The writers inherit and implement this class' methods to add support for a
new file destination.

__Arguments__
- __**options (dict)__: Writer options.

#### `writer.options`

#### `writer.write`
```python
writer.write(source, target, headers, encoding=None)
```
Writes source data to target.

__Arguments__
- __source (str)__: Source data.
- __target (str)__: Write target.
- __headers (List[str])__: List of header names.
- __encoding (str, optional)__: Source file encoding.

__Returns__

`count (int?)`: Written rows count if available

### `validate`
```python
validate(source, scheme=None, format=None)
```
Check if tabulator is able to load the source.

__Arguments__
- __source (Union[str, IO])__: The source path or IO object.
- __scheme (str, optional)__: The source scheme. Auto-detect by default.
- __format (str, optional)__: The source file format. Auto-detect by default.

__Raises__
- `SchemeError`: The file scheme is not supported.
- `FormatError`: The file format is not supported.

__Returns__

`bool`: Whether tabulator is able to load the source file.

### `TabulatorException`
```python
TabulatorException()
```
Base class for all tabulator exceptions.

### `SourceError`
```python
SourceError()
```
The source file could not be parsed correctly.

### `SchemeError`
```python
SchemeError()
```
The file scheme is not supported.

### `FormatError`
```python
FormatError()
```
The file format is unsupported or invalid.

### `EncodingError`
```python
EncodingError()
```
Encoding error

### `CompressionError`
```python
CompressionError()
```
Compression error

### `IOError`
```python
IOError()
```
Local loading error

### `LoadingError`
```python
LoadingError()
```
Local loading error

### `HTTPError`
```python
HTTPError()
```
Remote loading error

## Contributing

> The project follows the [Open Knowledge International coding standards](https://github.com/okfn/coding-standards).

Recommended way to get started is to create and activate a project virtual environment.
To install package and development dependencies into active environment:

```bash
$ make install
```

To run tests with linting and coverage:

```bash
$ make test
```

To run tests without Internet:

```
$ pytest -m 'not remote
```

## Changelog

Here described only breaking and the most important changes. The full changelog and documentation for all released versions could be found in nicely formatted [commit history](https://github.com/frictionlessdata/tabulator-py/commits/master).

#### v1.53

- Add support for raw_html extraction in html parser (#341)

#### v1.52

- Published stream.dialect (works only for csv, for now)

#### v1.51

- Added experimental table discovery options

#### v1.50

- Ensure that headers is always a list of strings

#### v1.49

- Added `workbook_cache` argument for XLSX formats

#### v1.48

- Published `stream.hashing_algorithm` property

#### v1.47

- Added `hashing_algorithm` parameter

#### v1.46

- Fixed multiline headers merging
- Introduced a `multiline_headers_duplicates` flag

#### v1.45

- HTML format: adds support for empty selector (#321)

#### v1.44

- Exposed `stream.compression`

#### v1.43

- Exposed `stream.source`

#### v1.42

- Exposed format option to the CLI

#### v1.41

- Implemented a `pick_rows` parameter (opposite to `skip_rows`)

#### v1.40

- Implemented `stream.save()` returning count of written rows

#### v1.39

- Implemented JSON writer (#311)

#### v1.38

- Use `chardet` for encoding detection by default. For `cchardet`: `pip install tabulator[cchardet]`. Due to a great deal of problems caused by `ccharted` for non-Linux/Conda installations we're returning back to using `chardet` by default.

#### v1.37

- Raise IOError/HTTPError even a not-existent file has a bad format (#304)

#### v1.36

- Implemented `blank` preset for `skip_rows` (#302)

#### v1.35

- Added `skip/pick_columns` aliases for (#293)

#### v1.34

- Added `multiline_headers_joiner` argument (#291)

#### v1.33

- Added support for regex patterns in `skip_rows` (#290)

#### v1.32

- Added ability to skip columns (#293)

#### v1.31

- Added `xlsx` writer
- Added `html` reader

#### v1.30

- Added `adjust_floating_point_error` parameter to the `xlsx` parser

#### v1.29

- Implemented the `stream.size` and `stream.hash` properties

#### v1.28

- Added SQL writer

#### v1.27

- Added `http_timeout` argument for the `http/https` format

#### v1.26

- Added `stream.fragment` field showing e.g. Excel sheet's or DP resource's name

#### v1.25

- Added support for the `s3` file scheme (data loading from AWS S3)

#### v1.24

- Added support for compressed file-like objects

#### v1.23

- Added a setter for the `stream.headers` property

#### v1.22

- The `headers` parameter will now use the first not skipped row if the `skip_rows` parameter is provided and there are comments on the top of a data source (see #264)

#### v1.21

- Implemented experimental `preserve_formatting` for xlsx

#### v1.20

- Added support for specifying filename in zip source

#### v1.19

Updated behaviour:
- For `ods` format the boolean, integer and datetime native types are detected now

#### v1.18

Updated behaviour:
- For `xls` format the boolean, integer and datetime native types are detected now

#### v1.17

Updated behaviour:
- Added support for Python 3.7

#### v1.16

New API added:
- `skip_rows` support for an empty string to skip rows with an empty first column

#### v1.15

New API added:
- Format will be extracted from URLs like `http://example.com?format=csv`

#### v1.14

Updated behaviour:
- Now `xls` booleans will be parsed as booleans not integers

#### v1.13

New API added:
- The `skip_rows` argument now supports negative numbers to skip rows starting from the end

#### v1.12

Updated behaviour:
- Instead of raising an exception, a `UserWarning` warning will be emitted if an option isn't recognized.

#### v1.11

New API added:
- Added `http_session` argument for the `http/https` format (it uses `requests` now)
- Added support for multiline headers: `headers` argument accept ranges like `[1,3]`

#### v1.10

New API added:
- Added support for compressed files i.e. `zip` and `gz` on Python3
- The `Stream` constructor now accepts a `compression` argument
- The `http/https` scheme now accepts a `http_stream` flag

#### v1.9

Improved behaviour:
- The `headers` argument allows to set the order for keyed sources and cherry-pick values

#### v1.8

New API added:
- Formats `XLS/XLSX/ODS` supports sheet names passed via the `sheet` argument
- The `Stream` constructor accepts an `ignore_blank_headers` option

#### v1.7

Improved behaviour:
- Rebased `datapackage` format on `datapackage@1` library

#### v1.6

New API added:
- Argument `source` for the `Stream` constructor can be a `pathlib.Path`

#### v1.5

New API added:
- Argument `bytes_sample_size` for the `Stream` constructor

#### v1.4

Improved behaviour:
- Updated encoding name to a canonical form

#### v1.3

New API added:
- `stream.scheme`
- `stream.format`
- `stream.encoding`

Promoted provisional API to stable API:
- `Loader` (custom loaders)
- `Parser` (custom parsers)
- `Writer` (custom writers)
- `validate`

#### v1.2

Improved behaviour:
- Autodetect common CSV delimiters

#### v1.1

New API added:
- Added `fill_merged_cells` option to `xls/xlsx` formats

#### v1.0

New API added:
- published `Loader/Parser/Writer` API
- Added `Stream` argument `force_strings`
- Added `Stream` argument `force_parse`
- Added `Stream` argument `custom_writers`

Deprecated API removal:
- removed `topen` and `Table` - use `Stream` instead
- removed `Stream` arguments `loader/parser_options` - use `**options` instead

Provisional API changed:
- Updated the `Loader/Parser/Writer` API - please use an updated version

#### v0.15

Provisional API added:
- Unofficial support for `Stream` arguments `custom_loaders/parsers`

[stream.py]: tabulator/stream.py
[examples-dir]: examples "Examples"
[requests-session]: https://docs.puthon-requests.org/en/master/user/advanced/#session-objects
[pydoc-csv]: https://docs.python.org/3/library/csv.html#dialects-and-formatting-parameters "Python CSV options"
[sqlalchemy]: https://www.sqlalchemy.org/
[tdp]: https://frictionlessdata.io/specs/tabular-data-package/ "Tabular Data Package"
[tabulator.exceptions]: tabulator/exceptions.py "Tabulator Exceptions"


text:
<?php

require_once COMMONPATH . 'core/Core_Exceptions.php';

class MY_Exceptions extends Core_Exceptions {}


text:
<?php
namespace Aggregator\Component;

class Facebook extends \Aggregator\Component\AggregatorAbstract
	{

		/**
		 * ID de la page facebook
		 * @var string
		 */
		private $_pageID;

		/**
		 * ID de l'application facebook
		 * @var int
		 */
		private $_appID;

		/**
		 * clé secret de l'application facebook
		 * @var string
		 */
		private $_appSecret;

		/**
		 * access token
		 * @var string
		 */
		private $_token;
		/**
		 * Nombre limite des posts
		 * @var number
		 */
		private $_limit;

		/**
		 * objet facebook
		 * @var object
		 */
		private $_facebook;

		/**
		 * Facebook url
		 * @var string
		 */
		const BASE_URI = 'https://www.facebook.com/';

		/**
		 * Auth URL
		 * @var string
		 */
		const API_URI = 'https://graph.facebook.com/oauth/access_token';

		/**
		 * Host (graph facebook)
		 * @param string
		 */
		const HOST_URI = 'graph.facebook.com';

		/**
		 * constructeur
		 * @param Zend_config_ini $conf
		 */
		public function __construct($conf)
		{
			$this->_pageID 		= $conf['pageID'];
			$this->_appID 		= $conf['appID'];
			$this->_appSecret 	= $conf['appSecret'];
			$this->_limit 		= $conf['limit'];
			$this->_token		= isset($conf['token']) ? $conf['token'] : null;
		}

		//get instance de l'objet facebook
		/**
		 * get Singleton instance de la classe facebook
		 * @return boolean
		 */
		private function _getInstanceFB(){
			if(!is_object($this->_facebook)){
				require_once(__DIR__ .'/../lib/Facebook/facebook.php');
				$this->_facebook = new \Facebook(array(
						'appId'  => $this->_appID,
						'secret' => $this->_appSecret
				));
			}
			return true;
		}

		/**
		 * la valeur de retour de cette fonction est n post(s) facebook
		 * @param string $path
		 * @param string $section
		 * @return array
		 */
		public function getPosts(){
			try {
				//limit +10 a cause du filtrage
				$url = parent::_getUrl('/', array('limit' => $this->_limit + 10), $this->_pageID.'/feed');
				$this->_getInstanceFB();
				/*if(!$this->_verifToken())
					return null;
				else{*/
					$result = $this->_facebook->api($url);
					return $this->_loop($result['data']);
				//}
			}catch(FacebookApiException $e) {
				$this->setException(json_encode($e->getResult()));
				return null;
			}
		}

		/**
		 * verifier l'existance du token
		 * @return boolean
		 */
		private function _verifToken(){
			if(isset($this->_token)){
				$token = $this->_getPermanetToken();
				if($token){
					$this->_updateToken($token, $path, $section);
					return true;
				}
				else return false;
			}else return true;
		}
		/**
		 * generer un access token permanant a travers un access token temporaire
		 * @param string $token
		 * @return string|boolean
		 */
		private function _getPermanetToken(){
			$options = array(
					'client_id' => $this->_appID,
					'client_secret' => $this->_appSecret,
					'grant_type' => 'fb_exchange_token',
					'fb_exchange_token' => $this->_token
			);
			$graph_url   = parent::_getUrl(self::API_URI, $options);
			$ch = curl_init($graph_url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: '.self::HOST_URI));
			$access_token = curl_exec($ch);
			curl_close($ch);
			if(strstr($access_token, "access_token=")){
				parse_str($access_token, $output);
				$access_token = $output['access_token'];
				$this->_facebook->setAccessToken($access_token);
				return $access_token;
			}else return false;
		}

		/**
		 * MAJ le token facebook
		 *
		 * @param string $token
		 * @param string $id
		 * @return void
		 */
		private function _updateToken($token, $path, $section){
			$config = new Zend_Config_Ini($path,null,array('skipExtends' => true,'allowModifications' => true));
			$config->$section->facebook->token = $token;
			$writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $path));
			$writer->write();
		}

		/**
		 * Parcourir le resultat
		 * @see Uzik_Aggregator_Abstract::_loop()
		 * @param array $result
		 * @return array
		 */
		protected function _loop($result){
			$posts = array();
			$i = 0;
			foreach($result as $row){
				$isAdmin = explode('_',$row['id']);
				if($isAdmin[0] == $row['from']['id']){
					$i++;
					$posts[] = $this->_parse($row);
				}
				if($i == $this->_limit){
					break;
				}
			}
			return $posts;
		}

		/**
		 * return le nombre des j'aimes et commentaires facebook
		 * @param array $entry
		 * @param string $type
		 * @return number
		 */
		private function _getCount($entry,$type){
			if(isset($entry[$type]['count'])) return $entry[$type]['count'];
			else return 0;
		}

		/**
		 * return le message facebook pour chaque post
		 * @param array $entry
		 * @return string
		 */
		private function _getMessage($entry){
			if(isset($entry['message'])) return parent::_parseURL($entry['message']);
			elseif(isset($entry['story'])) return parent::_parseURL($entry['story']);
			else return '';
		}

		/**
		 * Extraction de donnees
		 * @see Uzik_Aggregator_Abstract::_parse()
		 * @param array $entry
		 * @return array
		 */
		protected function _parse($entry){
			if($entry['type'] == 'status'){
				return  array(
						'type' => 'fb_status',
						'date' => strtotime($entry['created_time']),
						'message' => self::_getMessage($entry),
						'source' => '',
						'lien' => self::BASE_URI.$entry['id'],
						'likes' => self::_getCount($entry, 'likes'),
						'comments' => self::_getCount($entry, 'comments')
				);
			}elseif($entry['type'] == 'link'){
				return array(
						'type' => 'fb_link',
						'date' => strtotime($entry['created_time']),
						'message' => $entry['message'],
						'source' => $entry['link'],
						'lien' => self::BASE_URI.$entry['id'],
						'likes' => self::_getCount($entry, 'likes'),
						'comments' => self::_getCount($entry, 'comments')
				);
			}elseif($entry['type'] == 'photo'){
				return array(
						'type' => 'fb_photo',
						'date' => strtotime($entry['created_time']),
						'message' => self::_getMessage($entry),
						'source' => $this->_getAttachement($entry['picture']),
						'lien' => $entry['link'],
						'likes' => self::_getCount($entry, 'likes'),
						'comments' => self::_getCount($entry, 'comments')
				);
			}elseif($entry['type'] == 'video'){
				return array(
						'type' => 'fb_video',
						'date' => strtotime($entry['created_time']),
						'message' => $entry['description'],
						'source' => $this->_getAttachement($entry['picture']),
						'lien' => self::BASE_URI.$entry['id'],
						'likes' => self::_getCount($entry, 'likes'),
						'comments' => self::_getCount($entry, 'comments')
				);
			}
		}

		/**
		 * @see Uzik_Aggregator_Abstract::_getAttachement()
		 */
		protected function _getAttachement($src){
			return array(
					'small' => $src,
					'medium' => str_replace('_s.','_n.',$src),
					'large' => str_replace('_s.','_b.',$src)
			);
		}
	}
?>


text:
package org.apache.activemq.network;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.net.URI;
import java.util.Arrays;
import java.util.concurrent.ConcurrentMap;

import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.TopicRequestor;
import javax.jms.TopicSession;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.command.ConsumerId;
import org.apache.activemq.util.Wait;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class SimpleNetworkTest {

   protected static final int MESSAGE_COUNT = 10;
   private static final Logger LOG = LoggerFactory.getLogger(SimpleNetworkTest.class);

   protected AbstractApplicationContext context;
   protected Connection localConnection;
   protected Connection remoteConnection;
   protected BrokerService localBroker;
   protected BrokerService remoteBroker;
   protected Session localSession;
   protected Session remoteSession;
   protected ActiveMQTopic included;
   protected ActiveMQTopic excluded;
   protected String consumerName = "durableSubs";

   // works b/c of non marshaling vm transport, the connection
   // ref from the client is used during the forward
   @Test(timeout = 60 * 1000)
   public void testMessageCompression() throws Exception {

      ActiveMQConnection localAmqConnection = (ActiveMQConnection) localConnection;
      localAmqConnection.setUseCompression(true);

      MessageConsumer consumer1 = remoteSession.createConsumer(included);
      MessageProducer producer = localSession.createProducer(included);
      producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

      waitForConsumerRegistration(localBroker, 1, included);

      for (int i = 0; i < MESSAGE_COUNT; i++) {
         Message test = localSession.createTextMessage("test-" + i);
         producer.send(test);
         Message msg = consumer1.receive(3000);
         assertNotNull(msg);
         ActiveMQMessage amqMessage = (ActiveMQMessage) msg;
         assertTrue(amqMessage.isCompressed());
      }
      // ensure no more messages received
      assertNull(consumer1.receive(1000));
   }

   @Test(timeout = 60 * 1000)
   public void testRequestReply() throws Exception {
      final MessageProducer remoteProducer = remoteSession.createProducer(null);
      MessageConsumer remoteConsumer = remoteSession.createConsumer(included);
      remoteConsumer.setMessageListener(new MessageListener() {
         @Override
         public void onMessage(Message msg) {
            try {
               TextMessage textMsg = (TextMessage) msg;
               String payload = "REPLY: " + textMsg.getText();
               Destination replyTo;
               replyTo = msg.getJMSReplyTo();
               textMsg.clearBody();
               textMsg.setText(payload);
               remoteProducer.send(replyTo, textMsg);
            }
            catch (JMSException e) {
               e.printStackTrace();
            }
         }
      });

      TopicRequestor requestor = new TopicRequestor((TopicSession) localSession, included);
      // allow for consumer infos to perculate around
      Thread.sleep(5000);
      for (int i = 0; i < MESSAGE_COUNT; i++) {
         TextMessage msg = localSession.createTextMessage("test msg: " + i);
         TextMessage result = (TextMessage) requestor.request(msg);
         assertNotNull(result);
         LOG.info(result.getText());
      }
   }

   @Test(timeout = 60 * 1000)
   public void testFiltering() throws Exception {
      MessageConsumer includedConsumer = remoteSession.createConsumer(included);
      MessageConsumer excludedConsumer = remoteSession.createConsumer(excluded);
      MessageProducer includedProducer = localSession.createProducer(included);
      MessageProducer excludedProducer = localSession.createProducer(excluded);
      // allow for consumer infos to perculate around
      Thread.sleep(2000);
      Message test = localSession.createTextMessage("test");
      includedProducer.send(test);
      excludedProducer.send(test);
      assertNull(excludedConsumer.receive(1000));
      assertNotNull(includedConsumer.receive(1000));
   }

   @Test(timeout = 60 * 1000)
   public void testConduitBridge() throws Exception {
      MessageConsumer consumer1 = remoteSession.createConsumer(included);
      MessageConsumer consumer2 = remoteSession.createConsumer(included);
      MessageProducer producer = localSession.createProducer(included);
      producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

      waitForConsumerRegistration(localBroker, 2, included);

      for (int i = 0; i < MESSAGE_COUNT; i++) {
         Message test = localSession.createTextMessage("test-" + i);
         producer.send(test);
         assertNotNull(consumer1.receive(1000));
         assertNotNull(consumer2.receive(1000));
      }
      // ensure no more messages received
      assertNull(consumer1.receive(1000));
      assertNull(consumer2.receive(1000));
   }

   private void waitForConsumerRegistration(final BrokerService brokerService,
                                            final int min,
                                            final ActiveMQDestination destination) throws Exception {
      assertTrue("Internal bridge consumers registered in time", Wait.waitFor(new Wait.Condition() {
         @Override
         public boolean isSatisified() throws Exception {
            Object[] bridges = brokerService.getNetworkConnectors().get(0).bridges.values().toArray();
            if (bridges.length > 0) {
               LOG.info(brokerService + " bridges " + Arrays.toString(bridges));
               DemandForwardingBridgeSupport demandForwardingBridgeSupport = (DemandForwardingBridgeSupport) bridges[0];
               ConcurrentMap<ConsumerId, DemandSubscription> forwardingBridges = demandForwardingBridgeSupport.getLocalSubscriptionMap();
               LOG.info(brokerService + " bridge "  + demandForwardingBridgeSupport + ", localSubs: " + forwardingBridges);
               if (!forwardingBridges.isEmpty()) {
                  for (DemandSubscription demandSubscription : forwardingBridges.values()) {
                     if (demandSubscription.getLocalInfo().getDestination().equals(destination)) {
                        LOG.info(brokerService + " DemandSubscription " + demandSubscription + ", size: " + demandSubscription.size());
                        return demandSubscription.size() >= min;
                     }
                  }
               }
            }
            return false;
         }
      }));
   }

   @Test(timeout = 60 * 1000)
   public void testDurableStoreAndForward() throws Exception {
      // create a remote durable consumer
      MessageConsumer remoteConsumer = remoteSession.createDurableSubscriber(included, consumerName);
      Thread.sleep(1000);
      // now close everything down and restart
      doTearDown();
      doSetUp(false);
      MessageProducer producer = localSession.createProducer(included);
      for (int i = 0; i < MESSAGE_COUNT; i++) {
         Message test = localSession.createTextMessage("test-" + i);
         producer.send(test);
      }
      Thread.sleep(1000);
      // close everything down and restart
      doTearDown();
      doSetUp(false);
      remoteConsumer = remoteSession.createDurableSubscriber(included, consumerName);
      for (int i = 0; i < MESSAGE_COUNT; i++) {
         assertNotNull("message count: " + i, remoteConsumer.receive(2500));
      }
   }

   @Ignore("This seems like a simple use case, but it is problematic to consume an existing topic store, " + "it requires a connection per durable to match that connectionId")
   public void testDurableStoreAndForwardReconnect() throws Exception {
      // create a local durable consumer
      MessageConsumer localConsumer = localSession.createDurableSubscriber(included, consumerName);
      Thread.sleep(5000);
      // now close everything down and restart
      doTearDown();
      doSetUp(false);
      // send messages
      MessageProducer producer = localSession.createProducer(included);
      for (int i = 0; i < MESSAGE_COUNT; i++) {
         Message test = localSession.createTextMessage("test-" + i);
         producer.send(test);
      }
      Thread.sleep(5000);
      // consume some messages locally
      localConsumer = localSession.createDurableSubscriber(included, consumerName);
      LOG.info("Consume from local consumer: " + localConsumer);
      for (int i = 0; i < MESSAGE_COUNT / 2; i++) {
         assertNotNull("message count: " + i, localConsumer.receive(2500));
      }
      Thread.sleep(5000);
      // close everything down and restart
      doTearDown();
      doSetUp(false);
      Thread.sleep(5000);

      LOG.info("Consume from remote");
      // consume the rest remotely
      MessageConsumer remoteConsumer = remoteSession.createDurableSubscriber(included, consumerName);
      LOG.info("Remote consumer: " + remoteConsumer);
      Thread.sleep(5000);
      for (int i = 0; i < MESSAGE_COUNT / 2; i++) {
         assertNotNull("message count: " + i, remoteConsumer.receive(10000));
      }
   }

   @Before
   public void setUp() throws Exception {
      doSetUp(true);
   }

   @After
   public void tearDown() throws Exception {
      doTearDown();
   }

   protected void doTearDown() throws Exception {
      localConnection.close();
      remoteConnection.close();
      localBroker.stop();
      remoteBroker.stop();
   }

   protected void doSetUp(boolean deleteAllMessages) throws Exception {
      remoteBroker = createRemoteBroker();
      remoteBroker.setDeleteAllMessagesOnStartup(deleteAllMessages);
      remoteBroker.start();
      remoteBroker.waitUntilStarted();
      localBroker = createLocalBroker();
      localBroker.setDeleteAllMessagesOnStartup(deleteAllMessages);
      localBroker.start();
      localBroker.waitUntilStarted();
      URI localURI = localBroker.getVmConnectorURI();
      ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(localURI);
      fac.setAlwaysSyncSend(true);
      fac.setDispatchAsync(false);
      localConnection = fac.createConnection();
      localConnection.setClientID("clientId");
      localConnection.start();
      URI remoteURI = remoteBroker.getVmConnectorURI();
      fac = new ActiveMQConnectionFactory(remoteURI);
      remoteConnection = fac.createConnection();
      remoteConnection.setClientID("clientId");
      remoteConnection.start();
      included = new ActiveMQTopic("include.test.bar");
      excluded = new ActiveMQTopic("exclude.test.bar");
      localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   }

   protected String getRemoteBrokerURI() {
      return "org/apache/activemq/network/remoteBroker.xml";
   }

   protected String getLocalBrokerURI() {
      return "org/apache/activemq/network/localBroker.xml";
   }

   protected BrokerService createBroker(String uri) throws Exception {
      Resource resource = new ClassPathResource(uri);
      BrokerFactoryBean factory = new BrokerFactoryBean(resource);
      resource = new ClassPathResource(uri);
      factory = new BrokerFactoryBean(resource);
      factory.afterPropertiesSet();
      BrokerService result = factory.getBroker();
      return result;
   }

   protected BrokerService createLocalBroker() throws Exception {
      return createBroker(getLocalBrokerURI());
   }

   protected BrokerService createRemoteBroker() throws Exception {
      return createBroker(getRemoteBrokerURI());
   }
}


text:
package com.palantir.atlasdb.sweep;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.palantir.atlasdb.encoding.PtBytes;
import com.palantir.atlasdb.keyvalue.api.SweepResults;
import java.util.Optional;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableSweepTableResponse.class)
@JsonDeserialize(as = ImmutableSweepTableResponse.class)
public interface SweepTableResponse {

    Optional<String> nextStartRow();

    long numCellTsPairsExamined();

    long staleValuesDeleted();

    static SweepTableResponse from(SweepResults results) {
        return ImmutableSweepTableResponse.builder()
                .numCellTsPairsExamined(results.getCellTsPairsExamined())
                .staleValuesDeleted(results.getStaleValuesDeleted())
                .nextStartRow(results.getNextStartRow().map(PtBytes::encodeHexString))
                .build();
    }
}


text:
// Copyright (c) PocketCampus.Org 2014-15
// See LICENSE file for more details
// File author: Solal Pirelli

using System;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Web.Http;

namespace PocketCampus.Common.Controls
{
    [ContentProperty( Name = "Placeholder" )]
    public sealed class ImageWithPlaceholder : ContentControl
    {
        private static readonly HttpClient Client = new HttpClient();
        private static readonly TimeSpan Timeout = TimeSpan.FromSeconds( 5 );

        public string Source
        {
            get { return (string) GetValue( SourceProperty ); }
            set { SetValue( SourceProperty, value ); }
        }

        public static readonly DependencyProperty SourceProperty =
            DependencyProperty.Register( "Source", typeof( string ), typeof( ImageWithPlaceholder ), new PropertyMetadata( null, OnSourceChanged ) );

        private static async void OnSourceChanged( DependencyObject obj, DependencyPropertyChangedEventArgs args )
        {
            var control = (ImageWithPlaceholder) obj;
            var newSource = (string) args.NewValue;

            control._image.Source = null;
            control.SetupPlaceholder();

            try
            {
                var timeoutSource = new CancellationTokenSource( Timeout );
                var content = await Client.GetBufferAsync( new Uri( newSource, UriKind.Absolute ) ).AsTask( timeoutSource.Token );
                var image = new BitmapImage();
                await image.SetSourceAsync( content.AsStream().AsRandomAccessStream() );
                control._image.Source = image;
                control.Content = control._image;
            }
            catch
            {
                // Do nothing. The placeholder is already there.
            }
        }

        public object Placeholder
        {
            get { return (object) GetValue( PlaceholderProperty ); }
            set { SetValue( PlaceholderProperty, value ); }
        }

        public static readonly DependencyProperty PlaceholderProperty =
            DependencyProperty.Register( "Placeholder", typeof( object ), typeof( ImageWithPlaceholder ), new PropertyMetadata( null ) );

        private readonly Image _image;

        public ImageWithPlaceholder()
        {
            HorizontalContentAlignment = HorizontalAlignment.Stretch;
            VerticalContentAlignment = VerticalAlignment.Stretch;

            _image = new Image();
            SetupPlaceholder();
        }

        private void SetupPlaceholder()
        {
            SetBinding( ImageWithPlaceholder.ContentProperty, new Binding { Source = this, Path = new PropertyPath( "Placeholder" ) } );
        }
    }
}


text:
using System.Collections.Generic;

namespace UltimateTeam.Toolkit.Models
{
    public class UserDataInfo
    {
        public string DisplayName { get; set; }

        public string LastLogin { get; set; }

        public string LastLogout { get; set; }

        public string NucPersId { get; set; }

        public string NucUserId { get; set; }

        public List<UserDataInfoSettings> Settings { get; set; }

        public string Sku { get; set; }
    }
}


text:
package com.siyeh.ig.serialization;

import javax.annotation.Nonnull;

import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiModifier;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.SerializationUtils;

public class TransientFieldInNonSerializableClassInspection
  extends BaseInspection {

  @Nonnull
  public String getDisplayName() {
    return InspectionGadgetsBundle.message(
      "transient.field.in.non.serializable.class.display.name");
  }

  @Nonnull
  public String buildErrorString(Object... infos) {
    final PsiField field = (PsiField)infos[0];
    return InspectionGadgetsBundle.message(
      "transient.field.in.non.serializable.class.problem.descriptor",
      field.getName());
  }

  public InspectionGadgetsFix buildFix(Object... infos) {
    return new TransientFieldInNonSerializableClassFix();
  }

  private static class TransientFieldInNonSerializableClassFix
    extends InspectionGadgetsFix {

    @Nonnull
    public String getName() {
      return InspectionGadgetsBundle.message(
        "transient.field.in.non.serializable.class.remove.quickfix");
    }

    public void doFix(Project project, ProblemDescriptor descriptor)
      throws IncorrectOperationException {
      final PsiElement transientModifier = descriptor.getPsiElement();
      deleteElement(transientModifier);
    }
  }

  public BaseInspectionVisitor buildVisitor() {
    return new TransientFieldInNonSerializableClassVisitor();
  }

  private static class TransientFieldInNonSerializableClassVisitor
    extends BaseInspectionVisitor {

    @Override
    public void visitField(@Nonnull PsiField field) {
      if (!field.hasModifierProperty(PsiModifier.TRANSIENT)) {
        return;
      }
      final PsiClass aClass = field.getContainingClass();
      if (SerializationUtils.isSerializable(aClass)) {
        return;
      }
      registerModifierError(PsiModifier.TRANSIENT, field, field);
    }
  }
}