Skip to content

Commit

Permalink
Merge pull request #12 from cisco-sas/v0.6.2
Browse files Browse the repository at this point in the history
V0.6.2
  • Loading branch information
BinyaminSharet committed Feb 29, 2016
2 parents 4f78518 + 017d7e2 commit d0424da
Show file tree
Hide file tree
Showing 18 changed files with 1,692 additions and 1,082 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Version 0.6.2 (2016-03-01)
==========================


* bugfix: [Data Manager] Handle exceptions in tasks by raising them in caller context
* bugfix: [Data Manager] Unicode strings are now properly encoded in the report
* bugfix: [Data Model] BitFieldMultiByteEncoder: fixed byte order
* bugfix: [Data Model] BlockOperation: block size validation
* bugfix: [Data Model] ByteAlignedBitsEncoder: fixed byte alignment (issue #11)
* bugfix: [Data Model] ByteFlips: removed silent failures
* bugfix: [Data Model] If/IfNot: Protect from recursive rendering
* bugfix: [Web Interface] handle errors and return descriptive message when error occurs in the report API

* new feature: [Data Model] BitFieldMultiByteEncoder: support for little endian
* new feature: [Data Model] ElementCount: field that holds the number of elements in given container
* new feature: [Data Model] IndexOf: field that holds the index of a given field in its container
* new feature: [Data Model] RandomBits: Similar to RandomBytes, but in bits (allows non-byte aligned fields)
* new feature: [Tools] kitty-template-tester: print version

* removed feature: [Data Model] Crypto Encoders were removed from Kitty and now available in Katnip v0.2.2 this removes the dependency in pycrypto from kitty (issue #7)
6 changes: 2 additions & 4 deletions bin/kitty_template_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import types
import docopt
import traceback
from pkg_resources import get_distribution
from kitty.model import Template


Expand Down Expand Up @@ -68,15 +69,11 @@ def process(self, t):
while t.mutate():
count += 1
t.render()
# if count % 50000 == 0:
# verbose(count)
t.reset()
count = 0
while t.mutate():
count += 1
t.render()
# if count % 50000 == 0:
# verbose(count)
t.reset()


Expand Down Expand Up @@ -151,6 +148,7 @@ def process_file(f, processor):


def _main():
print('kitty version: %s' % get_distribution('kitty').version)
opts = docopt.docopt(__doc__)
files = opts['<FILE>']
fast = opts['--fast']
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
# built documents.
#
# The short X.Y version.
version = '0.6.0'
version = '0.6.2'
# The full version, including alpha/beta/rc tags.
release = '0.6.0'
release = '0.6.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
8 changes: 7 additions & 1 deletion kitty/data/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, task, *args):
self._result = None
self._task = task
self._args = args
self._exception = None

def execute(self, dataman):
'''
Expand All @@ -51,14 +52,19 @@ def execute(self, dataman):
:param dataman: the executing data manager
'''
self._event.clear()
self._result = self._task(dataman, *self._args)
try:
self._result = self._task(dataman, *self._args)
except Exception as ex:
self._exception = ex
self._event.set()

def get_results(self):
'''
:return: result from running the task
'''
self._event.wait()
if self._exception:
raise self._exception
return self._result


Expand Down
24 changes: 8 additions & 16 deletions kitty/interfaces/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from kitty.interfaces.base import EmptyInterface
from kitty.core.threading_utils import FuncThread
from kitty.data.data_manager import DataManagerTask


class _WebInterfaceServer(BaseHTTPServer.HTTPServer):
Expand Down Expand Up @@ -194,34 +193,27 @@ def _handle_api_request(self):
return response

def _get_report(self):
def as_int(val):
try:
return int(val)
except ValueError:
return -1
report = None
encoding = 'base64'

parsed = urlparse(self.path)
query = parse_qs(parsed.query)
if 'report_id' in query:
key = as_int(query['report_id'][0])

def task(dataman):
manager = dataman.get_reports_manager()
try:
return manager.get(key)
except Exception:
return None
try:
report_id_string = query['report_id'][0]
key = int(report_id_string)
report = self.dataman.get_report_by_id(key)
if report:
response = {
'encoding': encoding,
'report': report.to_dict(encoding)
}
except:
pass
else:
raise 'No report with id %d' % key
except Exception as ex:
response = {'error': 'Failed to get report %s' % ex}
else:
response = {'error': 'No report_id provided'}
return json.dumps(response)

def _my_handle(self):
Expand Down
14 changes: 8 additions & 6 deletions kitty/model/low_level/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@

class Condition(object):

def applies(self, container):
def applies(self, container, ctx):
'''
All subclasses must implement the `applies(self, container)` method
:type container: Container
:param container: the caller
:param ctx: rendering context in which applies was called
:return: True if condition applies, False otherwise
'''
raise NotImplementedError('applies')
Expand Down Expand Up @@ -77,19 +78,20 @@ def _get_ready(self, container):
if not self._field:
raise KittyException('No field provided to base the condition on')

def applies(self, container):
def applies(self, container, ctx):
'''
Subclasses should not override `applies`, but instead they should override `_applies`, which has the same syntax as `applies`.
In the `_applies` method the condition is guaranteed to have a reference to the desired field, as `self._field`.
:type container: :class:`~kitty.model.low_level.container.Container`
:param container: the caller
:param ctx: rendering context in which applies was called
:return: True if condition applies, False otherwise
'''
self._get_ready(container)
return self._applies(container)
return self._applies(container, ctx)

def _applies(self, container):
def _applies(self, container, ctx):
raise NotImplementedError('_applies')

def hash(self):
Expand Down Expand Up @@ -131,7 +133,7 @@ class InList(ListCondition):
])
'''

def _applies(self, container):
def _applies(self, container, ctx):
value = self._field.get_current_value()
return value in self._value_list

Expand Down Expand Up @@ -188,7 +190,7 @@ def __init__(self, field, comp_type, comp_value):
raise KittyException('unknown comparison type (%s)' % (comp_type))
self._comp_value = comp_value

def _applies(self, container):
def _applies(self, container, ctx):
value = self._field.get_current_value()
return self._comp_fn(value, self._comp_value)

Expand Down
Loading

0 comments on commit d0424da

Please sign in to comment.