text:
__version__ = '0.8'
__author__  = 'ArmedGuy'

import b3, time, threading, re, socket, thread, sys, pyircbot
from pyircbot import IrcEvent, IrcUser
from b3 import clients
import b3.events
import b3.plugin
import datetime, string
from b3 import functions
#--------------------------------------------------------------------------------------------------
class IrcbootPlugin(b3.plugin.Plugin):
    SpawnedPlugin = None
    _reColor = re.compile(r'(\^[0-9a-z])|[\x80-\xff]')
    _settings = { # default settings
        'irc': {
            'nick': "b3ircbot-ircboot",
            'ident': "b3ircboot",
            'realname': "Big Brother",
            'serverpassword': "",
            'nickservpassword': "",
            'host': None,
            'port': 6667,
            'channels': None,
        },
        'relay': {
            'mode': 'rcon',
            'broadcasts': 'true',
            'gamechat': 'true',
            'consolechat': 'true',
            'gameevents': 'true',
            'chatprefix': '',
        },
        'commands': {
            'ircadd': 80,
            'ircrem': 80,
            'ircexec': 100,
            'ircon': 80,
        },
        'users': {
            'userfile': None,
        },
    }
    _ircbot = None
    _adminPlugin = None
    _origOutputFunc = None
    def onLoadConfig(self):
        IrcbootPlugin.SpawnedPlugin = self
        if self._adminPlugin == None:
            try:
                self._adminPlugin = self.console.getPlugin('admin')
            except:
                self.error("Could not get admin plugin!")
                return False

        #----------------------------------- Bot Settings ---------------------------------------------
        for section in self.config.sections():
            for setting in self.config.options(section):
                try:
                    if setting == "channels":
                        if "," in self.config.get(section, setting):
                            self._settings[section][setting] = self.config.get(section, setting).split(",")
                        else:
                            self._settings[section][setting] = [1]
                            self._settings[section][setting][0] = self.config.get(section, setting)
                    else:
                        self._settings[section][setting] = self.config.get(section, setting)
                except:
                    print "exception on config load: %s" % sys.exc_info()[0]
                    if setting in ('host', 'channels', 'userfile'):
                        self.error("Could not load setting '%s->%s', plugin cannot start without it!" % (section,setting))
                        return False
                    else:
                        self.warning("Could not load setting '%s->%s', plugin falls back on default!" % (section, setting))
        for cmd in self._settings['commands']:
            self._adminPlugin.registerCommand(self, cmd, self._settings['commands'][cmd], self.getCmd(cmd), "")
        # ------------------------------------------------------ Start IRC Bot -----------------------------------------
        if self._ircbot:
            self._ircbot.exit()
        if "chatprefix" in self._settings['relay']:
            self._settings['relay']['chatprefix'] = self._settings['relay']['chatprefix'].replace("]C","")

        IrcAuthSystem.AuthenticationFile = self._settings['users']['userfile']

        self.debug("Starting pyircbot with nick=%s, ident=%s, realname=%s, host=%s, port=%i" % (self._settings['irc']['nick'], self._settings['irc']['ident'], self._settings['irc']['realname'], self._settings['irc']['host'], int(self._settings['irc']['port'])))

        botsettings = {
            'host': self._settings['irc']['host'],
            'port': int(self._settings['irc']['port']),
            'nick': self._settings['irc']['nick'],
            'ident': self._settings['irc']['ident'],
            'realname': self._settings['irc']['realname'],
        }
        if self._settings['irc']['serverpassword'] != "":
            botsettings['serverpassword'] = self._settings['irc']['serverpassword']
        self._ircbot = pyircbot.create(botsettings)

        standard = pyircbot.StandardBotRoutines(self._ircbot, botsettings)
        standard.queueJoinChannels(self._settings['irc']['channels'])
        if self._settings['irc']['nickservpassword'] != "":
            standard.queueNickServAuth(self._settings['irc']['nickservpassword'])
        standard.autoReconnect()

        self._ircbot.RegisterEventHandler(IrcEvent.UserJoined, self.onUserJoin)
        self._ircbot.RegisterEventHandler(IrcEvent.ChanmsgRecieved, self.onChanMsg)
        self._ircbot.RegisterEventHandler(IrcEvent.QueryRecieved, self.onQueryMsg)
        self._ircbot.connect()

    def startup(self):
        """\
        Initialize plugin settings
        """

        # listen for client events
        self.registerEvent(b3.events.EVT_CLIENT_SAY)
        self.registerEvent(b3.events.EVT_CLIENT_TEAM_SAY)
        self.registerEvent(b3.events.EVT_CLIENT_PRIVATE_SAY)
        self.registerEvent(b3.events.EVT_CLIENT_CONNECT)
        self.registerEvent(b3.events.EVT_CLIENT_DISCONNECT)

        # reroute console output
        self._origOutputFunc = self.console.say
        self.console.say = self.onConsoleSay
    def getCmd(self, cmd):
        cmd = 'cmd_%s' % cmd
        if hasattr(self, cmd):
            func = getattr(self, cmd)
            return func
        return None

    def getIrcBot(self):
        if self._ircbot != None:
            return self._ircbot

    def injectClientSay(self, user, msg):
        # TODO: filter commands so that broken ones wont give errors(!leveltest for example)
        if user.maxLevel > 0 and self._settings['relay']['mode'] == "rcon": # do NOT allow guests to use commands
            self.console.queueEvent(self.console.getEvent('EVT_CLIENT_SAY', msg, user))
        else:
            if self._settings['relay']['mode'] == "rcon":
                self._ircbot.notice(user.name, "You are not authorized to use this B3 Irc Bot")
            else:
                if msg[0] == "!" or msg[0] == "@" and user.maxLevel == 0:
                    msg = msg[1:] # do not let unregistered users use commands
                self.console.queueEvent(self.console.getEvent('EVT_CLIENT_SAY', msg, user))

    def onEvent(self, event):
        if not event.client or event.client.cid == None:
            return
        if self._settings['relay']['gamechat'] == "true":
            if self._ircbot:
                if event.type == b3.events.EVT_CLIENT_SAY:
                    for chan in self._settings['irc']['channels']:
                        self._ircbot.msg(chan, "%s%s" % (self._settings['relay']['chatprefix'], re.sub(self._reColor, '', "(ALL)%s: %s" % (event.client.name,event.data))))
                if event.type == b3.events.EVT_CLIENT_TEAM_SAY:
                    for chan in self._settings['irc']['channels']:
                        self._ircbot.msg(chan, "%s%s" % (self._settings['relay']['chatprefix'], re.sub(self._reColor, '', "(TEAM)%s: %s" % (event.client.name,event.data))))
                if event.type == b3.events.EVT_CLIENT_PRIVATE_SAY:
                    for chan in self._settings['irc']['channels']:
                        self._ircbot.msg(chan, "%s%s" % (self._settings['relay']['chatprefix'], re.sub(self._reColor, '', "(PM)%s: %s" % (event.client.name,event.data))))
        if self._settings['relay']['gameevents'] == "true":
            if self._ircbot:
                if event.type == b3.events.EVT_CLIENT_CONNECT:
                    for chan in self._settings['irc']['channels']:
                        self._ircbot.msg(chan, "%s%s" % (self._settings['relay']['chatprefix'], re.sub(self._reColor, '', "Player %s has joined the server" % event.client.name)))
                if event.type == b3.events.EVT_CLIENT_DISCONNECT:
                    for chan in self._settings['irc']['channels']:
                        self._ircbot.msg(chan, "%s%s" % (self._settings['relay']['chatprefix'], re.sub(self._reColor, '', "Player %s has left the server" % event.client.name)))
        self.debug("Got Command: %s" % event.type)

    def onConsoleSay(self, text):
        self._origOutputFunc(text)
        try:
            if self._settings['relay']['consolechat'] == "true":
                if self._ircbot:
                    for chan in self._settings['irc']['channels']:
                        self._ircbot.msg(chan, "%s%s" % (self._settings['relay']['chatprefix'], re.sub(self._reColor, '', "(CONSOLE) %s" % text)))
        except:
            pass
    # commands
    def cmd_ircadd(self, data, client, cmd=None):
        m = self._adminPlugin.parseUserCmd(data)
        if not m:
            sclient = client
        else:
            sclient = self._adminPlugin.findClientPrompt(m[0], client)
        if sclient:
            IrcAuthSystem.setLevel("%s!*@*" % sclient.name, sclient.maxLevel, True)
            client.message("Ingame player %s have been added with the level %i" % (str(sclient.name), int(sclient.maxLevel)))
        else:
            if("!" in m[0] and "@" in m[0]):
                try:
                    level = int(m[1])
                    IrcAuthSystem.setLevel(m[0], level, True)
                    client.message("Mask %s added with level %s" % ( m[0], str(m[1])))
                except:
                    client.message("Invalid parameter 'level' for mask")
            else:
                client.message("No client found with that name.")
    def cmd_ircrem(self, data, client, cmd=None):
        pass
    def cmd_ircexec(self, data, client, cmd=None):
        pass
    def cmd_ircon(self, data, client, cmd=None):
        res = self.console.write(data)
        client.message(res)

    # Handle pyircbot events

    def onUserJoin(self, type, data):
        if type == IrcEvent.UserJoined:
            user = IrcClient.GetClient(data.sender)
            if user.maxLevel > 0:
                self._ircbot.notice(user.name, "%s is running with mode '%s%', ready for commands" % (self._settings['irc']['nick'], self._settings['relay']['mode']))

    def onChanMsg(self, type, data):
        if type == IrcEvent.ChanmsgRecieved:
            if self._settings['relay']['mode'] == "rcon":
                if data.message[0:len(self._settings['irc']['nick'])] == self._settings['irc']['nick'] and "!" in data.message and (data.message.find("!") < len(self._settings['irc']['nick']) + 4): # highlight command sending
                   b3msg = data.message[data.message.find("!"):]
                   client = IrcClient.GetClient(data.sender)
                   self.injectClientSay(client, b3msg)
                elif (data.message[:2] == "@!" or data.message[:2] == "@@") and self._settings['relay']['broadcasts'] == 'true':
                    b3msg = data.message[1:]
                    client = IrcClient.GetClient(data.sender)
                    self.injectClientSay(client, b3msg)
            else: # full relay
                client = IrcClient.GetClient(data.sender)
                self.injectClientSay(client, data.message)
    def onQueryMsg(self, type, data):
        if type == IrcEvent.QueryRecieved:
            if data.message[0] == "!" or data.message[0] == "@":
                client = IrcClient.GetClient(data.sender)
                self.injectClientSay(client, data.message)

class IrcAuthSystem:
    AuthenticationFile = ""
    AuthenticationMap = []
    LastFileLoad = 0
    @staticmethod
    def getLevel(user):
        if(time.time() - IrcAuthSystem.LastFileLoad > 600): IrcAuthSystem.loadUsers()
        for client in IrcAuthSystem.AuthenticationMap:
            if client[2].match(user) != None:
                return int(client[1])
        return 0
    @staticmethod
    def setLevel(user, level, add=False):
        IrcAuthSystem.loadUsers()
        if add == True:
            IrcAuthSystem.AuthenticationMap.append((user, level, re.compile(user.replace("*",".*"))))
        else:
            for client in IrcAuthSystem.AuthenticationMap:
                if client[0].match(user) != None:
                    client[1] = level
        IrcAuthSystem.saveUsers()

    @staticmethod
    def loadUsers():
        try:
            IrcAuthSystem.AuthenticationMap = []
            f = open(IrcAuthSystem.AuthenticationFile)
            for line in f.readlines():
                if ":" in line:
                    d = line.split(":", 1)
                    IrcAuthSystem.AuthenticationMap.append((d[0],d[1],re.compile(d[0].replace("*",".*"))))
            IrcAuthSystem.LastFileLoad = time.time()
            f.close()
        except:
            IrcbootPlugin.SpawnedPlugin.error("IrcAuthSystem.loadUsers: could not load users! Exception: %s" % str(sys.exc_info()))
    @staticmethod
    def saveUsers():
        try:
            f = open(IrcAuthSystem.AuthenticationFile, "w")
            for client in IrcAuthSystem.AuthenticationMap:
                IrcbootPlugin.SpawnedPlugin.debug("Writing %s to the authmap" % client[0])
                if(client[1] != 0):
                    f.write("%s:%i\n" % (client[0],int(client[1])))
            f.close()
        except:
            IrcbootPlugin.SpawnedPlugin.error("IrcAuthSystem.saveUsers: could not save users! Exception: %s" % str(sys.exc_info()))

class IrcClient(b3.clients.Client):
    Clients = []
    _reColor = re.compile(r'(\^[0-9a-z])|[\x80-\xff]')
    maxLevel = 0
    id = 0
    hide = True
    _user = ""

    @staticmethod
    def GetClient(user):
        for client in IrcClient.Clients:
            if client._user == user:
                return client
        return IrcClient(IrcbootPlugin.SpawnedPlugin.getIrcBot(), user)

    def __init__(self, relaybot, user, channel=""):
        IrcClient.Clients.append(self)
        self._user = user
        self._ircbot = relaybot
        self.maxLevel = IrcAuthSystem.getLevel(user)
        self.name = user.split("!")[0]
        self.authed = True

    def getWrap(self, text, length=80, minWrapLen=150): # taken from b3 core, but without any colors, just removing them
        """Returns a sequence of lines for text that fits within the limits"""
        if not text:
            return []

        lines = []
        length = int(length)
        text = text.replace('//', '/ /')
        text = re.sub(self._reColor, '', text)
        if len(text) <= minWrapLen and "\n" not in text:
            return [text]
        #if len(re.sub(REG, '', text)) <= minWrapLen:
        #    return [text]
        for t in text.split("\n"):
            text = re.split(r'\s+', t)

            line = text[0]
            for t in text[1:]:
                if len(re.sub(self._reColor, '', line)) + len(re.sub(self._reColor, '', t)) + 2 <= length:
                    line = '%s %s' % (line, t)
                else:
                    if len(lines) > 0:
                        lines.append(line)
                    else:
                        lines.append(line)

                    m = re.findall(self._reColor, line)
                    if m:
                        color = m[-1]

                    line = t

            if len(line):
                if len(lines) > 0:
                    lines.append(line)
                else:
                    lines.append(line)

        return lines
    def message(self, message):
        lines = self.getWrap(message)
        if len(lines) > 3:
            # run threaded with msg delay to prevent bot from getting its ass handed by netsec
            thread.start_new_thread(self.msg_threaded, (lines,))
        else:
            for line in lines:
                self._ircbot.notice(self.name, "[pm]: %s" % line)
    def msg_threaded(self, lines):
        for line in lines:
            self._ircbot.notice(self.name, "[pm]: %s" % line)
            time.sleep(0.2)


text:
import React, {
  Component
} from 'react';
import ReactDOM from 'react-dom';
import Api from './Api';
import PropTypes from 'prop-types';
import '../../Res/chatroomapi.css';

class ChatroomApi extends Component {

  constructor(props) {
    super(props);
  }

  render() {
    return ( < Api url = 'chatroom' / > );
  }

}

export default ChatroomApi;

redpajama_set_name: RedPajamaGithub


text:
from __future__ import absolute_import

import uuid
import subprocess
import copy
from subprocess import PIPE

from xformmanager.storageutility import *
from xformmanager.xformdef import FormDef
from xformmanager.copy import prepare_migration_objects, migrate
from xformmanager.models import MetaDataValidationError, Metadata
from xformmanager.util import table_exists
from receiver.models import Attachment

class XFormManager(object):
    """A central location for managing xforms.  This object includes
       functionality to upload, insert into, and delete XForms.  The forms
       are translated into database tables where submission data is flattened
       out and saved for easy reporting access.

       This class makes the process of handling formdefs (our representation
       of xform schemas) and formdefmodels (db interaction layer), completely
       transparent to the programmers.
    """

    def __init__(self):
        self.su  = StorageUtility()

    def remove_schema(self, id, remove_submissions=False):
        """Remove a schema entirely, dropping its database tables and optionally
           deleting all submission to it as well."""
        self.su.remove_schema(id, remove_submissions)

    def remove_data(self, formdef_id, id, remove_submission=False):
        """Deletes a single row of data from the table, optionally
           deleting the original submission to it as well."""
        self.su.remove_instance_matching_schema(formdef_id, id, remove_submission)

    def save_schema_POST_to_file(self, stream, file_name):
        """Given a form post (instance) saves that form to disk, without
           doing any additional processing."""
        try:
            type = file_name.rsplit('.',1)[1]
        except IndexError:
            # POSTed file has no extension
            type = "xform"
        filename_on_disk = self._save_schema_stream_to_file(stream, type)
        return filename_on_disk

    def save_form_data(self, attachment):
        """Given an attachment attempt to match it to a known (registered)
           XForm and parse out its data, saving to the flattened tables and
           creating metadata for it.

           Returns True on success and False on failure"""
        return self.su.save_form_data(attachment)

    def validate_schema(self, file_name):
        """validate schema
           Returns a tuple (is_valid, error)
           is_valid - True if valid, False if not
           error - Relevant validation error
        """
        fout = open(file_name, 'r')
        formdef = FormDef(fout)
        fout.close()
        try:
            formdef.validate()
        except FormDef.FormDefError, e:
            return False, e
        except MetaDataValidationError, e:
            return False, e
        # other failures should propagate up the stack.
        return True, None

    def create_schema_from_file(self, new_file_name, domain=None):
        """Given a xsd schema, create the django models and database
           tables reqiured to submit data to that form."""
        # process xsd file to FormDef object
        fout = open(new_file_name, 'r')
        formdef = FormDef(fout, domain=domain)
        fout.close()
        formdefmodel = self.su.add_schema(formdef)
        formdefmodel.xsd_file_location = new_file_name
        formdefmodel.save()
        return formdefmodel

    def add_schema_manually(self, schema, type, domain=None):
        """Manually register a schema."""
        file_name = self._save_schema_string_to_file(schema, type)
        return self.create_schema_from_file(file_name, domain)

    def add_schema(self, file_name, input_stream, domain=None):
        """ we keep this api open for the unit tests """
        file_name = self.save_schema_POST_to_file(input_stream, file_name)
        return self.create_schema_from_file(file_name, domain)

    def repost_schema(self, form):
        """Repost a schema entirely, dropping its database tables and then
           recreating them and reposting all submissions that had previously
           matched.  Useful during upgrades."""

        # copy the original form to map properties
        form_model_copy = copy.copy(form)

        # get related objects so we can migrate them
        migration_objects = prepare_migration_objects(form)

        # store the attachments that mapped to the form for later reposting
        matching_meta_attachments = list(Metadata.objects.filter(formdefmodel=form)\
                                         .values_list('attachment__id', flat=True))

        # copy the form's XSD/XForm to a temporary location for reposting
        xsd_file = form.xsd_file_location
        temp_xsd_path = os.path.join(tempfile.gettempdir(), "form%s.xsd" % form.id)
        shutil.copy(xsd_file, temp_xsd_path)
        if form.xform_file_location:
            xform_file = form.xform_file_location
            temp_xform_path = os.path.join(tempfile.gettempdir(), "form%s.xml" % form.id)
            shutil.copy(xform_file, temp_xform_path)

        # drop
        self.remove_schema(form.id, remove_submissions=False)

        # add
        file_to_post = temp_xform_path if form.xform_file_location else temp_xsd_path
        type = "xform" if form.xform_file_location else "xsd"
        file_stream = open(file_to_post, "r")
        fileback = self._save_schema_stream_to_file(file_stream, type)
        new_form = self.create_schema_from_file(fileback, form_model_copy.domain)

        # migrate properties
        for property in ["submit_time", "submit_ip", "bytes_received", "form_display_name",
                         "date_created", "uploaded_by"]:
            setattr(new_form, property, getattr(form_model_copy, property))
        new_form.save()

        # migrate related objects
        # these two classes are covered by reposting
        classes_not_to_touch = Metadata, ElementDefModel
        migrate(migration_objects, new_form, classes_not_to_touch)

        # repost data
        for attachment_id in matching_meta_attachments:
            attach = Attachment.objects.get(id=attachment_id)
            self.save_form_data(attach)

        return new_form

    def check_schema(self, form):
        """
        Checks a schema for certain errors, logging them and returning
        them to the caller.  Errors that are checked are:
         - no xsd file found
         - no schema tables found for the form or any child tables
         - no xml files found for linked posts
        """
        errors = []
        warnings = []
        # check xsd file:
        xsd_file = form.xsd_file_location
        if not os.path.exists(xsd_file):
            errors.append("XSD file not found")
        if not form.xform_file_location:
            warnings.append("XForm file not found")

        # check schema and child tables
        if not table_exists(form.table_name):
            errors.append("Root table %s not found in the database")
        child_errors = self._children_missing_tables(form.element)
        for child in child_errors:
            errors.append("Child table %s not found in the database" % child.table_name)

        # check attachments that matched this schema
        matching_meta_attachments = Attachment.objects.filter(form_metadata__formdefmodel=form)

        missing_attachment_files = \
            [attachment for attachment in matching_meta_attachments \
             if not os.path.exists(attachment.filepath)]
        missing_submission_files = \
            [attachment.submission for attachment in matching_meta_attachments \
             if not os.path.exists(attachment.submission.raw_post)]
        if missing_attachment_files:
            errors.append("%s attachments missing filesystem entries." % len(missing_attachment_files))
        if missing_submission_files:
            errors.append("%s attachments missing submission filesystem entries." % len(missing_submission_files))
        return [errors, warnings]

    def _children_missing_tables(self, element):
        """Return a list of children with missing tables for the form, traversing
           to an arbitrary depth."""
        error_children = []
        # we really should never be pointing to ourselves, but unfortunately the
        # old code was setup this way, so we have to explicitly exclude it from
        # consideration
        for child in element.children.exclude(id=element.id):
            if not table_exists(child.table_name):
                error_children.append(child)
            deeper_errors = self._children_missing_tables(child)
            error_children.extend(deeper_errors)
        return error_children

    def _add_schema_from_file(self, file_name, domain=None):
        """ we keep this api open for the unit tests """
        name = os.path.basename(file_name)
        fin = open(file_name, 'r')
        ret = self.add_schema(name, fin, domain)
        fin.close()
        return ret

    def _save_schema_stream_to_file(self, stream, type):
        return self._save_schema_string_to_file(stream.read(), type)

    def _save_schema_string_to_file(self, input_data, type ):
        """Most of the 'new xform' functionality eventually ends up at this
           method.  Given a string of xml and a type.  If the type is an
           XForm first saves the form to disk, then converts it to an .xsd
           file and also saves that.  If the type is already xsd, just saves
           it directly to disk.

           Returns the path to the newly created file."""
        transaction_str = str(uuid.uuid1())
        new_file_name = self._base_xsd_file_name(transaction_str)
        if type.lower() != "xsd":
            # assume this is an xhtml/xform file
            # first save the raw xform
            xform_filename = new_file_name + str(".xform")
            full_name = self._save_raw_data_to_file(xform_filename, input_data)
            schema,err,has_error = form_translate( input_data )
            if has_error:
                raise IOError, "Could not convert xform to schema." + \
                               " Please verify that this is a valid xform file."
        else:
            schema = input_data
        return self._save_raw_data_to_file(new_file_name, schema)

    def _save_raw_data_to_file(self, filename_base, data):
        """Save raw data to the xform manager's storage area.
           The filename used will be what is passed in.
           Returns the full name of the file that was written."""
        full_name = self._get_full_storage_location(filename_base)
        dest_file = open(full_name, 'w')
        dest_file.write(data)
        dest_file.close()
        return full_name

    def _save_raw_file_from_stream(self, filename_base, input_stream, buffer_size=1024*1024):
        """Save a raw stream to the xform manager's storage area.
           The filename used will be what is passed in.
           Returns the full name of the file that was written."""
        full_name = self._get_full_storage_location(filename_base)
        dest_file = open(full_name, 'w')
        while True:
            buffer = input_stream.read(buffer_size)
            if buffer:
                dest_file.write(buffer)
            else:
                break
        dest_file.close()
        input_stream.close()
        return full_name

    def _get_full_storage_location(self, filename_base):
        # Just a convenience passthrough to os.path.join()
        return os.path.join(self._get_storage_directory(),
                            filename_base)

    def _get_storage_directory(self):
        """Where this app keeps its files, which is specified in the config
           local.ini as 'xsd_repository_path'"""
        return settings.RAPIDSMS_APPS['xformmanager']['xsd_repository_path']

    def _xsd_file_name(self, base_name):
        return self.get_full_storage_location(self._get_storage_directory(),
                                              self._base_xsd_file_name(base_name))

    def _base_xsd_file_name(self, base_name):
        return str(base_name) + '-xsd.xml'

class FormDefError(SyntaxError):
    """ Generic error for XFormManager.Manager """
    pass

def form_translate(input_data):
    '''Translates an xform into an xsd file'''
    return _form_translate(input_data, "schema")

def readable_form(input_data):
    '''Gets a readable display of an xform'''
    return _form_translate(input_data, "summary")

def csv_dump(input_data):
    '''Get the csv translation file from an xform'''
    return _form_translate(input_data, "csvdump")

def _form_translate(input_data, operation):
    """Utility for interacting with the form_translate jar, which provides
       functionality for a number of different useful form tools including
       converting a form to an xsd file, turning a form into a more readable
       format, and generating a list of translations as an exportable .csv
       file."""

    # In case you're trying to produce this behavior on the command line for
    # rapid testing, the command that eventually gets called is:
    # java -jar form_translate.jar <operation> < form.xml > output
    #
    # You can pass in a filename or a full string/stream of xml data
    logging.debug ("form_translate %s: begin subprocess - java -jar form_translate.jar %s < input file > " \
                   % (operation, operation))
    p = subprocess.Popen(["java","-jar",
                          os.path.join(settings.RAPIDSMS_APPS['xformmanager']['xform_translate_path'],
                                       "form_translate.jar"),
                          operation],
                          shell=False,
                          stdout=subprocess.PIPE,stdin=subprocess.PIPE,
                          stderr=subprocess.PIPE)
    logging.debug ("form_translate %s: begin communicate with subprocess" % operation)

    p.stdin.write(input_data)
    p.stdin.flush()
    p.stdin.close()

    output = p.stdout.read()
    error = p.stderr.read()

    # error has data even when things go perfectly, so return both
    # the full stream and a boolean indicating whether there was an
    # error.  This should be fixed in a cleaner way.
    has_error = "exception" in error.lower()
    logging.debug ("form_translate %s: finish communicate with subprocess" % operation)
    return (output,error, has_error)


text:
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Notice" table="notice">
    <id name="idnotice" type="integer" column="idnotice">
      <generator strategy="IDENTITY"/>
    </id>
    <field name="titre" type="string" column="titre" length="45" nullable="false"/>
    <field name="fonctionnalite" type="string" column="fonctionnalite" length="45" nullable="false"/>
    <field name="explication" type="text" column="explication" nullable="false"/>
    <many-to-one field="projetprojet" target-entity="Projet">
      <join-columns>
        <join-column name="projet_idprojet" referenced-column-name="idprojet"/>
      </join-columns>
    </many-to-one>
  </entity>
</doctrine-mapping>


text:
Docker container for shipping Lumen apps

### Getting started

  Copy the Dockerfile to the project root

    wget https://raw.githubusercontent.com/gayanhewa/lumen-container/master/Dockerfile

  Build the container :

    docker build -t <my-app-name> .

  Run the container :

    docker run -d -p 8080:80 <my-app-name>

  When we are developing the application , it becomes cumbersome to rebuild each time to test a change. To overcome this you can mount a local directory / file as a mounted volume into the container. It can be done in the following manner.

    docker run -d -v /local/directory/path:/var/www -p 80:80 <my-app-name>

  Access the app on http://localhost:8080

  The base image gayanhewa/lumen comes in with a single virtualhost configured for the container , php5-fpm backed in with nginx.

  If you want to make changes to the image do the following :

    docker run -it <name-used-to-build> bash

  Install apps , change configuration settings accordingly.

    docker commit <container_id> <your-user-name>/<image-name>:<tag>

    docker commit sad123sad1as gayanhewa/mynewlumen:01

  To get the container id you can use :

    docker ps -a

  Once commited you can publish :

    docker push <your-user-name>/<image-name>:<tag>

### Lumen Enviorment Variables

  In you can either add the .env file to the project root or use Dockerfile to update the env variable values [supported](https://github.com/laravel/lumen/blob/master/.env.example) by lumen.

  For an example the definition of the DB_CONNECTION can be found in the Dockerfile.


text:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#778899"
    android:id="@+id/linearLayout"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="20dp"
        >

        <TextView
            android:layout_marginLeft="40dp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/textView_Hour"

            android:text="00"
            android:textSize="70sp"
            android:gravity="center"
            android:layout_weight="1"
            />
        <TextView
            android:layout_marginRight="40dp"
            android:layout_marginLeft="20dp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/textView_Minute"
            android:gravity="center"
            android:text="00"
            android:textSize="70sp"

            />
    </LinearLayout>

    <LinearLayout
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
        <LinearLayout
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_weight="1"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="载入中..."
                android:id="@+id/textView_weather"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="载入中..."
                android:id="@+id/textView_place"
                />
        </LinearLayout>
        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@drawable/d00"
            android:layout_weight="1"
            android:id="@+id/imageView_picture"
            />
        <LinearLayout
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_weight="1"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="载入中..."
                android:id="@+id/textView_date"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="载入中..."
                android:id="@+id/textView_lunar_date"
                />
        </LinearLayout>

    </LinearLayout>

</LinearLayout>


text:
using PatchKit.Unity.Patcher.AppUpdater.Status;
using PatchKit.Unity.Patcher.Cancellation;

namespace PatchKit.Unity.Patcher.AppUpdater.Commands
{
    public interface IAppUpdaterCommand
    {
        void Execute(CancellationToken cancellationToken);

        void Prepare(UpdaterStatus status, CancellationToken cancellationToken);
    }
}


text:
typedef void(WINAPI *pfnGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);
extern pfnGetSystemTimeAsFileTime g_pfnGetSystemTimeAsFileTime;

void WINAPI InitializeGetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
{
    pfnGetSystemTimeAsFileTime func = NULL;

#ifndef FEATURE_PAL
    HMODULE hKernel32 = WszLoadLibrary(W("kernel32.dll"));
    if (hKernel32 != NULL)
    {
        func = (pfnGetSystemTimeAsFileTime)GetProcAddress(hKernel32, "GetSystemTimePreciseAsFileTime");
        if (func != NULL)
        {
            // GetSystemTimePreciseAsFileTime exists and we'd like to use it.  However, on
            // misconfigured systems, it's possible for the "precise" time to be inaccurate:
            //     https://github.com/dotnet/coreclr/issues/14187
            // If it's inaccurate, though, we expect it to be wildly inaccurate, so as a
            // workaround/heuristic, we get both the "normal" and "precise" times, and as
            // long as they're close, we use the precise one. This workaround can be removed
            // when we better understand what's causing the drift and the issue is no longer
            // a problem or can be better worked around on all targeted OSes.

            FILETIME systemTimeResult;
            ::GetSystemTimeAsFileTime(&systemTimeResult);

            FILETIME preciseSystemTimeResult;
            func(&preciseSystemTimeResult);

            LONG64 systemTimeLong100ns = (LONG64)((((ULONG64)systemTimeResult.dwHighDateTime) << 32) | (ULONG64)systemTimeResult.dwLowDateTime);
            LONG64 preciseSystemTimeLong100ns = (LONG64)((((ULONG64)preciseSystemTimeResult.dwHighDateTime) << 32) | (ULONG64)preciseSystemTimeResult.dwLowDateTime);

            const INT32 THRESHOLD_100NS = 1000000; // 100ms
            if (abs(preciseSystemTimeLong100ns - systemTimeLong100ns) > THRESHOLD_100NS)
            {
                // Too much difference.  Don't use GetSystemTimePreciseAsFileTime.
                func = NULL;
            }
        }
    }
    if (func == NULL)
#endif
    {
        func = &::GetSystemTimeAsFileTime;
    }

    g_pfnGetSystemTimeAsFileTime = func;
    func(lpSystemTimeAsFileTime);
}

pfnGetSystemTimeAsFileTime g_pfnGetSystemTimeAsFileTime = &InitializeGetSystemTimeAsFileTime;

FCIMPL0(INT64, SystemNative::__GetSystemTimeAsFileTime)
{
    FCALL_CONTRACT;

    INT64 timestamp;
    g_pfnGetSystemTimeAsFileTime((FILETIME*)&timestamp);

#if BIGENDIAN
    timestamp = (INT64)(((UINT64)timestamp >> 32) | ((UINT64)timestamp << 32));
#endif

    return timestamp;
}
FCIMPLEND;

FCIMPL0(UINT32, SystemNative::GetTickCount)
{
    FCALL_CONTRACT;

    return ::GetTickCount();
}
FCIMPLEND;

VOID QCALLTYPE SystemNative::Exit(INT32 exitcode)
{
    QCALL_CONTRACT;

    BEGIN_QCALL;

    // The exit code for the process is communicated in one of two ways.  If the
    // entrypoint returns an 'int' we take that.  Otherwise we take a latched
    // process exit code.  This can be modified by the app via setting
    // Environment's ExitCode property.
    SetLatchedExitCode(exitcode);

    ForceEEShutdown();

    END_QCALL;
}

FCIMPL1(VOID,SystemNative::SetExitCode,INT32 exitcode)
{
    FCALL_CONTRACT;

    // The exit code for the process is communicated in one of two ways.  If the
    // entrypoint returns an 'int' we take that.  Otherwise we take a latched
    // process exit code.  This can be modified by the app via setting
    // Environment's ExitCode property.
    SetLatchedExitCode(exitcode);
}
FCIMPLEND

FCIMPL0(INT32, SystemNative::GetExitCode)
{
    FCALL_CONTRACT;

    // Return whatever has been latched so far.  This is uninitialized to 0.
    return GetLatchedExitCode();
}
FCIMPLEND

void QCALLTYPE SystemNative::_GetCommandLine(QCall::StringHandleOnStack retString)
{
    QCALL_CONTRACT;

    BEGIN_QCALL;

    LPCWSTR commandLine;

    if (g_pCachedCommandLine != NULL)
    {
        // Use the cached command line if available
        commandLine = g_pCachedCommandLine;
    }
    else
    {
        commandLine = WszGetCommandLine();
        if (commandLine==NULL)
            COMPlusThrowOM();
    }

    retString.Set(commandLine);

    END_QCALL;
}

FCIMPL0(Object*, SystemNative::GetCommandLineArgs)
{
    FCALL_CONTRACT;

    PTRARRAYREF strArray = NULL;

    HELPER_METHOD_FRAME_BEGIN_RET_1(strArray);

    LPWSTR commandLine;

    if (g_pCachedCommandLine != NULL)
    {
        // Use the cached command line if available
        commandLine = g_pCachedCommandLine;
    }
    else
    {
        commandLine = WszGetCommandLine();
        if (commandLine==NULL)
            COMPlusThrowOM();
    }

    DWORD numArgs = 0;
    LPWSTR* argv = SegmentCommandLine(commandLine, &numArgs);
    if (!argv)
        COMPlusThrowOM();

    _ASSERTE(numArgs > 0);

    strArray = (PTRARRAYREF) AllocateObjectArray(numArgs, g_pStringClass);
    // Copy each argument into new Strings.
    for(unsigned int i=0; i<numArgs; i++)
    {
        STRINGREF str = StringObject::NewString(argv[i]);
        STRINGREF * destData = ((STRINGREF*)(strArray->GetDataPtr())) + i;
        SetObjectReference((OBJECTREF*)destData, (OBJECTREF)str, strArray->GetAppDomain());
    }
    delete [] argv;

    HELPER_METHOD_FRAME_END();

    return OBJECTREFToObject(strArray);
}
FCIMPLEND

// Return a method info for the method were the exception was thrown
FCIMPL1(ReflectMethodObject*, SystemNative::GetMethodFromStackTrace, ArrayBase* pStackTraceUNSAFE)
{
    FCALL_CONTRACT;

    I1ARRAYREF pArray(static_cast<I1Array *>(pStackTraceUNSAFE));
    StackTraceArray stackArray(pArray);

    if (!stackArray.Size())
        return NULL;

    // The managed stacktrace classes always returns typical method definition, so we don't need to bother providing exact instantiation.
    // Generics::GetExactInstantiationsOfMethodAndItsClassFromCallInformation(pElements[0].pFunc, pElements[0].pExactGenericArgsToken, pTypeHandle, &pMD);

    MethodDesc* pFunc = stackArray[0].pFunc;

    // Strip the instantiation to make sure that the reflection never gets a bad method desc back.
    REFLECTMETHODREF refRet = NULL;

    HELPER_METHOD_FRAME_BEGIN_RET_0()
    pFunc = pFunc->LoadTypicalMethodDefinition();
    refRet = pFunc->GetStubMethodInfo();
    _ASSERTE(pFunc->IsRuntimeMethodHandle());

    HELPER_METHOD_FRAME_END();

    return (ReflectMethodObject*)OBJECTREFToObject(refRet);
}
FCIMPLEND

FCIMPL0(StringObject*, SystemNative::_GetModuleFileName)
{
    FCALL_CONTRACT;

    STRINGREF   refRetVal = NULL;

    HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
    if (g_pCachedModuleFileName)
    {
        refRetVal = StringObject::NewString(g_pCachedModuleFileName);
    }
    else
    {
        PathString wszFilePathString;

        DWORD lgth = WszGetModuleFileName(NULL, wszFilePathString);
        if (!lgth)
        {
            COMPlusThrowWin32();
        }

        refRetVal = StringObject::NewString(wszFilePathString.GetUnicode());
    }
    HELPER_METHOD_FRAME_END();

    return (StringObject*)OBJECTREFToObject(refRetVal);
}
FCIMPLEND

FCIMPL0(StringObject*, SystemNative::GetRuntimeDirectory)
{
    FCALL_CONTRACT;

    STRINGREF   refRetVal   = NULL;
    DWORD dwFile = MAX_LONGPATH+1;

    HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
    SString wszFilePathString;

    WCHAR * wszFile = wszFilePathString.OpenUnicodeBuffer(dwFile);
    HRESULT hr = GetInternalSystemDirectory(wszFile, &dwFile);
    wszFilePathString.CloseBuffer(dwFile);

    if(FAILED(hr))
        COMPlusThrowHR(hr);

    dwFile--; // remove the trailing NULL

    if(dwFile)
        refRetVal = StringObject::NewString(wszFile, dwFile);

    HELPER_METHOD_FRAME_END();
    return (StringObject*)OBJECTREFToObject(refRetVal);
}
FCIMPLEND

INT32 QCALLTYPE SystemNative::GetProcessorCount()
{
    QCALL_CONTRACT;

    INT32 processorCount = 0;

    BEGIN_QCALL;

    CPUGroupInfo::EnsureInitialized();

    if(CPUGroupInfo::CanEnableThreadUseAllCpuGroups())
    {
        processorCount = CPUGroupInfo::GetNumActiveProcessors();
    }

    // Processor count will be 0 if CPU groups are disabled/not supported
    if(processorCount == 0)
    {
        SYSTEM_INFO systemInfo;
        ZeroMemory(&systemInfo, sizeof(systemInfo));

        GetSystemInfo(&systemInfo);

        processorCount = systemInfo.dwNumberOfProcessors;
    }

#ifdef FEATURE_PAL
    uint32_t cpuLimit;

    if (PAL_GetCpuLimit(&cpuLimit) && cpuLimit < processorCount)
        processorCount = cpuLimit;
#endif

    END_QCALL;

    return processorCount;
}

FCIMPL0(FC_BOOL_RET, SystemNative::HasShutdownStarted)
{
    FCALL_CONTRACT;

    // Return true if the EE has started to shutdown and is now going to
    // aggressively finalize objects referred to by static variables OR
    // if someone is unloading the current AppDomain AND we have started
    // finalizing objects referred to by static variables.
    FC_RETURN_BOOL((g_fEEShutDown & ShutDown_Finalize2) || GetAppDomain()->IsFinalizing());
}
FCIMPLEND

// FailFast is supported in BCL.small as internal to support failing fast in places where EEE used to be thrown.
//
// Static message buffer used by SystemNative::FailFast to avoid reliance on a
// managed string object buffer. This buffer is not always used, see comments in
// the method below.
WCHAR g_szFailFastBuffer[256];
#define FAIL_FAST_STATIC_BUFFER_LENGTH (sizeof(g_szFailFastBuffer) / sizeof(WCHAR))

// This is the common code for FailFast processing that is wrapped by the two
// FailFast FCalls below.
void SystemNative::GenericFailFast(STRINGREF refMesgString, EXCEPTIONREF refExceptionForWatsonBucketing, UINT_PTR retAddress, UINT exitCode, STRINGREF refErrorSourceString)
{
    CONTRACTL
    {
        THROWS;
        GC_TRIGGERS;
        MODE_COOPERATIVE;
        SO_TOLERANT;
    }CONTRACTL_END;

    struct
    {
        STRINGREF refMesgString;
        EXCEPTIONREF refExceptionForWatsonBucketing;
        STRINGREF refErrorSourceString;
    } gc;
    ZeroMemory(&gc, sizeof(gc));

    GCPROTECT_BEGIN(gc);

    gc.refMesgString = refMesgString;
    gc.refExceptionForWatsonBucketing = refExceptionForWatsonBucketing;
    gc.refErrorSourceString = refErrorSourceString;

    // Managed code injected FailFast maps onto the unmanaged version
    // (EEPolicy::HandleFatalError) in the following manner: the exit code is
    // always set to COR_E_FAILFAST and the address passed (usually a failing
    // EIP) is in fact the address of a unicode message buffer (explaining the
    // reason for the fault).
    // The message string comes from a managed string object so we can't rely on
    // the buffer remaining in place below our feet. But equally we don't want
    // to inject failure points (by, for example, allocating a heap buffer or a
    // pinning handle) when we have a much higher chance than usual of actually
    // tripping those failure points and eradicating useful debugging info.
    // We employ various strategies to deal with this:
    //   o  If the message is small enough we copy it into a static buffer
    //      (g_szFailFastBuffer).
    //   o  Otherwise we try to allocate a buffer of the required size on the
    //      heap. This buffer will be leaked.
    //   o  If the allocation above fails we return to the static buffer and
    //      truncate the message.
    //
    // Another option would seem to be to implement a new frame type that
    // protects object references as pinned, but that seems like overkill for
    // just this problem.
    WCHAR  *pszMessage = NULL;
    DWORD   cchMessage = (gc.refMesgString == NULL) ? 0 : gc.refMesgString->GetStringLength();

    WCHAR * errorSourceString = NULL;

    if (gc.refErrorSourceString != NULL)
    {
        DWORD cchErrorSource = gc.refErrorSourceString->GetStringLength();
        errorSourceString = new (nothrow) WCHAR[cchErrorSource + 1];

        if (errorSourceString != NULL)
        {
            memcpyNoGCRefs(errorSourceString, gc.refErrorSourceString->GetBuffer(), cchErrorSource * sizeof(WCHAR));
            errorSourceString[cchErrorSource] = W('\0');
        }
    }

    if (cchMessage < FAIL_FAST_STATIC_BUFFER_LENGTH)
    {
        pszMessage = g_szFailFastBuffer;
    }
    else
    {
        // We can fail here, but we can handle the fault.
        CONTRACT_VIOLATION(FaultViolation);
        pszMessage = new (nothrow) WCHAR[cchMessage + 1];
        if (pszMessage == NULL)
        {
            // Truncate the message to what will fit in the static buffer.
            cchMessage = FAIL_FAST_STATIC_BUFFER_LENGTH - 1;
            pszMessage = g_szFailFastBuffer;
        }
    }

    if (cchMessage > 0)
        memcpyNoGCRefs(pszMessage, gc.refMesgString->GetBuffer(), cchMessage * sizeof(WCHAR));
    pszMessage[cchMessage] = W('\0');

    if (cchMessage == 0) {
        WszOutputDebugString(W("CLR: Managed code called FailFast without specifying a reason.\r\n"));
    }
    else {
        WszOutputDebugString(W("CLR: Managed code called FailFast, saying \""));
        WszOutputDebugString(pszMessage);
        WszOutputDebugString(W("\"\r\n"));
    }

    Thread *pThread = GetThread();

#ifndef FEATURE_PAL
    // If we have the exception object, then try to setup
    // the watson bucket if it has any details.
    // On CoreCLR, Watson may not be enabled. Thus, we should
    // skip this, if required.
    if (IsWatsonEnabled())
    {
        BEGIN_SO_INTOLERANT_CODE(pThread);
        if ((gc.refExceptionForWatsonBucketing == NULL) || !SetupWatsonBucketsForFailFast(gc.refExceptionForWatsonBucketing))
        {
            PTR_EHWatsonBucketTracker pUEWatsonBucketTracker = pThread->GetExceptionState()->GetUEWatsonBucketTracker();
            _ASSERTE(pUEWatsonBucketTracker != NULL);
            pUEWatsonBucketTracker->SaveIpForWatsonBucket(retAddress);
            pUEWatsonBucketTracker->CaptureUnhandledInfoForWatson(TypeOfReportedError::FatalError, pThread, NULL);
            if (pUEWatsonBucketTracker->RetrieveWatsonBuckets() == NULL)
            {
                pUEWatsonBucketTracker->ClearWatsonBucketDetails();
            }
        }
        END_SO_INTOLERANT_CODE;
    }
#endif // !FEATURE_PAL

    // stash the user-provided exception object. this will be used as
    // the inner exception object to the FatalExecutionEngineException.
    if (gc.refExceptionForWatsonBucketing != NULL)
        pThread->SetLastThrownObject(gc.refExceptionForWatsonBucketing);

    EEPolicy::HandleFatalError(exitCode, retAddress, pszMessage, NULL, errorSourceString);

    GCPROTECT_END();
}

// Note: Do not merge this FCALL method with any other FailFast overloads.
// Watson uses the managed FailFast method with one String for crash dump bucketization.
FCIMPL1(VOID, SystemNative::FailFast, StringObject* refMessageUNSAFE)
{
    FCALL_CONTRACT;

    STRINGREF refMessage = (STRINGREF)refMessageUNSAFE;

    HELPER_METHOD_FRAME_BEGIN_1(refMessage);

    // The HelperMethodFrame knows how to get the return address.
    UINT_PTR retaddr = HELPER_METHOD_FRAME_GET_RETURN_ADDRESS();

    // Call the actual worker to perform failfast
    GenericFailFast(refMessage, NULL, retaddr, COR_E_FAILFAST, NULL);

    HELPER_METHOD_FRAME_END();
}
FCIMPLEND

FCIMPL2(VOID, SystemNative::FailFastWithExitCode, StringObject* refMessageUNSAFE, UINT exitCode)
{
    FCALL_CONTRACT;

    STRINGREF refMessage = (STRINGREF)refMessageUNSAFE;

    HELPER_METHOD_FRAME_BEGIN_1(refMessage);

    // The HelperMethodFrame knows how to get the return address.
    UINT_PTR retaddr = HELPER_METHOD_FRAME_GET_RETURN_ADDRESS();

    // Call the actual worker to perform failfast
    GenericFailFast(refMessage, NULL, retaddr, exitCode, NULL);

    HELPER_METHOD_FRAME_END();
}
FCIMPLEND

FCIMPL2(VOID, SystemNative::FailFastWithException, StringObject* refMessageUNSAFE, ExceptionObject* refExceptionUNSAFE)
{
    FCALL_CONTRACT;

    STRINGREF refMessage = (STRINGREF)refMessageUNSAFE;
    EXCEPTIONREF refException = (EXCEPTIONREF)refExceptionUNSAFE;

    HELPER_METHOD_FRAME_BEGIN_2(refMessage, refException);

    // The HelperMethodFrame knows how to get the return address.
    UINT_PTR retaddr = HELPER_METHOD_FRAME_GET_RETURN_ADDRESS();

    // Call the actual worker to perform failfast
    GenericFailFast(refMessage, refException, retaddr, COR_E_FAILFAST, NULL);

    HELPER_METHOD_FRAME_END();
}
FCIMPLEND

FCIMPL3(VOID, SystemNative::FailFastWithExceptionAndSource, StringObject* refMessageUNSAFE, ExceptionObject* refExceptionUNSAFE, StringObject* errorSourceUNSAFE)
{
    FCALL_CONTRACT;

    STRINGREF refMessage = (STRINGREF)refMessageUNSAFE;
    EXCEPTIONREF refException = (EXCEPTIONREF)refExceptionUNSAFE;
    STRINGREF errorSource = (STRINGREF)errorSourceUNSAFE;

    HELPER_METHOD_FRAME_BEGIN_3(refMessage, refException, errorSource);

    // The HelperMethodFrame knows how to get the return address.
    UINT_PTR retaddr = HELPER_METHOD_FRAME_GET_RETURN_ADDRESS();

    // Call the actual worker to perform failfast
    GenericFailFast(refMessage, refException, retaddr, COR_E_FAILFAST, errorSource);

    HELPER_METHOD_FRAME_END();
}
FCIMPLEND

FCIMPL0(FC_BOOL_RET, SystemNative::IsServerGC)
{
    FCALL_CONTRACT;

    FC_RETURN_BOOL(GCHeapUtilities::IsServerHeap());
}
FCIMPLEND

#ifdef FEATURE_COMINTEROP

BOOL QCALLTYPE SystemNative::WinRTSupported()
{
    QCALL_CONTRACT;

    BOOL hasWinRT = FALSE;

    BEGIN_QCALL;
    hasWinRT = ::WinRTSupported();
    END_QCALL;

    return hasWinRT;
}

#endif // FEATURE_COMINTEROP


text:
define(function ()
{
	'use strict';

	return {

		fire : function ($topic, $data)
		{
			if (!this._topics || !this._topics[$topic]) { return; }

			var subscribers = this._topics[$topic];
			for (var i = 0, subscribersLength = subscribers.length; i < subscribersLength; i += 1)
			{
				subscribers[i]($data);
			}
		},

		on : function ($topic, $subscriber)
		{
			this._topics = this._topics || {};
			this._topics[$topic] = this._topics[$topic] || [];
			this._topics[$topic].push($subscriber);
		},

		off : function ($topic, $subscriber)
		{
			if (!$topic)
			{
				this._topics = undefined;
				return;
			}
			if (!$subscriber)
			{
				this._topics[$topic] = undefined;
				return;
			}

			if (this._topics[$topic].indexOf($subscriber) === -1)
			{
				throw new Error('No listener');
			}

			this._topics[$topic].splice(this._topics[$topic].indexOf($subscriber), 1);
			this._topics[$topic] = this._topics[$topic].length < 0 ? this._topics[$topic] : undefined;
		}
	};
});


text:
module RuboCop
  module Cop
    module Rails
      # This cop enforces the consistent use of action filters methods.
      #
      # The cop is configurable and the enforce the use of older
      # something_filter methods or the newer something_action methods.
      class ActionFilter < Cop
        include ConfigurableEnforcedStyle

        MSG = 'Prefer `%s` over `%s`.'.freeze

        FILTER_METHODS = [
          :after_filter,
          :append_after_filter,
          :append_around_filter,
          :append_before_filter,
          :around_filter,
          :before_filter,
          :prepend_after_filter,
          :prepend_around_filter,
          :prepend_before_filter,
          :skip_after_filter,
          :skip_around_filter,
          :skip_before_filter,
          :skip_filter
        ].freeze

        ACTION_METHODS = [
          :after_action,
          :append_after_action,
          :append_around_action,
          :append_before_action,
          :around_action,
          :before_action,
          :prepend_after_action,
          :prepend_around_action,
          :prepend_before_action,
          :skip_after_action,
          :skip_around_action,
          :skip_before_action,
          :skip_action_callback
        ].freeze

        def on_block(node)
          method, _args, _body = *node

          check_method_node(method)
        end

        def on_send(node)
          receiver, _method_name, *_args = *node

          check_method_node(node) if receiver.nil?
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.replace(node.loc.selector,
                              preferred_method(node.loc.selector.source).to_s)
          end
        end

        private

        def check_method_node(node)
          _receiver, method_name, *_args = *node
          return unless offending_method?(method_name)

          add_offense(node, :selector,
                      format(MSG,
                             preferred_method(method_name),
                             method_name))
        end

        def offending_method?(method_name)
          bad_methods.include?(method_name)
        end

        def bad_methods
          style == :action ? FILTER_METHODS : ACTION_METHODS
        end

        def good_methods
          style == :action ? ACTION_METHODS : FILTER_METHODS
        end

        def preferred_method(method)
          good_methods[bad_methods.index(method.to_sym)]
        end
      end
    end
  end
end


text:
.. _mark:

Marking test functions with attributes
=================================================================

By using the ``pytest.mark`` helper you can easily set
metadata on your test functions. There are
some builtin markers, for example:

* :ref:`skip <skip>` - always skip a test function
* :ref:`skipif <skipif>` - skip a test function if a certain condition is met
* :ref:`xfail <xfail>` - produce an "expected failure" outcome if a certain
  condition is met
* :ref:`parametrize <parametrizemark>` to perform multiple calls
  to the same test function.

It's easy to create custom markers or to apply markers
to whole test classes or modules. See :ref:`mark examples` for examples
which also serve as documentation.

.. note::

    Marks can only be applied to tests, having no effect on
    :ref:`fixtures <fixtures>`.


text:
package com.thinkbiganalytics.nifi.provenance.model;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thinkbiganalytics.nifi.provenance.KyloProcessorFlowType;
import com.thinkbiganalytics.nifi.provenance.model.util.ProvenanceEventUtil;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * This is used in both the NiFi KyloReportingTask and also in Kylo Operations Manager
 *
 *
 * Note: Any modifications to this class will result in the need to update kylo-services and the KyloReportingTask nar
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProvenanceEventRecordDTO implements Serializable {

    private static final long serialVersionUID = 4464985246055158127L;

    private static final Logger log = LoggerFactory.getLogger(ProvenanceEventRecordDTO.class);

    private transient AtomicBoolean processed = new AtomicBoolean(false);

    /**
     * Indicates the start of a Root Flow file
     */
    private boolean isStartOfJob;

    /**
     * Indicates the end of a Root Flow File
     */
    private boolean isEndOfJob;

    /**
     * indicates it is the final event in a root file or if the root file has child root flow files (as a result of a Merge) when this is true it is the final event for all of the root flow files
     */
    private boolean isFinalJobEvent;

    /**
     * inidcates if this is a Batch Root Flow file
     */
    private boolean isBatchJob;

    /**
     * Track all failures related to this jobFlowFileId if this is a finalJobEvent
     */
    private boolean hasFailedEvents;

    private Long previousEventId;

    /**
     * The previous events flow file id
     */
    private String previousFlowfileId;

    /**
     * the event Time of the previous event to help determine event duration
     */
    private DateTime previousEventTime;

    private DateTime startTime;

    private String id;
    private Long eventId;
    private DateTime eventTime;

    private Long eventDuration;
    private String eventType;
    private String flowFileUuid;
    private String fileSize;
    private Long fileSizeBytes;
    private String clusterNodeId;
    private String clusterNodeAddress;
    private String groupId;
    private String componentId;
    private String componentType;
    private String componentName;
    private List<String> parentUuids;
    private List<String> childUuids;
    private String details;

    private String sourceConnectionIdentifier;

    private Long inputContentClaimFileSizeBytes;
    private String inputContentClaimFileSize;
    private Long outputContentClaimFileSizeBytes;
    private String outputContentClaimFileSize;

    private Set<String> relatedRootFlowFiles;

    private boolean isStartOfFlowFile;

    /**
     * Indicates if the processor attached to this event {@code componentId}  is a FAILURE, WARNING,
     */
    private KyloProcessorFlowType processorType;

    /**
     * if this event came from a processor or connection that has the keyword "failure" or is "Auto terminated by Failure event"
     */
    private boolean isFailure;

    /**
     * set when the aggregator is determining if the flow of events indicate a stream (rapid fire)
     */
    private boolean stream;

    /**
     * The flow file id the corresponds to the parent /starting event
     */
    private String jobFlowFileId;

    /**
     * The Id that corresponds to the first event that started the job
     */
    private Long jobEventId;

    //flow information  the following are set via looking at the rest api graph of events

    /**
     * The Feed name  {category}.{feed}
     */
    private String feedName;
    /**
     * The processgroup that is holding the flow for this feed
     */
    private String feedProcessGroupId;

    private String batchId;

    private String relationship;

    @JsonProperty("updatedAttributes")
    private Map<String, String> updatedAttributes;

    @JsonProperty("previousAttributes")
    private Map<String, String> previousAttributes;

    @JsonIgnore
    private Map<String, Object> additionalProperties = new HashMap<String, Object>();

    @JsonProperty("attributes")
    private Map<String, String> attributeMap;
    private FeedFlowFile feedFlowFile;

    public ProvenanceEventRecordDTO() {

    }

    public FeedFlowFile getFeedFlowFile() {
        return feedFlowFile;
    }

    public void setFeedFlowFile(FeedFlowFile feedFlowFile) {
        this.feedFlowFile = feedFlowFile;
    }

    public String getFeedName() {
        return feedName;
    }

    public void setFeedName(String feedName) {
        this.feedName = feedName;
    }

    public boolean isTerminatedByFailureRelationship() {
        return ProvenanceEventUtil.isTerminatedByFailureRelationship(this);
    }

    public boolean isEndingFlowFileEvent() {
        return ProvenanceEventUtil.isEndingFlowFileEvent(this);
    }

    public String getRelationship() {
        return relationship;
    }

    public void setRelationship(String relationship) {
        this.relationship = relationship;
    }

    @JsonAnyGetter
    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    public void setAdditionalProperties(Map<String, Object> additionalProperties) {
        this.additionalProperties = additionalProperties;
    }

    @JsonAnySetter
    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }

    @JsonProperty("attributes")
    public Map<String, String> getAttributeMap() {
        return attributeMap;
    }

    @JsonProperty("attributes")
    public void setAttributeMap(Map<String, String> attributeMap) {
        this.attributeMap = attributeMap;
    }

    @JsonProperty("updatedAttributes")
    public Map<String, String> getUpdatedAttributes() {
        return updatedAttributes;
    }

    @JsonProperty("updatedAttributes")
    public void setUpdatedAttributes(Map<String, String> updatedAttributes) {
        this.updatedAttributes = updatedAttributes;
    }

    @JsonProperty("previousAttributes")
    public Map<String, String> getPreviousAttributes() {
        return previousAttributes;
    }

    @JsonProperty("previousAttributes")
    public void setPreviousAttributes(Map<String, String> previousAttributes) {
        this.previousAttributes = previousAttributes;
    }

    public String getSourceConnectionIdentifier() {
        return sourceConnectionIdentifier;
    }

    public void setSourceConnectionIdentifier(String sourceConnectionIdentifier) {
        this.sourceConnectionIdentifier = sourceConnectionIdentifier;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Long getEventId() {
        return eventId;
    }

    public void setEventId(Long eventId) {
        this.eventId = eventId;
    }

    public Long getEventDuration() {
        return eventDuration;
    }

    public void setEventDuration(Long eventDuration) {
        this.eventDuration = eventDuration;
    }

    public String getEventType() {
        return eventType;
    }

    public void setEventType(String eventType) {
        this.eventType = eventType;
    }

    public String getFlowFileUuid() {
        return flowFileUuid;
    }

    public void setFlowFileUuid(String flowFileUuid) {
        this.flowFileUuid = flowFileUuid;
    }

    public String getFileSize() {
        return fileSize;
    }

    public void setFileSize(String fileSize) {
        this.fileSize = fileSize;
    }

    public Long getFileSizeBytes() {
        return fileSizeBytes;
    }

    public void setFileSizeBytes(Long fileSizeBytes) {
        this.fileSizeBytes = fileSizeBytes;
    }

    public String getClusterNodeId() {
        return clusterNodeId;
    }

    public void setClusterNodeId(String clusterNodeId) {
        this.clusterNodeId = clusterNodeId;
    }

    public String getClusterNodeAddress() {
        return clusterNodeAddress;
    }

    public void setClusterNodeAddress(String clusterNodeAddress) {
        this.clusterNodeAddress = clusterNodeAddress;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getComponentId() {
        return componentId;
    }

    public void setComponentId(String componentId) {
        this.componentId = componentId;
    }

    public String getComponentType() {
        return componentType;
    }

    public void setComponentType(String componentType) {
        this.componentType = componentType;
    }

    public String getComponentName() {
        return componentName;
    }

    public void setComponentName(String componentName) {
        this.componentName = componentName;
    }

    public List<String> getParentUuids() {
        return parentUuids;
    }

    public void setParentUuids(List<String> parentUuids) {
        this.parentUuids = parentUuids;
    }

    public List<String> getChildUuids() {
        return childUuids;
    }

    public void setChildUuids(List<String> childUuids) {
        this.childUuids = childUuids;
    }

    public void addChildUuid(String childFlowFileId) {
        if (childUuids == null) {
            childUuids = new ArrayList<>();
        }
        if (!childUuids.contains(childFlowFileId)) {
            childUuids.add(childFlowFileId);
        }
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public boolean isStartOfFlowFile() {
        return isStartOfFlowFile;
    }

    public void setStartOfFlowFile(boolean startOfFlowFile) {
        isStartOfFlowFile = startOfFlowFile;
    }

    public void setPreviousEvent(ProvenanceEventRecordDTO previousEvent) {
        if (previousEvent != null) {
            this.previousEventId = previousEvent.getEventId();
            this.previousEventTime = previousEvent.getEventTime();
            this.previousFlowfileId = previousEvent.getFlowFileUuid();
            this.setStartTime(previousEventTime);
        }
    }

    public Long getPreviousEventId() {
        return previousEventId;
    }

    public DateTime getPreviousEventTime() {
        return previousEventTime;
    }

    public DateTime getEventTime() {
        return eventTime;
    }

    public void setEventTime(DateTime eventTime) {
        this.eventTime = eventTime;
    }

    public Set<String> getParentFlowFileIds() {
        if (getParentUuids() != null) {
            return new HashSet<>(this.getParentUuids());
        }
        return new HashSet<>();
    }

    public Long getInputContentClaimFileSizeBytes() {
        return inputContentClaimFileSizeBytes;
    }

    public void setInputContentClaimFileSizeBytes(Long inputContentClaimFileSizeBytes) {
        this.inputContentClaimFileSizeBytes = inputContentClaimFileSizeBytes;
    }

    public String getInputContentClaimFileSize() {
        return inputContentClaimFileSize;
    }

    public void setInputContentClaimFileSize(String inputContentClaimFileSize) {
        this.inputContentClaimFileSize = inputContentClaimFileSize;
    }

    public Long getOutputContentClaimFileSizeBytes() {
        return outputContentClaimFileSizeBytes;
    }

    public void setOutputContentClaimFileSizeBytes(Long outputContentClaimFileSizeBytes) {
        this.outputContentClaimFileSizeBytes = outputContentClaimFileSizeBytes;
    }

    public String getOutputContentClaimFileSize() {
        return outputContentClaimFileSize;
    }

    public void setOutputContentClaimFileSize(String outputContentClaimFileSize) {
        this.outputContentClaimFileSize = outputContentClaimFileSize;
    }

    public boolean isStream() {
        return stream;
    }

    public void setStream(boolean stream) {
        this.stream = stream;
    }

    public AtomicBoolean getProcessed() {
        return processed;
    }

    public String getFeedProcessGroupId() {
        return feedProcessGroupId;
    }

    public void setFeedProcessGroupId(String feedProcessGroupId) {
        this.feedProcessGroupId = feedProcessGroupId;
    }

    public String getJobFlowFileId() {
        return jobFlowFileId;
    }

    public void setJobFlowFileId(String jobFlowFileId) {
        this.jobFlowFileId = jobFlowFileId;
    }

    public Long getJobEventId() {
        return jobEventId;
    }

    public void setJobEventId(Long jobEventId) {
        this.jobEventId = jobEventId;
    }

    public boolean isStartOfJob() {
        return isStartOfJob;
    }

    public void setIsStartOfJob(boolean isStartOfJob) {
        this.isStartOfJob = isStartOfJob;
    }

    public void setIsFailure(boolean isFailure) {
        this.isFailure = isFailure;
    }

    public boolean isFailure() {
        return isFailure;
    }

    public boolean isEndOfJob() {
        return isEndOfJob;
    }

    public void setIsEndOfJob(boolean isEndOfJob) {
        this.isEndOfJob = isEndOfJob;
    }

    public String getBatchId() {
        return batchId;
    }

    public void setBatchId(String batchId) {
        this.batchId = batchId;
    }

    private void addRelatedRootFlowFile(String rootFlowFileId) {

    }

    public Set<String> getRelatedRootFlowFiles() {
        return relatedRootFlowFiles;
    }

    public void setRelatedRootFlowFiles(Set<String> relatedRootFlowFiles) {
        this.relatedRootFlowFiles = relatedRootFlowFiles;
    }

    public boolean isFinalJobEvent() {
        return isFinalJobEvent;
    }

    public void setIsFinalJobEvent(boolean isFinalJobEvent) {
        this.isFinalJobEvent = isFinalJobEvent;
        if (this.isFinalJobEvent) {
            this.hasFailedEvents = getFeedFlowFile().hasFailedEvents();
        }
    }

    public boolean isHasFailedEvents() {
        return hasFailedEvents;
    }

    public void setHasFailedEvents(boolean hasFailedEvents) {
        this.hasFailedEvents = hasFailedEvents;
    }

    public boolean isBatchJob() {
        return isBatchJob;
    }

    public void setIsBatchJob(boolean isBatchJob) {
        this.isBatchJob = isBatchJob;
    }

    public DateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(DateTime startTime) {
        this.startTime = startTime;
    }

    public KyloProcessorFlowType getProcessorType() {
        return processorType;
    }

    public void setProcessorType(KyloProcessorFlowType processorType) {
        this.processorType = processorType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        ProvenanceEventRecordDTO that = (ProvenanceEventRecordDTO) o;

        if (eventId != null ? !eventId.equals(that.eventId) : that.eventId != null) {
            return false;
        }
        return !(flowFileUuid != null ? !flowFileUuid.equals(that.flowFileUuid) : that.flowFileUuid != null);

    }

    @Override
    public int hashCode() {
        int result = eventId != null ? eventId.hashCode() : 0;
        result = 31 * result + (flowFileUuid != null ? flowFileUuid.hashCode() : 0);
        return result;
    }

    public String toString() {
        final StringBuilder sb = new StringBuilder("ProvenanceEventRecordDTO{");
        sb.append("eventId=").append(getEventId());
        sb.append(", processorName=").append(getComponentName());
        sb.append(", componentId=").append(getComponentId());
        sb.append(", flowFile=").append(getFlowFileUuid());
        sb.append(", previous=").append(getPreviousEventId());
        sb.append(", eventType=").append(getEventType());
        sb.append(", eventDetails=").append(getDetails());
        sb.append(", isEndOfJob=").append(isEndOfJob());
        sb.append(", isBatch=").append(isBatchJob());
        sb.append(", isStream=").append(isStream());
        sb.append(", feed=").append(getFeedName());

        sb.append('}');
        return sb.toString();
    }

    /**
     * reset this object so it can go back to pool
     */
    public void reset() {
        this.isStartOfJob = false;
        this.isEndOfJob = false;
        this.isFinalJobEvent = false;
        this.isBatchJob = true;
        this.hasFailedEvents = false;
        this.previousEventId = null;
        this.previousFlowfileId = null;
        this.previousEventTime = null;
        this.startTime = null;
        this.id = null;
        this.eventId = null;
        this.eventTime = null;
        this.eventDuration = null;
        this.eventType = null;
        this.flowFileUuid = null;
        this.fileSize = null;
        this.fileSizeBytes = null;
        this.clusterNodeId = null;
        this.clusterNodeAddress = null;
        this.groupId = null;
        this.componentId = null;
        this.componentType = null;
        this.componentName = null;
        this.parentUuids = null;
        this.childUuids = null;
        this.details = null;
        this.sourceConnectionIdentifier = null;
        this.inputContentClaimFileSizeBytes = null;
        this.inputContentClaimFileSize = null;
        this.outputContentClaimFileSizeBytes = null;
        this.outputContentClaimFileSize = null;
        this.relatedRootFlowFiles = null;
        this.isStartOfFlowFile = false;
        this.processorType = null;
        this.isFailure = false;
        this.stream = false;
        this.jobFlowFileId = null;
        this.jobEventId = null;
        this.feedName = null;
        this.feedProcessGroupId = null;
        this.batchId = null;
        this.relationship = null;
        this.feedFlowFile = null;
        this.updatedAttributes = null;
        this.previousAttributes = null;
        this.additionalProperties = null;
        this.attributeMap = null;
    }
}