74 | Tweet Stream for First-Time Users
75 | Tweet Stream (First Time Users) - Last minute
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/twitter2/bin/requests/packages/charade/eucjpprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | import sys
29 | from . import constants
30 | from .mbcharsetprober import MultiByteCharSetProber
31 | from .codingstatemachine import CodingStateMachine
32 | from .chardistribution import EUCJPDistributionAnalysis
33 | from .jpcntx import EUCJPContextAnalysis
34 | from .mbcssm import EUCJPSMModel
35 |
36 |
37 | class EUCJPProber(MultiByteCharSetProber):
38 | def __init__(self):
39 | MultiByteCharSetProber.__init__(self)
40 | self._mCodingSM = CodingStateMachine(EUCJPSMModel)
41 | self._mDistributionAnalyzer = EUCJPDistributionAnalysis()
42 | self._mContextAnalyzer = EUCJPContextAnalysis()
43 | self.reset()
44 |
45 | def reset(self):
46 | MultiByteCharSetProber.reset(self)
47 | self._mContextAnalyzer.reset()
48 |
49 | def get_charset_name(self):
50 | return "EUC-JP"
51 |
52 | def feed(self, aBuf):
53 | aLen = len(aBuf)
54 | for i in range(0, aLen):
55 | # PY3K: aBuf is a byte array, so aBuf[i] is an int, not a byte
56 | codingState = self._mCodingSM.next_state(aBuf[i])
57 | if codingState == constants.eError:
58 | if constants._debug:
59 | sys.stderr.write(self.get_charset_name()
60 | + ' prober hit error at byte ' + str(i)
61 | + '\n')
62 | self._mState = constants.eNotMe
63 | break
64 | elif codingState == constants.eItsMe:
65 | self._mState = constants.eFoundIt
66 | break
67 | elif codingState == constants.eStart:
68 | charLen = self._mCodingSM.get_current_charlen()
69 | if i == 0:
70 | self._mLastChar[1] = aBuf[0]
71 | self._mContextAnalyzer.feed(self._mLastChar, charLen)
72 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen)
73 | else:
74 | self._mContextAnalyzer.feed(aBuf[i - 1:i + 1], charLen)
75 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1],
76 | charLen)
77 |
78 | self._mLastChar[0] = aBuf[aLen - 1]
79 |
80 | if self.get_state() == constants.eDetecting:
81 | if (self._mContextAnalyzer.got_enough_data() and
82 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)):
83 | self._mState = constants.eFoundIt
84 |
85 | return self.get_state()
86 |
87 | def get_confidence(self):
88 | contxtCf = self._mContextAnalyzer.get_confidence()
89 | distribCf = self._mDistributionAnalyzer.get_confidence()
90 | return max(contxtCf, distribCf)
91 |
--------------------------------------------------------------------------------
/twitter2/bin/requests/packages/charade/sjisprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | import sys
29 | from .mbcharsetprober import MultiByteCharSetProber
30 | from .codingstatemachine import CodingStateMachine
31 | from .chardistribution import SJISDistributionAnalysis
32 | from .jpcntx import SJISContextAnalysis
33 | from .mbcssm import SJISSMModel
34 | from . import constants
35 |
36 |
37 | class SJISProber(MultiByteCharSetProber):
38 | def __init__(self):
39 | MultiByteCharSetProber.__init__(self)
40 | self._mCodingSM = CodingStateMachine(SJISSMModel)
41 | self._mDistributionAnalyzer = SJISDistributionAnalysis()
42 | self._mContextAnalyzer = SJISContextAnalysis()
43 | self.reset()
44 |
45 | def reset(self):
46 | MultiByteCharSetProber.reset(self)
47 | self._mContextAnalyzer.reset()
48 |
49 | def get_charset_name(self):
50 | return "SHIFT_JIS"
51 |
52 | def feed(self, aBuf):
53 | aLen = len(aBuf)
54 | for i in range(0, aLen):
55 | codingState = self._mCodingSM.next_state(aBuf[i])
56 | if codingState == constants.eError:
57 | if constants._debug:
58 | sys.stderr.write(self.get_charset_name()
59 | + ' prober hit error at byte ' + str(i)
60 | + '\n')
61 | self._mState = constants.eNotMe
62 | break
63 | elif codingState == constants.eItsMe:
64 | self._mState = constants.eFoundIt
65 | break
66 | elif codingState == constants.eStart:
67 | charLen = self._mCodingSM.get_current_charlen()
68 | if i == 0:
69 | self._mLastChar[1] = aBuf[0]
70 | self._mContextAnalyzer.feed(self._mLastChar[2 - charLen:],
71 | charLen)
72 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen)
73 | else:
74 | self._mContextAnalyzer.feed(aBuf[i + 1 - charLen:i + 3
75 | - charLen], charLen)
76 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1],
77 | charLen)
78 |
79 | self._mLastChar[0] = aBuf[aLen - 1]
80 |
81 | if self.get_state() == constants.eDetecting:
82 | if (self._mContextAnalyzer.got_enough_data() and
83 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)):
84 | self._mState = constants.eFoundIt
85 |
86 | return self.get_state()
87 |
88 | def get_confidence(self):
89 | contxtCf = self._mContextAnalyzer.get_confidence()
90 | distribCf = self._mDistributionAnalyzer.get_confidence()
91 | return max(contxtCf, distribCf)
92 |
--------------------------------------------------------------------------------
/twitter2/bin/requests/structures.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | requests.structures
5 | ~~~~~~~~~~~~~~~~~~~
6 |
7 | Data structures that power Requests.
8 |
9 | """
10 |
11 | import os
12 | import collections
13 | from itertools import islice
14 |
15 |
16 | class IteratorProxy(object):
17 | """docstring for IteratorProxy"""
18 | def __init__(self, i):
19 | self.i = i
20 | # self.i = chain.from_iterable(i)
21 |
22 | def __iter__(self):
23 | return self.i
24 |
25 | def __len__(self):
26 | if hasattr(self.i, '__len__'):
27 | return len(self.i)
28 | if hasattr(self.i, 'len'):
29 | return self.i.len
30 | if hasattr(self.i, 'fileno'):
31 | return os.fstat(self.i.fileno()).st_size
32 |
33 | def read(self, n):
34 | return "".join(islice(self.i, None, n))
35 |
36 |
37 | class CaseInsensitiveDict(collections.MutableMapping):
38 | """
39 | A case-insensitive ``dict``-like object.
40 |
41 | Implements all methods and operations of
42 | ``collections.MutableMapping`` as well as dict's ``copy``. Also
43 | provides ``lower_items``.
44 |
45 | All keys are expected to be strings. The structure remembers the
46 | case of the last key to be set, and ``iter(instance)``,
47 | ``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()``
48 | will contain case-sensitive keys. However, querying and contains
49 | testing is case insensitive:
50 |
51 | cid = CaseInsensitiveDict()
52 | cid['Accept'] = 'application/json'
53 | cid['aCCEPT'] == 'application/json' # True
54 | list(cid) == ['Accept'] # True
55 |
56 | For example, ``headers['content-encoding']`` will return the
57 | value of a ``'Content-Encoding'`` response header, regardless
58 | of how the header name was originally stored.
59 |
60 | If the constructor, ``.update``, or equality comparison
61 | operations are given keys that have equal ``.lower()``s, the
62 | behavior is undefined.
63 |
64 | """
65 | def __init__(self, data=None, **kwargs):
66 | self._store = dict()
67 | if data is None:
68 | data = {}
69 | self.update(data, **kwargs)
70 |
71 | def __setitem__(self, key, value):
72 | # Use the lowercased key for lookups, but store the actual
73 | # key alongside the value.
74 | self._store[key.lower()] = (key, value)
75 |
76 | def __getitem__(self, key):
77 | return self._store[key.lower()][1]
78 |
79 | def __delitem__(self, key):
80 | del self._store[key.lower()]
81 |
82 | def __iter__(self):
83 | return (casedkey for casedkey, mappedvalue in self._store.values())
84 |
85 | def __len__(self):
86 | return len(self._store)
87 |
88 | def lower_items(self):
89 | """Like iteritems(), but with all lowercase keys."""
90 | return (
91 | (lowerkey, keyval[1])
92 | for (lowerkey, keyval)
93 | in self._store.items()
94 | )
95 |
96 | def __eq__(self, other):
97 | if isinstance(other, collections.Mapping):
98 | other = CaseInsensitiveDict(other)
99 | else:
100 | return NotImplemented
101 | # Compare insensitively
102 | return dict(self.lower_items()) == dict(other.lower_items())
103 |
104 | # Copy is required
105 | def copy(self):
106 | return CaseInsensitiveDict(self._store.values())
107 |
108 | def __repr__(self):
109 | return '%s(%r)' % (self.__class__.__name__, dict(self.items()))
110 |
111 |
112 | class LookupDict(dict):
113 | """Dictionary lookup object."""
114 |
115 | def __init__(self, name=None):
116 | self.name = name
117 | super(LookupDict, self).__init__()
118 |
119 | def __repr__(self):
120 | return '' % (self.name)
121 |
122 | def __getitem__(self, key):
123 | # We allow fall-through here, so values default to None
124 |
125 | return self.__dict__.get(key, None)
126 |
127 | def get(self, key, default=None):
128 | return self.__dict__.get(key, default)
129 |
--------------------------------------------------------------------------------
/twitter2/bin/splunklib/modularinput/argument.py:
--------------------------------------------------------------------------------
1 | # Copyright 2011-2014 Splunk, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | # not use this file except in compliance with the License. You may obtain
5 | # a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations
13 | # under the License.
14 |
15 | try:
16 | import xml.etree.ElementTree as ET
17 | except ImportError:
18 | import xml.etree.cElementTree as ET
19 |
20 | class Argument(object):
21 | """Class representing an argument to a modular input kind.
22 |
23 | ``Argument`` is meant to be used with ``Scheme`` to generate an XML
24 | definition of the modular input kind that Splunk understands.
25 |
26 | ``name`` is the only required parameter for the constructor.
27 |
28 | **Example with least parameters**::
29 |
30 | arg1 = Argument(name="arg1")
31 |
32 | **Example with all parameters**::
33 |
34 | arg2 = Argument(
35 | name="arg2",
36 | description="This is an argument with lots of parameters",
37 | validation="is_pos_int('some_name')",
38 | data_type=Argument.data_type_number,
39 | required_on_edit=True,
40 | required_on_create=True
41 | )
42 | """
43 |
44 | # Constant values, do not change.
45 | # These should be used for setting the value of an Argument object's data_type field.
46 | data_type_boolean = "BOOLEAN"
47 | data_type_number = "NUMBER"
48 | data_type_string = "STRING"
49 |
50 | def __init__(self, name, description=None, validation=None,
51 | data_type=data_type_string, required_on_edit=False, required_on_create=False):
52 | """
53 | :param name: ``string``, identifier for this argument in Splunk.
54 | :param description: ``string``, human-readable description of the argument.
55 | :param validation: ``string`` specifying how the argument should be validated, if using internal validation.
56 | If using external validation, this will be ignored.
57 | :param data_type: ``string``, data type of this field; use the class constants.
58 | "data_type_boolean", "data_type_number", or "data_type_string".
59 | :param required_on_edit: ``Boolean``, whether this arg is required when editing an existing modular input of this kind.
60 | :param required_on_create: ``Boolean``, whether this arg is required when creating a modular input of this kind.
61 | """
62 | self.name = name
63 | self.description = description
64 | self.validation = validation
65 | self.data_type = data_type
66 | self.required_on_edit = required_on_edit
67 | self.required_on_create = required_on_create
68 |
69 | def add_to_document(self, parent):
70 | """Adds an ``Argument`` object to this ElementTree document.
71 |
72 | Adds an subelement to the parent element, typically
73 | and sets up its subelements with their respective text.
74 |
75 | :param parent: An ``ET.Element`` to be the parent of a new subelement
76 | :returns: An ``ET.Element`` object representing this argument.
77 | """
78 | arg = ET.SubElement(parent, "arg")
79 | arg.set("name", self.name)
80 |
81 | if self.description is not None:
82 | ET.SubElement(arg, "description").text = self.description
83 |
84 | if self.validation is not None:
85 | ET.SubElement(arg, "validation").text = self.validation
86 |
87 | # add all other subelements to this Argument, represented by (tag, text)
88 | subelements = [
89 | ("data_type", self.data_type),
90 | ("required_on_edit", self.required_on_edit),
91 | ("required_on_create", self.required_on_create)
92 | ]
93 |
94 | for name, value in subelements:
95 | ET.SubElement(arg, name).text = str(value).lower()
96 |
97 | return arg
--------------------------------------------------------------------------------
/twitter2/bin/splunklib/searchcommands/logging.py:
--------------------------------------------------------------------------------
1 | # Copyright 2011-2014 Splunk, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | # not use this file except in compliance with the License. You may obtain
5 | # a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations
13 | # under the License.
14 |
15 | from __future__ import absolute_import
16 |
17 | from logging.config import fileConfig
18 | from logging import getLogger, root, StreamHandler
19 | import os
20 |
21 |
22 | def configure(name, path=None):
23 | """ Configure logging and return a logger and the location of its logging
24 | configuration file.
25 |
26 | This function expects:
27 |
28 | + A Splunk app directory structure::
29 |
30 |
31 | bin
32 | ...
33 | default
34 | ...
35 | local
36 | ...
37 |
38 | + The current working directory is ****/bin**.
39 |
40 | Splunk guarantees this. If you are running the app outside of Splunk, be
41 | sure to set the current working directory to ****/bin** before
42 | calling.
43 |
44 | This function looks for a logging configuration file at each of these
45 | locations, loading the first, if any, logging configuration file that it
46 | finds::
47 |
48 | local/{name}.logging.conf
49 | default/{name}.logging.conf
50 | local/logging.conf
51 | default/logging.conf
52 |
53 | The current working directory is set to ** before the logging
54 | configuration file is loaded. Hence, paths in the logging configuration
55 | file are relative to **. The current directory is reset before
56 | return.
57 |
58 | You may short circuit the search for a logging configuration file by
59 | providing an alternative file location in `path`. Logging configuration
60 | files must be in `ConfigParser format`_.
61 |
62 | #Arguments:
63 |
64 | :param name: Logger name
65 | :type name: str
66 | :param path: Location of an alternative logging configuration file or `None`
67 | :type path: str or NoneType
68 | :returns: A logger and the location of its logging configuration file
69 |
70 | .. _ConfigParser format: http://goo.gl/K6edZ8
71 |
72 | """
73 | app_directory = os.path.dirname(os.getcwd())
74 |
75 | if path is None:
76 | probing_path = [
77 | 'local/%s.logging.conf' % name,
78 | 'default/%s.logging.conf' % name,
79 | 'local/logging.conf',
80 | 'default/logging.conf']
81 | for relative_path in probing_path:
82 | configuration_file = os.path.join(app_directory, relative_path)
83 | if os.path.exists(configuration_file):
84 | path = configuration_file
85 | break
86 | elif not os.path.isabs(path):
87 | found = False
88 | for conf in 'local', 'default':
89 | configuration_file = os.path.join(app_directory, conf, path)
90 | if os.path.exists(configuration_file):
91 | path = configuration_file
92 | found = True
93 | break
94 | if not found:
95 | raise ValueError(
96 | 'Logging configuration file "%s" not found in local or default '
97 | 'directory' % path)
98 | elif not os.path.exists(path):
99 | raise ValueError('Logging configuration file "%s" not found')
100 |
101 | if path is not None:
102 | working_directory = os.getcwd()
103 | os.chdir(app_directory)
104 | try:
105 | path = os.path.abspath(path)
106 | fileConfig(path)
107 | finally:
108 | os.chdir(working_directory)
109 |
110 | if len(root.handlers) == 0:
111 | root.addHandler(StreamHandler())
112 |
113 | logger = getLogger(name)
114 | return logger, path
115 |
--------------------------------------------------------------------------------
/twitter2/bin/requests/packages/charade/charsetgroupprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Communicator client code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from . import constants
29 | import sys
30 | from .charsetprober import CharSetProber
31 |
32 |
33 | class CharSetGroupProber(CharSetProber):
34 | def __init__(self):
35 | CharSetProber.__init__(self)
36 | self._mActiveNum = 0
37 | self._mProbers = []
38 | self._mBestGuessProber = None
39 |
40 | def reset(self):
41 | CharSetProber.reset(self)
42 | self._mActiveNum = 0
43 | for prober in self._mProbers:
44 | if prober:
45 | prober.reset()
46 | prober.active = True
47 | self._mActiveNum += 1
48 | self._mBestGuessProber = None
49 |
50 | def get_charset_name(self):
51 | if not self._mBestGuessProber:
52 | self.get_confidence()
53 | if not self._mBestGuessProber:
54 | return None
55 | # self._mBestGuessProber = self._mProbers[0]
56 | return self._mBestGuessProber.get_charset_name()
57 |
58 | def feed(self, aBuf):
59 | for prober in self._mProbers:
60 | if not prober:
61 | continue
62 | if not prober.active:
63 | continue
64 | st = prober.feed(aBuf)
65 | if not st:
66 | continue
67 | if st == constants.eFoundIt:
68 | self._mBestGuessProber = prober
69 | return self.get_state()
70 | elif st == constants.eNotMe:
71 | prober.active = False
72 | self._mActiveNum -= 1
73 | if self._mActiveNum <= 0:
74 | self._mState = constants.eNotMe
75 | return self.get_state()
76 | return self.get_state()
77 |
78 | def get_confidence(self):
79 | st = self.get_state()
80 | if st == constants.eFoundIt:
81 | return 0.99
82 | elif st == constants.eNotMe:
83 | return 0.01
84 | bestConf = 0.0
85 | self._mBestGuessProber = None
86 | for prober in self._mProbers:
87 | if not prober:
88 | continue
89 | if not prober.active:
90 | if constants._debug:
91 | sys.stderr.write(prober.get_charset_name()
92 | + ' not active\n')
93 | continue
94 | cf = prober.get_confidence()
95 | if constants._debug:
96 | sys.stderr.write('%s confidence = %s\n' %
97 | (prober.get_charset_name(), cf))
98 | if bestConf < cf:
99 | bestConf = cf
100 | self._mBestGuessProber = prober
101 | if not self._mBestGuessProber:
102 | return 0.0
103 | return bestConf
104 | # else:
105 | # self._mBestGuessProber = self._mProbers[0]
106 | # return self._mBestGuessProber.get_confidence()
107 |
--------------------------------------------------------------------------------
/twitter2/bin/splunklib/modularinput/event.py:
--------------------------------------------------------------------------------
1 | # Copyright 2011-2014 Splunk, Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | # not use this file except in compliance with the License. You may obtain
5 | # a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations
13 | # under the License.
14 |
15 | try:
16 | import xml.etree.cElementTree as ET
17 | except ImportError as ie:
18 | import xml.etree.ElementTree as ET
19 |
20 | class Event(object):
21 | """Represents an event or fragment of an event to be written by this modular input to Splunk.
22 |
23 | To write an input to a stream, call the ``write_to`` function, passing in a stream.
24 | """
25 | def __init__(self, data=None, stanza=None, time=None, host=None, index=None, source=None,
26 | sourcetype=None, done=True, unbroken=True):
27 | """There are no required parameters for constructing an Event
28 |
29 | **Example with minimal configuration**::
30 |
31 | my_event = Event(
32 | data="This is a test of my new event.",
33 | stanza="myStanzaName",
34 | time="%.3f" % 1372187084.000
35 | )
36 |
37 | **Example with full configuration**::
38 |
39 | excellent_event = Event(
40 | data="This is a test of my excellent event.",
41 | stanza="excellenceOnly",
42 | time="%.3f" % 1372274622.493,
43 | host="localhost",
44 | index="main",
45 | source="Splunk",
46 | sourcetype="misc",
47 | done=True,
48 | unbroken=True
49 | )
50 |
51 | :param data: ``string``, the event's text.
52 | :param stanza: ``string``, name of the input this event should be sent to.
53 | :param time: ``float``, time in seconds, including up to 3 decimal places to represent milliseconds.
54 | :param host: ``string``, the event's host, ex: localhost.
55 | :param index: ``string``, the index this event is specified to write to, or None if default index.
56 | :param source: ``string``, the source of this event, or None to have Splunk guess.
57 | :param sourcetype: ``string``, source type currently set on this event, or None to have Splunk guess.
58 | :param done: ``boolean``, is this a complete ``Event``? False if an ``Event`` fragment.
59 | :param unbroken: ``boolean``, Is this event completely encapsulated in this ``Event`` object?
60 | """
61 | self.data = data
62 | self.done = done
63 | self.host = host
64 | self.index = index
65 | self.source = source
66 | self.sourceType = sourcetype
67 | self.stanza = stanza
68 | self.time = time
69 | self.unbroken = unbroken
70 |
71 | def write_to(self, stream):
72 | """Write an XML representation of self, an ``Event`` object, to the given stream.
73 |
74 | The ``Event`` object will only be written if its data field is defined,
75 | otherwise a ``ValueError`` is raised.
76 |
77 | :param stream: stream to write XML to.
78 | """
79 | if self.data is None:
80 | raise ValueError("Events must have at least the data field set to be written to XML.")
81 |
82 | event = ET.Element("event")
83 | if self.stanza is not None:
84 | event.set("stanza", self.stanza)
85 | event.set("unbroken", str(int(self.unbroken)))
86 |
87 | # if a time isn't set, let Splunk guess by not creating a