Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for f in c['factors']:
temp_test_case.factors.append(f)
temp_test_case.factors.gathered = True
# Predict that Case against the remainder, Record the Result
result = temp_reasoner.predict(temp_test_case, case_collection, model, top_issue)
new_case_output.branches.append(result)
new_case_output.branches.gathered = True
output.branches.append(new_case_output)
output.branches.gathered = True
return output
class DAIBPCase(DAObject):
def init(self, *pargs, **kwargs):
super(DAIBPCase, self).init(*pargs, **kwargs)
self.initializeAttribute('factors',DAList.using(object_type=DAObject))
class DAIBPIssue(DATree):
def init(self, *pargs, **kwargs):
super(DAIBPIssue, self).init(*pargs, **kwargs)
self.initializeAttribute('factors',DAList)
self.branches.object_type = DAIBPIssue
def iterator(self):
# Returns a list of the elements in the tree below this object.
output = []
output.append(self)
for b in self.branches:
output.extend(b.iterator())
from docassemble.base.core import DAObject, DAList, DADict, DAFile, DAFileCollection, DAFileList, DATemplate, selections
from docassemble.base.functions import comma_and_list, get_language, set_language, get_dialect, word, comma_list, ordinal, ordinal_number, need, nice_number, quantity_noun, possessify, verb_past, verb_present, noun_plural, noun_singular, space_to_underscore, force_ask, force_gather, period_list, name_suffix, currency, indefinite_article, nodoublequote, capitalize, title_case, url_of, do_you, did_you, does_a_b, did_a_b, your, her, his, is_word, get_locale, set_locale, process_action, url_action, get_info, set_info, get_config, prevent_going_back, qr_code, action_menu_item, from_b64_json, defined, value, message, response, command, single_paragraph, location_returned, location_known, user_lat_lon, interview_url, interview_url_action, interview_url_as_qr, interview_url_action_as_qr, objects_from_file, get_default_timezone, user_logged_in, user_privileges, user_has_privilege, user_info, action_arguments, action_argument, task_performed, task_not_yet_performed, mark_task_as_performed, times_task_performed, set_task_counter, send_file
from docassemble.base.util import LatitudeLongitude, RoleChangeTracker, Name, IndividualName, Address, Person, Individual, ChildList, FinancialList, PeriodicFinancialList, Income, Asset, Expense, Value, PeriodicValue, OfficeList, Organization, send_email, map_of, us, last_access_time, last_access_delta, last_access_days, last_access_hours, last_access_minutes, timezone_list, as_datetime, current_datetime, date_difference, date_interval, today, month_of, day_of, year_of, format_date, format_time
__all__ = ['interview_url', 'Court', 'Case', 'Jurisdiction', 'Document', 'LegalFiling', 'Person', 'Individual', 'DAList', 'PartyList', 'ChildList', 'FinancialList', 'PeriodicFinancialList', 'Income', 'Asset', 'LatitudeLongitude', 'RoleChangeTracker', 'DATemplate', 'Expense', 'Value', 'PeriodicValue', 'DAFile', 'DAFileCollection', 'DAFileList', 'send_email', 'comma_and_list', 'get_language', 'get_dialect', 'set_language', 'word', 'comma_list', 'ordinal', 'ordinal_number', 'need', 'nice_number', 'quantity_noun', 'verb_past', 'verb_present', 'noun_plural', 'noun_singular', 'space_to_underscore', 'force_ask', 'force_gather', 'period_list', 'name_suffix', 'currency', 'indefinite_article', 'capitalize', 'title_case', 'url_of', 'get_locale', 'set_locale', 'process_action', 'url_action', 'selections', 'get_info', 'set_info', 'user_lat_lon', 'location_known', 'location_returned', 'get_config', 'map_of', 'objects_from_file', 'us', 'prevent_going_back', 'month_of', 'day_of', 'year_of', 'format_date', 'format_time', 'today', 'qr_code', 'interview_url_as_qr', 'interview_url_action_as_qr', 'action_menu_item', 'from_b64_json', 'defined', 'value', 'message', 'response', 'command', 'single_paragraph', 'interview_url_action', 'action_arguments', 'action_argument', 'last_access_time', 'last_access_delta', 'last_access_days', 'last_access_hours', 'last_access_minutes', 'timezone_list', 'as_datetime', 'current_datetime', 'date_difference', 'date_interval', 'get_default_timezone', 'user_logged_in', 'user_privileges', 'user_has_privilege', 'user_info', 'task_performed', 'task_not_yet_performed', 'mark_task_as_performed', 'times_task_performed', 'set_task_counter', 'send_file']
class Court(DAObject):
"""Represents a court of law."""
def __str__(self):
return(self.name)
def __repr__(self):
return(repr(self.name))
def _add_person_and_children_of(target, output_list):
if target not in output_list and target.identified():
output_list.append(target)
if hasattr(target, 'child'):
for child in target.child.elements:
_add_person_and_children_of(child, output_list)
class Case(DAObject):
"""Represents a case in court."""
def init(self, **kwargs):
for block in self.all_blocks():
block.demonstrated
def source(self):
return u"---\n".join(map(lambda x: x.source(), self.all_blocks()))
def known_source(self, skip=None):
output = list()
for block in self.all_blocks():
if block is skip:
continue
try:
output.append(block.source(follow_additional_fields=False))
except:
pass
return "---\n".join(output)
class DAField(DAObject):
def init(self, **kwargs):
return super(DAField, self).init(**kwargs)
class DAFieldList(DAList):
def init(self, **kwargs):
self.object_type = DAField
self.auto_gather = False
self.gathered = True
return super(DAFieldList, self).init(**kwargs)
def __str__(self):
return text_type(self).encode('utf-8')
def __unicode__(self):
return docassemble.base.functions.comma_and_list(map(lambda x: '`' + x.variable + '`', self.elements))
class DAQuestion(DAObject):
def init(self, **kwargs):
"""A DAObject with pre-set attributes address, which is a City, and
location, which is a LatitudeLongitude.
"""
def init(self, *pargs, **kwargs):
if 'address' not in kwargs:
self.address = City()
if 'location' not in kwargs:
self.initializeAttribute('location', LatitudeLongitude)
return super(Event, self).init(*pargs, **kwargs)
def __str__(self):
return self.__unicode__().encode('utf-8') if PY2 else self.__unicode__()
def __unicode__(self):
return text_type(self.address)
class Person(DAObject):
"""Represents a legal or natural person."""
def init(self, *pargs, **kwargs):
if not hasattr(self, 'name') and 'name' not in kwargs:
self.name = Name()
if 'address' not in kwargs:
self.initializeAttribute('address', Address)
if 'location' not in kwargs:
self.initializeAttribute('location', LatitudeLongitude)
if 'name' in kwargs and isinstance(kwargs['name'], string_types):
if not hasattr(self, 'name'):
self.name = Name()
self.name.text = kwargs['name']
del kwargs['name']
# if 'roles' not in kwargs:
# self.roles = set()
return super(Person, self).init(*pargs, **kwargs)
class DAAttachmentList(DAList):
def init(self, **kwargs):
self.object_type = DAAttachment
return super(DAAttachmentList, self).init(**kwargs)
def url_list(self):
return docassemble.base.functions.comma_and_list(map(lambda x: '[`' + x.markdown_filename + '`](' + docassemble.base.functions.url_of("playgroundfiles", section="template", file=x.markdown_filename) + ')', self.elements))
class DAUploadMultiple(DAObject):
def init(self, **kwargs):
return super(DAUploadMultiple, self).init(**kwargs)
class DAUpload(DAObject):
def init(self, **kwargs):
return super(DAUpload, self).init(**kwargs)
class DAInterview(DAObject):
def init(self, **kwargs):
self.blocks = list()
self.initializeAttribute('questions', DAQuestionDict)
self.initializeAttribute('final_screen', DAQuestion)
self.initializeAttribute('decorations', DADecorationDict)
self.target_variable = None
return super(DAInterview, self).init(**kwargs)
def has_decorations(self):
if self.decorations.gathered and len(self.decorations) > 0:
return True
return False
def decoration_list(self):
out_list = [["None", "No decoration"]]
for key, data in self.decorations.iteritems():
out_list.append([key, '[EMOJI ' + str(data.fileref) + ', 1em] ' + str(key)])
return out_list
court.
"""
result = run_hook('court', self, 'in_the_court', self.jurisdiction)
if result is None:
return "In the " + self.name
return result
def _add_person_and_children_of(target, output_list):
if target not in output_list and target.identified():
output_list.append(target)
if hasattr(target, 'child'):
for child in target.child.elements:
_add_person_and_children_of(child, output_list)
class Case(DAObject):
"""Represents a case in court."""
def init(self, *pargs, **kwargs):
#logmessage("Case init: running")
self.court = Court()
self.defendant = PartyList()
self.plaintiff = PartyList()
self.firstParty = self.plaintiff
self.secondParty = self.defendant
self.is_solo_action = False
self.state = None
self.action_type = 'plaintiff defendant'
return super(Case, self).init(*pargs, **kwargs)
def __unicode__(self):
return text_type(self.case_id)
def __str__(self):
return self.__unicode__().encode('utf-8') if PY2 else self.__unicode__()
self.error = this_thread.current_info['user']['location']['error']
self.known = False
#logmessage("known is false")
self.gathered = True
self.description = text_type(self)
return
def __str__(self):
return self.__unicode__().encode('utf-8') if PY2 else self.__unicode__()
def __unicode__(self):
if hasattr(self, 'latitude') and hasattr(self, 'longitude'):
return text_type(self.latitude) + ', ' + text_type(self.longitude)
elif hasattr(self, 'error'):
return text_type(self.error)
return u'Unknown'
class RoleChangeTracker(DAObject):
"""Used within an interview to facilitate changes in the active role
required for filling in interview information. Ensures that participants
do not receive multiple e-mails needlessly."""
def init(self, *pargs, **kwargs):
self.last_role = None
return
# def should_send_email(self):
# """Returns True or False depending on whether an e-mail will be sent on
# role change"""
# return True
def _update(self, target_role):
"""When a notification is delivered about a necessary change in the
active role of the interviewee, this function is called with
the name of the new role. This prevents the send_email()
function from sending duplicative notifications."""
self.last_role = target_role
pass
return "---\n".join(output)
class DAField(DAObject):
def init(self, **kwargs):
return super(DAField, self).init(**kwargs)
class DAFieldList(DAList):
def init(self, **kwargs):
self.object_type = DAField
self.gathered = True
return super(DAFieldList, self).init(**kwargs)
def __str__(self):
return docassemble.base.functions.comma_and_list(map(lambda x: '`' + x.variable + '`', self.elements))
class DAQuestion(DAObject):
def init(self, **kwargs):
self.initializeAttribute('field_list', DAFieldList)
self.templates_used = set()
return super(DAQuestion, self).init(**kwargs)
def names_reduced(self):
varsinuse = Playground().variables_from(self.interview.known_source(skip=self))
var_list = sorted([field.variable for field in self.field_list])
return [var for var in varsinuse['all_names_reduced'] if var not in var_list and var != self.interview.target_variable]
def other_variables(self):
varsinuse = Playground().variables_from(self.interview.known_source(skip=self))
var_list = sorted([field.variable for field in self.field_list])
return [var for var in varsinuse['undefined_names'] if var not in var_list and var != self.interview.target_variable]
def source(self, follow_additional_fields=True):
content = ''
if self.type == 'question':
if self.field_list[0].field_type not in ['end_attachment']:
output += text_type(self.city)
if hasattr(self, 'state') and self.state:
output += ", " + text_type(self.state)
if hasattr(self, 'zip') and self.zip:
output += " " + text_type(self.zip)
elif hasattr(self, 'postal_code') and self.postal_code:
output += " " + text_type(self.postal_code)
return(output)
class City(Address):
"""A geographic address specific only to a city."""
def init(self, *pargs, **kwargs):
self.city_only = True
return super(City, self).init(*pargs, **kwargs)
class Thing(DAObject):
"""Represents something with a name."""
def init(self, *pargs, **kwargs):
if not hasattr(self, 'name') and 'name' not in kwargs:
self.name = Name()
if 'name' in kwargs and isinstance(kwargs['name'], string_types):
if not hasattr(self, 'name'):
self.name = Name()
self.name.text = kwargs['name']
del kwargs['name']
return super(Thing, self).init(*pargs, **kwargs)
def __setattr__(self, attrname, value):
if attrname == 'name' and isinstance(value, string_types):
self.name.text = value
else:
return super(Thing, self).__setattr__(attrname, value)
def __unicode__(self):
the_key = self._get_base_key() + ':' + key
return server.server_sql_defined(the_key)
def get(self, key):
"""Reads an object from the data store for the given key."""
the_key = self._get_base_key() + ':' + key
return server.server_sql_get(the_key, secret=this_thread.current_info.get('secret', None))
def set(self, key, value):
"""Writes an object to the data store under the given key."""
the_key = self._get_base_key() + ':' + key
server.server_sql_set(the_key, value, encrypted=self.is_encrypted(), secret=this_thread.current_info.get('secret', None), the_user_id=this_thread.current_info['user']['the_user_id'])
def delete(self, key):
"""Deletes an object from the data store"""
the_key = self._get_base_key() + ':' + key
server.server_sql_delete(the_key)
class DARedis(DAObject):
"""A class used to interact with the redis server."""
def key(self, keyname):
"""Returns a key that combines the interview name with the keyname."""
return this_thread.current_info.get('yaml_filename', '') + ':' + str(keyname)
def get_data(self, key):
"""Returns data from Redis and unpickles it."""
result = server.server_redis_user.get(key)
if result is None:
return None
try:
result = server.fix_pickle_obj(result)
except:
logmessage("get_data: could not unpickle contents of " + str(key))
result = None
return result
def set_data(self, key, data, expire=None):