Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, *pargs, **kwargs):
if len(pargs) > 0:
if ':' in pargs[0]:
raise Exception("MachineLearner: you cannot use a colon in a machine learning name")
question = docassemble.base.functions.get_current_question()
if question is not None:
self.group_id = question.interview.get_ml_store() + ':' + pargs[0]
else:
self.group_id = pargs[0]
if len(pargs) > 1:
self.initial_file = pargs[1]
if 'group_id' in kwargs:
self.group_id = kwargs['group_id']
if 'initial_file' in kwargs:
self.initial_file = kwargs['initial_file']
if kwargs.get('use_initial_file', False):
question = docassemble.base.functions.get_current_question()
if question is not None:
self.initial_file = question.interview.get_ml_store()
self.reset_counter = 0
def reset(self):
formatter = '%0' + text_type(len(text_type(max_pages))) + 'd'
for page in range(1, max_pages):
page_file = dict()
test_path = file_info['path'] + 'page-in-progress'
if os.path.isfile(test_path):
while (os.path.isfile(test_path) and time.time() - os.stat(test_path)[stat.ST_MTIME]) < 30:
if not os.path.isfile(test_path):
break
time.sleep(1)
page_file['extension'] = 'png'
page_file['path'] = file_info['path'] + 'page-' + formatter % page
page_file['fullpath'] = page_file['path'] + '.png'
if not os.path.isfile(page_file['fullpath']):
server.fg_make_png_for_pdf_path(file_info['path'] + '.pdf', 'page')
if os.path.isfile(page_file['fullpath']):
output += text_type(image_for_docx(docassemble.base.functions.DALocalFile(page_file['fullpath']), docassemble.base.functions.this_thread.current_question, docassemble.base.functions.this_thread.misc.get('docx_template', None), width=width))
else:
output += "[Error including page image]"
output += ' '
return(output)
def __unicode__(self):
return docassemble.base.functions.comma_and_list(map(lambda x: '`' + x.variable + '`', self.elements))
def from_url(self, url):
"""Makes the contents of the file the contents of the given URL."""
self.retrieve()
cookiefile = tempfile.NamedTemporaryFile(suffix='.txt')
the_path = self.file_info['path']
f = open(the_path, 'wb')
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.WRITEDATA, f)
c.setopt(pycurl.USERAGENT, docassemble.base.functions.server.daconfig.get('user agent', 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36'))
c.setopt(pycurl.COOKIEFILE, cookiefile.name)
c.perform()
c.close()
self.retrieve()
def _make_pdf_thumbnail(self, page):
import docassemble.base.functions
docassemble.base.functions.server_context.context = 'celery'
import docassemble.base.interview_cache
import docassemble.base.parse
import docassemble.base.ocr
worker_controller.flaskapp = flaskapp
worker_controller.set_request_active = set_request_active
worker_controller.fetch_user_dict = fetch_user_dict
worker_controller.save_user_dict = save_user_dict
worker_controller.obtain_lock = obtain_lock
worker_controller.obtain_lock_patiently = obtain_lock_patiently
worker_controller.release_lock = release_lock
worker_controller.Message = Message
worker_controller.reset_user_dict = reset_user_dict
worker_controller.da_send_mail = da_send_mail
worker_controller.functions = docassemble.base.functions
worker_controller.interview_cache = docassemble.base.interview_cache
worker_controller.parse = docassemble.base.parse
worker_controller.retrieve_email = retrieve_email
worker_controller.get_info_from_file_number = get_info_from_file_number
worker_controller.trigger_update = trigger_update
worker_controller.ocr = docassemble.base.ocr
worker_controller.r = r
worker_controller.apiclient = apiclient
worker_controller.get_ext_and_mimetype = get_ext_and_mimetype
worker_controller.loaded = True
worker_controller.get_user_object = get_user_object
worker_controller.login_user = login_user
worker_controller.error_notification = error_notification
worker_controller.noquote = noquote
import sys
sys.stderr.write("1\n")
import eventlet
sys.stderr.write("2\n")
eventlet.sleep()
sys.stderr.write("3\n")
eventlet.monkey_patch()
sys.stderr.write("4\n")
from six import string_types, text_type, PY2
import docassemble.base.config
docassemble.base.config.load(arguments=sys.argv)
from docassemble.base.config import daconfig
import docassemble.base.functions
docassemble.base.functions.server_context.context = 'websockets'
from flask_socketio import join_room, disconnect
from docassemble.webapp.app_socket import app, db, socketio
from sqlalchemy import create_engine, MetaData, or_, and_
from simplekv.memory.redisstore import RedisStore
import docassemble.base.util
import redis
import json
import datetime
import pytz
if PY2:
import cPickle as pickle
else:
import pickle
import re
new_set = set()
for sub_object in the_object:
new_set.add(recurse_obj(sub_object, recursive=recursive))
return new_list
else:
return the_object
if type(the_object) is dict:
if 'object' in the_object and ('item' in the_object or 'items' in the_object):
if the_object['object'] in globals() and inspect.isclass(globals()[the_object['object']]):
constructor = globals()[the_object['object']]
elif the_object['object'] in locals() and inspect.isclass(locals()[the_object['object']]):
constructor = locals()[the_object['object']]
if not constructor:
if 'module' in the_object:
if the_object['module'].startswith('.'):
module_name = docassemble.base.functions.this_thread.current_package + the_object['module']
else:
module_name = the_object['module']
new_module = __import__(module_name, globals(), locals(), [the_object['object']], -1)
constructor = getattr(new_module, the_object['object'], None)
if not constructor:
raise SystemError('recurse_obj: found an object for which the object declaration, ' + str(the_object['object']) + ' could not be found')
if 'items' in the_object:
objects = list()
for item in the_object['items']:
if type(item) is not dict:
raise SystemError('recurse_obj: found an item, ' + str(item) + ' that was not expressed as a dictionary')
if recursive:
transformed_item = recurse_obj(item)
else:
transformed_item = item
#new_obj = constructor(**transformed_item)
def save_numbered_file(filename, orig_path, yaml_file_name=None, uid=None):
if uid is None:
try:
uid = docassemble.base.functions.get_uid()
assert uid is not None
except:
uid = unattached_uid()
if uid is None:
raise Exception("save_numbered_file: uid not defined")
file_number = get_new_file_number(uid, filename, yaml_file_name=yaml_file_name)
extension, mimetype = get_ext_and_mimetype(filename)
new_file = SavedFile(file_number, extension=extension, fix=True)
new_file.copy_from(orig_path)
new_file.save(finalize=True)
return(file_number, extension, mimetype)
interview_status = docassemble.base.parse.InterviewStatus(current_info=dict(user=dict(is_anonymous=False, is_authenticated=True, email=cron_user.email, theid=cron_user_id, the_user_id=cron_user_id, roles=[role.name for role in cron_user.roles], firstname=cron_user.first_name, lastname=cron_user.last_name, nickname=cron_user.nickname, country=cron_user.country, subdivisionfirst=cron_user.subdivisionfirst, subdivisionsecond=cron_user.subdivisionsecond, subdivisionthird=cron_user.subdivisionthird, organization=cron_user.organization, location=None, session_uid='cron'), session=key, secret=None, yaml_filename=filename, url=None, url_root=None, encrypted=False, action=cron_type_to_use, interface='cron', arguments=dict()))
interview.assemble(the_dict, interview_status)
save_status = docassemble.base.functions.this_thread.misc.get('save_status', 'new')
if interview_status.question.question_type in ["restart", "exit", "exit_logout"]:
reset_user_dict(key, filename, force=True)
if interview_status.question.question_type in ["restart", "exit", "logout", "exit_logout", "new_session"]:
release_lock(key, filename)
interview_status.do_sleep()
elif interview_status.question.question_type == "backgroundresponseaction":
new_action = interview_status.question.action
interview_status = docassemble.base.parse.InterviewStatus(current_info=dict(user=user_info, session=key, secret=None, yaml_filename=filename, url=None, url_root=None, encrypted=False, action=new_action['action'], arguments=new_action['arguments'], interface='cron'))
try:
interview.assemble(the_dict, interview_status)
except:
pass
save_status = docassemble.base.functions.this_thread.misc.get('save_status', 'new')
if save_status != 'ignore':
save_user_dict(key, the_dict, filename, encrypt=False, manual_user_id=cron_user_id, steps=steps, max_indexno=indexno)
release_lock(key, filename)
interview_status.do_sleep()
elif interview_status.question.question_type == "response" and interview_status.questionText == 'null':
release_lock(key, filename)
interview_status.do_sleep()
else:
if save_status != 'ignore':
save_user_dict(key, the_dict, filename, encrypt=False, manual_user_id=cron_user_id, steps=steps, max_indexno=indexno)
release_lock(key, filename)
interview_status.do_sleep()
if interview_status.question.question_type == "response":
if hasattr(interview_status.question, 'all_variables'):
if hasattr(interview_status.question, 'include_internal'):
include_internal = interview_status.question.include_internal
def __init__(self, file_number, extension=None, fix=False, section='files', filename='file', project=None, subdir=None):
file_number = int(file_number)
section = str(section)
if section not in docassemble.base.functions.this_thread.saved_files:
docassemble.base.functions.this_thread.saved_files[section] = dict()
if file_number in docassemble.base.functions.this_thread.saved_files[section]:
# sys.stderr.write("SavedFile: using cache for " + section + '/' + str(file_number) + "\n")
sf = docassemble.base.functions.this_thread.saved_files[section][file_number]
for attribute in ['file_number', 'fixed', 'section', 'filename', 'extension', 'directory', 'path', 'modtimes', 'keydict', 'subdir']:
if hasattr(sf, attribute):
setattr(self, attribute, getattr(sf, attribute))
self.extension = extension
self.filename = filename
self.subdir = subdir
else:
# sys.stderr.write("SavedFile: not using cache for " + section + '/' + str(file_number) + "\n")
docassemble.base.functions.this_thread.saved_files[section][file_number] = self
self.fixed = False
self.file_number = file_number
self.section = section