text:
import unittest
from mock import MagicMock, patch
from timeout_decorator import timeout, TimeoutError

from tests import FakeApi

from pgoapi import PGoApi
from pgoapi.exceptions import NotLoggedInException, ServerBusyOrOfflineException
from pokemongo_bot.api_wrapper import ApiWrapper

class TestApiWrapper(unittest.TestCase):
    def test_raises_not_logged_in_exception(self):
        api = ApiWrapper(PGoApi())
        api.get_inventory(test='awesome')
        with self.assertRaises(NotLoggedInException):
            api.call()

    def test_api_call_with_no_requests_set(self):
        api = ApiWrapper(PGoApi())
        with self.assertRaises(RuntimeError):
            api.call()

    @patch('pokemongo_bot.api_wrapper.sleep')
    def test_api_server_is_unreachable_raises_server_busy_or_offline_exception(self, sleep):
        sleep.return_value = True # we don't need to really sleep
        api = FakeApi('Wrong Value')
        api.get_inventory(test='awesome')
        # we expect an exception because the "server" isn't returning a valid response
        with self.assertRaises(ServerBusyOrOfflineException):
            api.call()

    def test_mocked_call(self):
        api = FakeApi(True)
        api._is_response_valid = MagicMock(return_value=True)
        api.get_inventory(test='awesome')
        result = api.call()
        self.assertTrue(result)

    def test_return_value_is_not_valid(self):

        def returnApi(ret_value):
            api = FakeApi(ret_value)
            api.get_inventory(test='awesome')
            return api

        wrong_return_values = [
            None,
            False,
            {},
            {'responses': {}},
            {'status_code': 0},
            {'responses': {'GET_INVENTORY_OR_NOT': {}}, 'status_code': 0}
        ]
        for wrong in wrong_return_values:
            api = returnApi(wrong)
            request_callers = api._pop_request_callers() # we can pop because we do no call

            is_valid = api._is_response_valid(wrong, request_callers)
            self.assertFalse(is_valid, 'return value {} is valid somehow ?'.format(wrong))

    def test_return_value_is_valid(self):
        api = FakeApi() # we set the return value below
        api.get_inventory(test='awesome')

        request = api.request_callers[0] # only one request
        self.assertEqual(request.upper(), 'GET_INVENTORY')

        good_return_value = {'responses': {request.upper(): {}}, 'status_code': 0}
        api.setApiReturnValue(good_return_value)

        result = api.call()
        self.assertEqual(result, good_return_value)
        self.assertEqual(len(api.request_callers), 0, 'request_callers must be empty')

    def test_multiple_requests(self):
        api = FakeApi()
        api.get_inventory(test='awesome')
        api.fort_details()

        good_return_value = {'responses': {'GET_INVENTORY': {}, 'FORT_DETAILS': {}}, 'status_code': 0}
        api.setApiReturnValue(good_return_value)

        result = api.call()
        self.assertEqual(result, good_return_value)

    @timeout(1)
    def test_api_call_throttle_should_pass(self):
        api = FakeApi(True)
        api._is_response_valid = MagicMock(return_value=True)
        api.requests_per_seconds = 5

        for i in range(api.requests_per_seconds):
            api.call()

    @timeout(1) # expects a timeout
    def test_api_call_throttle_should_fail(self):
        api = FakeApi(True)
        api._is_response_valid = MagicMock(return_value=True)
        api.requests_per_seconds = 5

        with self.assertRaises(TimeoutError):
            for i in range(api.requests_per_seconds * 2):
                api.call()


text:
from telegram.ext import Updater, CommandHandler
from control import ser
from multiprocessing import Process
import threading
import time

prnterr = ""
printstate = 0
telgst = 0
abr = 0
btnd = 0

def prstabfr(self, q):
	global printstate
	if q == 1:
		printstate = 1
	elif q == 2:
		printstate = 2
	elif q == 0:
		printstate = 0
	elif q == 3:
		printstate = 3
	elif q == 4:
		printstate = 4
	elif q == 6:
		printstate = 6
	elif q == 7:
		printstate = 7

def prerrabfr(self, x):
	global prnterr
	x = prnterr

def prtningrd(bot, update):
    global printstate
    if printstate == 1:
        update.message.reply_text(
            'Hello {}'.format(update.message.from_user.first_name))
        update.message.reply_text('Your print start now')
    elif printstate == 2:
        update.message.reply_text(
            'Hello {}'.format(update.message.from_user.first_name))
        update.message.reply_text('Your print is ready')
    elif printstate == 3:
        update.message.reply_text(
            'Hello {}'.format(update.message.from_user.first_name))
        update.message.reply_text('You interrupted your print!')
    elif printstate == 0:
        update.message.reply_text(
            'Hello {}'.format(update.message.from_user.first_name))
        update.message.reply_text('Not printing')
    elif printstate == 4:
        update.message.reply_text(
            'Hello {}'.format(update.message.from_user.first_name))
        update.message.reply_text('Printing')
    elif printstate == 6:
        update.message.reply_text(
            'Hello {}'.format(update.message.from_user.first_name))
        update.message.reply_text('It is possible that your print failed')
        update.message.reply_text('We recomment to look at your printer')
    elif printstate == 7:
        update.message.reply_text(
            'Hello {}'.format(update.message.from_user.first_name))
        update.message.reply_text('We are sure that your Print Failed')
        update.message.reply_text('The Error was:'+prnterr)

updater = Updater('345261417:AAHhob6mp4_oYaCAPNfihqKp2MzktnOplJI')

updater.dispatcher.add_handler(CommandHandler('state', prtningrd))

def shtdn(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Shuting down now')
    telgst = 1
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('shutdown', shtdn))

def mxleft10(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Moving x 10 to left')
    telgst = 2
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('mx-10', mxleft10))

def mxright10(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Moving x 10 to right')
    telgst = 3
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('mx+10', mxright10))

def myleft10(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Moving y 10 to left')
    telgst = 5
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('my-10', myleft10))

def myright10(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Moving y 10 to right')
    telgst = 4
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('my+10', myright10))

def mzright10(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Moving z 10 to right')
    telgst = 6
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('mz+10', mzright10))

def mzleft10(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Moving z 10 to left')
    telgst = 7
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('mz-10', mzleft10))

def Homepr(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Homing')
    telgst = 8
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('home', Homepr))

def stopit(bot, update):
    global telgst
    update.message.reply_text('Hello {}'.format(update.message.from_user.first_name))
    update.message.reply_text('Interrupting your print now')
    telgst = 9
    time.sleep(0.15)
    telgst = 0

updater.dispatcher.add_handler(CommandHandler('stop', stopit))

def contltelegramprinter(ser):
	global telgst
	while True:
		time.sleep(0.15)
		#print ("hei")
		if telgst == 1:
			os.system("shutdown now -h")
		elif telgst == 2:
			ser.write (b"G91\r\n")
			ser.write (b"G1 X-10\r\n")
			ser.write (b"G90\r\n")
		elif telgst == 3:
			ser.write (b"G91\r\n")
			ser.write (b"G1 X+10\r\n")
			ser.write (b"G90\r\n")
		elif telgst == 4:
			ser.write (b"G91\r\n")
			ser.write (b"G1 Y+10\r\n")
			ser.write (b"G90\r\n")
		elif telgst == 5:
			ser.write (b"G91\r\n")
			ser.write (b"G1 Y-10\r\n")
			ser.write (b"G90\r\n")
		elif telgst == 7:
			ser.write (b"G91\r\n")
			ser.write (b"G1 Z-10\r\n")
			ser.write (b"G90\r\n")
		elif telgst == 6:
			ser.write (b"G91\r\n")
			ser.write (b"G1 Z+10\r\n")
			ser.write (b"G90\r\n")
		elif telgst == 8:
			ser.write (b"G28\r\n")
		elif telgst == 9:
			global printstate
			printstate = 3
			global abr
			abr = 1
			global bntd
			bntd = 2

telep = threading.Thread(target=contltelegramprinter, args=(ser,))
telep.start()

def teleg():
	updater.start_polling()
	#updater.idle()

telegram = threading.Thread(target=teleg, args=())
telegram.start()

redpajama_set_name: RedPajamaGithub


text:
import { json2csv, parse, Parser, Transform } from 'json2csv';
import { Transform as NodeTransform } from 'stream';

let s: string;
let obj: object;

interface ExampleObj {
    str?: string;
    num?: number;
    obj?: object;
}

/**************
 * Public API *
 **************/
parse({});
parse([]);
parse({}, {});

interface Car {
    car: string;
    price: number;
}

new Parser();
const parser: Parser<ExampleObj> = new Parser({});
s = parser.parse({ str: '', num: 1, obj: {} });

const opts: json2csv.Options<Car> = {
    fields: [{
        label: 'Car Name',
        value: 'car'
    }, {
        label: 'Price USD',
        value: 'price'
    }]
};

const json2csvParser = new Parser<Car>(opts);

parser.parse([]);
const transform: Transform<ExampleObj> = new Transform<ExampleObj>({ quote: '' });
const nodeTransform: NodeTransform = transform;

/********************
 * Internal Methods *
 ********************/
class ParserExt extends Parser<ExampleObj> {
    constructor() {
        super();
        // Parser methods
        obj = this.preprocessData({});
        obj = this.preprocessData({ str: '', num: 1, obj: {} });
        obj = this.preprocessData([]);
        s = this.processData([]);

        // JSON2CSVBase methods
        let opts: json2csv.Options<ExampleObj>;
        opts = this.preprocessOpts();
        opts = this.preprocessOpts(opts);
        s = this.getHeader();
        obj = this.preprocessRow({});
        obj = this.preprocessRow({ str: '', num: 1, obj: {} });
        s = this.processRow({});
        s = this.processRow({ str: '', num: 1, obj: {} });
        s = this.processCell({}, { label: 'test', default: 'test2', value: 'field' });
        s = this.processCell({ str: '', num: 1, obj: {} }, { label: 'test', default: 'test2', value: 'field' });
        s = this.processCell({}, { label: 'test', default: 'test2', value: (row: object, field: string) => 'string' });
        s = this.processCell({ str: '', num: 1, obj: {} }, { label: 'test', default: 'test2', value: (row: object, field: string) => 'string' });
        this.getValue({}, { label: 'test' });
        this.getValue({ str: '', num: 1, obj: {} }, { label: 'test' });
        s = this.processValue(undefined, true);
        s = this.processValue(null, true);
        s = this.processValue(1, true);
        s = this.processValue('test', true);
        s = this.processValue(new Date(), true);
        s = this.processValue({}, true);
        s = this.processValue([], true);
        const flattenedData: object = this.flatten({});
        const unwindedData: object[] = this.unwindData([], []);
    }
}

class TransformExt extends Transform<ExampleObj> {
    constructor() {
        super();
        // Transform methods
        this.pushLine({});
        this.pushLine({ str: '', num: 1, obj: {} });

        // JSON2CSVBase methods
        let opts: json2csv.Options<ExampleObj>;
        opts = this.preprocessOpts();
        opts = this.preprocessOpts(opts);
        s = this.getHeader();
        obj = this.preprocessRow({});
        obj = this.preprocessRow({ str: '', num: 1, obj: {} });
        s = this.processRow({});
        s = this.processRow({ str: '', num: 1, obj: {} });
        s = this.processCell({}, { label: 'test', default: 'test2', value: 'field' });
        s = this.processCell({ str: '', num: 1, obj: {} }, { label: 'test', default: 'test2', value: 'field' });
        s = this.processCell({}, { label: 'test', default: 'test2', value: (row: object, field: string) => 'string' });
        s = this.processCell({ str: '', num: 1, obj: {} }, { label: 'test', default: 'test2', value: (row: object, field: string) => 'string' });
        this.getValue({}, { label: 'test' });
        this.getValue({ str: '', num: 1, obj: {} }, { label: 'test' });
        s = this.processValue(undefined, true);
        s = this.processValue(null, true);
        s = this.processValue(1, true);
        s = this.processValue('test', true);
        s = this.processValue(new Date(), true);
        s = this.processValue({}, true);
        s = this.processValue([], true);
        const flattenedData: object = this.flatten({});
        const unwindedData: object[] = this.unwindData([], []);
    }
}


text:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, Sample_14_2!</string>
    <string name="app_name">Sample_14_2</string>
    <string name="title">姿态传感器案例</string>
    <string name="myTextView1">Yaw为:</string>
    <string name="myTextView2">Pitch为:</string>
    <string name="myTextView3">Roll为:</string>
</resources>


text:
<?php include_once("includes/topwrapper.php");
error_reporting(E_ALL ^ E_DEPRECATED);
?>
<link href="css/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />

Tablets

                            <?php
                            include_once("includes/util.php");
                            $util = new Util();
                            $activeColumnIndex = -1;
                            $piColumnIndex = -1;
                            $counter = 0;
                            $serialIdIndex = -1;
                            $deploymentArray = $util->getTabletInformation();
                            $firstArray = $deploymentArray[0];
                            while(current($firstArray) != null)
                            {
                                if(strtolower(trim(key($firstArray))) == "is active")
                                    $activeColumnIndex = $counter;
                                elseif(strtolower(trim(key($firstArray))) == "using pi")
                                    $piColumnIndex = $counter;
                                elseif(strtolower(trim(key($firstArray))) == "serial id")
                                    $serialIdIndex = $counter;
                                $counter++;
                                echo("".key($firstArray)."	");
                                next($firstArray);
                            }
                            echo('Command	');
                            ?>

                        <?php
                        $isfirst = true;
                        $counter = 0;
                        $dropdown = false;
                        $serialId = "";
                        foreach($deploymentArray as $deployment)
                        {
                            echo("
");
                            foreach($deployment as $dataValue)
                            {
                                if($counter === $activeColumnIndex)
                                {
                                    if($dataValue == 1)
                                        echo("Yes	");
                                    else
                                        echo("No	");
                                }
                                elseif($counter === $piColumnIndex)
                                {
                                    if($dataValue == 1)
                                        echo("Yes	");
                                    else
                                        echo("No	");
                                }
                                else
                                    echo("$dataValue	");
                                if($counter === $serialIdIndex)
                                    $serialId = trim($dataValue);
                                $counter++;
                            }
                            echo(" <button class=\"btn btn-default\">Issue</button>	");
                            $counter = 0;
                            echo("
");
                        }
                        ?>