예제 #1
0
import inspect
import json
import re
import string
import sys
import warnings
from collections import namedtuple
from math import isnan
from types import FunctionType

from mo_dots import is_null, Null
from mo_future import unichr, text, generator_types, get_function_name
from mo_imports import delay_import

ParseException = delay_import("mo_parsing.exceptions.ParseException")


def append_config(base, *slots):
    fields = base.Config._fields + slots
    return namedtuple("Config", fields)


try:
    from mo_logs import Log
except Exception:

    class Log(object):
        @classmethod
        def note(cls, template, cause=None, **params):
            pass
예제 #2
0
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Contact: Kyle Lahnakoski ([email protected])
#

from __future__ import absolute_import, division, unicode_literals

import types
from copy import deepcopy

from mo_future import generator_types, first, is_text
from mo_imports import expect, delay_import

from mo_dots.utils import CLASS

Log = delay_import("mo_logs.Log")
datawrap, coalesce, list_to_data, to_data, from_data, Null, EMPTY = expect(
    "datawrap", "coalesce", "list_to_data", "to_data", "from_data", "Null", "EMPTY"
)


LIST = str("list")
_get = object.__getattribute__
_set = object.__setattr__
_emit_slice_warning = True


class FlatList(object):
    """
    ENCAPSULATES HANDING OF Nulls BY wrapING ALL MEMBERS AS NEEDED
    ENCAPSULATES FLAT SLICES ([::]) FOR USE IN WINDOW FUNCTIONS
예제 #3
0
from mo_dots import Null, to_data, join_field, split_field, coalesce, startswith_field
from mo_future import first
from mo_imports import expect, delay_import
from mo_json import EXISTS
from mo_json.typed_encoder import EXISTS_TYPE, NESTED_TYPE
from mo_logs import Log
from mo_math import MAX

MATCH_NONE, MATCH_ALL, AndOp, OrOp, NestedOp = expect(
    "MATCH_NONE",
    "MATCH_ALL",
    "AndOp",
    "OrOp",
    "NestedOp",
)
get_decoders_by_path = delay_import(
    "jx_elasticsearch.es52.agg_op.get_decoders_by_path")


def _inequality_to_esfilter(self, schema):
    if is_op(self.lhs, Variable_) and is_literal(self.rhs):
        cols = schema.leaves(self.lhs.var)
        if not cols:
            lhs = self.lhs.var  # HAPPENS DURING DEBUGGING, AND MAYBE IN REAL LIFE TOO
        elif len(cols) == 1:
            lhs = first(cols).es_column
        else:
            raise Log.error("operator {{op|quote}} does not work on objects",
                            op=self.op)
        return {"range": {lhs: {self.op: self.rhs.value}}}
    else:
        script = Painless[self].to_es_script(schema)
예제 #4
0
    Suppress,
    ZeroOrMore,
)
from mo_parsing.expressions import MatchFirst, Or
from mo_parsing.results import ParseResults, NO_PARSER
from mo_parsing.tokens import (
    CaselessKeyword,
    CaselessLiteral,
    Keyword,
    NoMatch,
    Literal,
    Empty,
)
from mo_parsing.utils import regex_range, wrap_parse_action

Regex = delay_import("mo_parsing.regex.Regex")


def delimitedList(expr, separator=",", combine=False):
    """
    PARSE DELIMITED LIST OF expr
    Example::

        delimitedList(Word(alphas)).parseString("aa,bb,cc") # -> ['aa', 'bb', 'cc']
        delimitedList(Word(hexnums), delim=':', combine=True).parseString("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE']
    """
    if combine:
        return Combine(expr + ZeroOrMore(separator + expr))
    else:
        return expr + ZeroOrMore(Suppress(separator) + expr)
예제 #5
0
    FlatList,
    coalesce,
    is_list,
    listwrap,
    unwraplist,
    dict_to_data,
    is_data,
)
from mo_future import PY3, is_text, text, STDOUT
from mo_kwargs import override
from mo_logs import constants as _constants, exceptions, strings
from mo_logs.exceptions import Except, LogItem, suppress_exception
from mo_logs.log_usingStream import StructuredLogger_usingStream
from mo_logs.strings import CR, indent

StructuredLogger_usingFile = delay_import(
    "mo_logs.log_usingFile.StructuredLogger_usingFile")
StructuredLogger_usingMulti = delay_import(
    "mo_logs.log_usingMulti.StructuredLogger_usingMulti")
StructuredLogger_usingThread = delay_import(
    "mo_logs.log_usingThread.StructuredLogger_usingThread")
startup_read_settings = delay_import("mo_logs.startup.read_settings")

_Thread = None


class Log(object):
    """
    FOR STRUCTURED LOGGING AND EXCEPTION CHAINING
    """

    trace = False
예제 #6
0
#
# Contact: Kyle Lahnakoski ([email protected])
#
from __future__ import absolute_import, division, unicode_literals

import datetime
import re

from mo_dots import get_module, dict_to_data
from mo_future import is_text, text
from mo_imports import delay_import, expect
from mo_math import MIN, is_nan, is_number, abs, floor, round

from mo_times.vendor.dateutil.relativedelta import relativedelta

Date = delay_import("mo_times.Date")
Log = delay_import("mo_logs.Log")


class Duration(object):
    __slots__ = ["_milli", "month"]

    def __new__(cls, value=None, **kwargs):
        output = object.__new__(cls)
        if value == None:
            if kwargs:
                output.milli = datetime.timedelta(
                    **kwargs).total_seconds() * 1000
                output.month = 0
                return output
            else: