<commit_before>from __future__ import print_function
import time
import socket
import sys
import os
import platform
import re
from pymavlink import mavutil, mavwp
from Queue import Empty
from pymavlink.dialects.v10 import ardupilotmega
import types

if platform.system() == 'Windows':
    from errno import WSAECONNRESET as ECONNABORTED
else:
    from errno import ECONNABORTED

# Clean impl of mp dependencies for dronekit

import dronekit.module.api as api

def errprinter(*args):
    print(*args, file=sys.stderr)

class FakeAPI:
    def __init__(self, module):
        self.__vehicle = api.MPVehicle(module)
        self.exit = False

    def get_vehicles(self, query=None):
        return [ self.__vehicle ]

# def mav_thread(conn, state):

#     return (in_queue, out_queue)

class MavWriter():
    def __init__(self, queue):
        self.queue = queue

    def write(self, pkt):
        self.queue.put(pkt)

    def read(self):
        errprinter('writer should not have had a read request')
        os._exit(43)

def send_heartbeat(master):
    master.mav.heartbeat_send(mavutil.mavlink.MAV_TYPE_GCS, mavutil.mavlink.MAV_AUTOPILOT_INVALID, 0, 0, 0)

def request_data_stream_send(master, rate=1):
    master.mav.request_data_stream_send(master.target_system, master.target_component,
                                        mavutil.mavlink.MAV_DATA_STREAM_ALL, rate, 1)

from Queue import Queue
from threading import Thread

class MPFakeState:
    def __init__(self, master, status_printer=None):
        self.master = master
        out_queue = Queue()
        # self.mav_thread = mav_thread(master, self)
        # self.mav = master.mav

        self.api = None

        # TODO get rid of "master" object as exposed,
        # keep it private, expose something smaller for dronekit
        self.out_queue = out_queue
        self.master.mav = mavutil.mavlink.MAVLink(MavWriter(self.out_queue), srcSystem=self.master.source_system, use_native=False)

        self.command_map = {}
        self.completions = {}

        self.target_system = 0
        self.target_component = 0

        self.status = type('MPStatus',(object,),{
            'flightmode': 'AUTO',
            'armed': False,
        })()

        self.mav_param = {} 

        # Weird
        self.mpstate = self
        self.functions = self
        self.mpstate.settings = self

        # waypoints
        self.wploader = mavwp.MAVWPLoader()
        self.wp_loaded = True

        # Attaches message listeners.
        self.message_listeners = dict()

        def message_default(name):
            """
            Decorator for default message handlers.
            """
            def decorator(fn):
                if isinstance(name, list):
                    for n in name:
                        self.on_message(n, fn)
                else:
                    self.on_message(name, fn)
            return decorator

        self.status_printer = status_printer

        @message_default('STATUSTEXT')
        def listener(self, name, m):
            self.status_printer(re.sub(r'(^|\n)', '>>> \1', m.text.rstrip()))

        self.lat = None
        self.lon = None
        self.alt = None
        self.vx = None
        self.vy = None
        self.vz = None
        
        @message_default('GLOBAL_POSITION_INT')
        def listener(self, name, m):
            (self.lat, self.lon) = (m.lat / 1.0e7, m.lon / 1.0e7)
            (self.vx, self.vy, self.vz) = (m.vx / 100.0, m.vy / 100.0, m.vz / 100.0)
            self._MPFakeState__on_change('location', 'velocity')

        @message_default('GPS_RAW')
        def listener(self, name, m):
            # (self.lat, self.lon) = (m.lat, m.lon)
            # self.__on_change('location')<commit_msg>Corrects status_printer.<commit_after>from __future__ import print_function
import time
import socket
import sys
import os
import platform
import re
from pymavlink import mavutil, mavwp
from Queue import Empty
from pymavlink.dialects.v10 import ardupilotmega
import types

if platform.system() == 'Windows':
    from errno import WSAECONNRESET as ECONNABORTED
else:
    from errno import ECONNABORTED

# Clean impl of mp dependencies for dronekit

import dronekit.module.api as api

def errprinter(*args):
    print(*args, file=sys.stderr)

class FakeAPI:
    def __init__(self, module):
        self.__vehicle = api.MPVehicle(module)
        self.exit = False

    def get_vehicles(self, query=None):
        return [ self.__vehicle ]

# def mav_thread(conn, state):

#     return (in_queue, out_queue)

class MavWriter():
    def __init__(self, queue):
        self.queue = queue

    def write(self, pkt):
        self.queue.put(pkt)

    def read(self):
        errprinter('writer should not have had a read request')
        os._exit(43)

def send_heartbeat(master):
    master.mav.heartbeat_send(mavutil.mavlink.MAV_TYPE_GCS, mavutil.mavlink.MAV_AUTOPILOT_INVALID, 0, 0, 0)

def request_data_stream_send(master, rate=1):
    master.mav.request_data_stream_send(master.target_system, master.target_component,
                                        mavutil.mavlink.MAV_DATA_STREAM_ALL, rate, 1)

from Queue import Queue
from threading import Thread

class MPFakeState:
    def __init__(self, master):
        self.master = master
        out_queue = Queue()
        # self.mav_thread = mav_thread(master, self)
        # self.mav = master.mav

        self.api = None

        # TODO get rid of "master" object as exposed,
        # keep it private, expose something smaller for dronekit
        self.out_queue = out_queue
        self.master.mav = mavutil.mavlink.MAVLink(MavWriter(self.out_queue), srcSystem=self.master.source_system, use_native=False)

        self.command_map = {}
        self.completions = {}

        self.target_system = 0
        self.target_component = 0

        self.status = type('MPStatus',(object,),{
            'flightmode': 'AUTO',
            'armed': False,
        })()

        self.mav_param = {} 

        # Weird
        self.mpstate = self
        self.functions = self
        self.mpstate.settings = self

        # waypoints
        self.wploader = mavwp.MAVWPLoader()
        self.wp_loaded = True

        # Attaches message listeners.
        self.message_listeners = dict()

        def message_default(name):
            """
            Decorator for default message handlers.
            """
            def decorator(fn):
                if isinstance(name, list):
                    for n in name:
                        self.on_message(n, fn)
                else:
                    self.on_message(name, fn)
            return decorator

        self.status_printer = None

        @message_default('STATUSTEXT')
        def listener(self, name, m):
            if self.status_printer:
                self.status_printer(re.sub(r'(^|\n)', '>>> \1', m.text.rstrip()))

        self.lat = None
        self.lon = None
        self.alt = None
        self.vx = None
        self.vy = None
        self.vz = None
        
        @message_default('GLOBAL_POSITION_INT')
        def listener(self, name, m):
            (self.lat, self.lon) = (m.lat / 1.0e7, m.lon / 1.0e7)
            (self.vx, self.vy, self.vz) = (m.vx / 100.0, m.vy / 100.0, m.vz / 100.0)
            self._MPFakeState__on_change('location', 'velocity')

        @message_default('GPS_RAW')
        def listener(self, name, m):
            # (self.lat, self.lon) = (m.lat, m.lon)
            # self.__on_change('location')
{'fraction_non_alphanumeric': 0.10299225220411434, 'fraction_numerical': 0.008014961261020572, 'mean_word_length': 2.1657505285412264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '72785', 'n_tokens_mistral': 2446, 'n_tokens_neox': 2331, 'n_words': 543}