<commit_before># imports for tornado
import tornado
from tornado import web, httpserver, ioloop
import tornado.options
from tornado.options import define, options

# imports for logging
import traceback
import os
from os import path

# imports for yara to work
#import akka
from io import StringIO
import base64
import binascii
import configparser
import sys
import yara

# Set up Tornado options
define("port", default=8080, help="port to run", type=int)

class YaraHandler(tornado.web.RequestHandler):
	@property
	def YaraEngine(self):
		return yara.load(sys.argv[1])

class YaraProcess(YaraHandler):
	def process(self, filename, rules=None):
		try:
			if rules:
				ruleBuff = StringIO()
				ruleBuff.write(rules)
				ruleBuff.seek(0)

				rules = yara.load(file=ruleBuff)
				results = rules.match(filename[0], external={'filename': filename[1]})
			else:
				results = self.YaraEngine.match(filename[0], external={'filename': filename[1]})
			results2 = list(map(lambda x: {"rules": x.rules}, results))
			return results2
		except Exception as e:
			return e

	def get(self, filename):
		print("get req")
		try:
			fullPath = (os.path.join('/tmp/', filename), filename)
			data = self.process(fullPath)
			print(data)
			self.write({"yara": data})
		except Exception as e:
			print(e)
			self.write({"error": traceback.format_exc(e)})

	def post(self, filename):
		print("post req")
		print(self.request.body)
		try:
			fullPath = os.path.join('/tmp/', filename)
			rules = base64.b64decode(self.get_body_argument('custom_rule')).decode('latin-1')
			data = self.process(fullPath, rules)
			print(data)
			self.write({"yara": data})
		except Exception as e:
			print(e)
			self.write({"error": traceback.format_exc(e)})

<commit_msg>adjusted lambda to use x.rule verses rules<commit_after># imports for tornado
import tornado
from tornado import web, httpserver, ioloop
import tornado.options
from tornado.options import define, options

# imports for logging
import traceback
import os
from os import path

# imports for yara to work
#import akka
from io import StringIO
import base64
import binascii
import configparser
import sys
import yara

# Set up Tornado options
define("port", default=8080, help="port to run", type=int)

class YaraHandler(tornado.web.RequestHandler):
	@property
	def YaraEngine(self):
		return yara.load(sys.argv[1])

class YaraProcess(YaraHandler):
	def process(self, filename, rules=None):
		try:
			if rules:
				ruleBuff = StringIO()
				ruleBuff.write(rules)
				ruleBuff.seek(0)

				rules = yara.load(file=ruleBuff)
				results = rules.match(filename[0], externals={'filename': filename[1]})
			else:
				results = self.YaraEngine.match(filename[0], externals={'filename': filename[1]})
			results2 = list(map(lambda x: {"rules": x.rule}, results))
			return results2
		except Exception as e:
			return e

	def get(self, filename):
		print("get req")
		try:
			fullPath = (os.path.join('/tmp/', filename), filename)
			data = self.process(fullPath)
			print(data)
			self.write({"yara": data})
		except Exception as e:
			print(e)
			self.write({"error": traceback.format_exc(e)})

	def post(self, filename):
		print("post req")
		print(self.request.body)
		try:
			fullPath = os.path.join('/tmp/', filename)
			rules = base64.b64decode(self.get_body_argument('custom_rule')).decode('latin-1')
			data = self.process(fullPath, rules)
			print(data)
			self.write({"yara": data})
		except Exception as e:
			print(e)
			self.write({"error": traceback.format_exc(e)})


{'fraction_non_alphanumeric': 0.13034797490017114, 'fraction_numerical': 0.010838562464346835, 'mean_word_length': 4.531545741324921, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4821652', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1151, 'n_words': 312}