def instantiate_recipient(config, cert, recipient): cert['recipient']['givenName'] = recipient.given_name cert['recipient']['familyName'] = recipient.family_name cert['recipient']['publicKey'] = recipient.pubkey if config.hash_emails: salt = helpers.encode(os.urandom(16)) cert['recipient']['salt'] = salt cert['recipient']['identity'] = hash_and_salt_email_address( recipient.identity, salt) else: cert['recipient']['identity'] = recipient.identity if config.additional_per_recipient_fields: if not recipient.additional_fields: raise Exception( 'expected additional recipient fields in the csv file but none found' ) for field in config.additional_per_recipient_fields: cert = jsonpath_helpers.set_field( cert, field['path'], recipient.additional_fields[field['csv_column']]) else: if recipient.additional_fields: # throw an exception on this in case it's a user error. We may decide to remove this if it's a nuisance raise Exception( 'there are fields in the csv file that are not expected by the additional_per_recipient_fields configuration' )
def save(self): if self.has_folder or self.is_actions_found: name = constants.INFO_FILE else: name = "{}.json".format(self.attrs["Name"]) if "Type" in self.attrs \ and self.attrs['Type'] in constants.EXTERNAL_SOURCE_TYPES \ and "source" in self.attributes: source_name = name + constants.EXTERNAL_SOURCE_TYPES[ self.attrs['Type']] PARSER.write_file(source_name, "".join(self.attributes["source"])) self.attrs["source_file_name"] = source_name del self.attributes["source"] self.attributes = { key: encode(clean_data("".join(val))).split('\n') for (key, val) in self.attributes.items() } data = OrderedDict([("attrs", sort_dict(self.attrs)), ("attributes", sort_dict(self.attributes))]) data = json.dumps(data, indent=4) detect_guids(data) PARSER.write_file(name, data) if self.childs_order: order_data = json.dumps(self.childs_order, indent=4) detect_guids(order_data) PARSER.write_file(constants.CHILDS_ORDER, order_data) if self.has_folder or self.is_actions_found: PARSER.pop_from_current_path()
def instantiate_recipient(config, cert, recipient): if config.hash_emails: salt = helpers.encode(os.urandom(16)) cert['recipient']['hashed'] = True cert['recipient']['salt'] = salt cert['recipient']['identity'] = hash_and_salt_email_address( recipient.identity, salt) else: cert['recipient']['identity'] = recipient.identity cert['recipient']['hashed'] = False profile_field = scope_name('recipientProfile') cert[profile_field] = {} cert[profile_field]['type'] = ['RecipientProfile', 'Extension'] cert[profile_field]['name'] = recipient.name cert[profile_field][ 'publicKey'] = 'ecdsa-koblitz-pubkey:' + recipient.pubkey if config.additional_per_recipient_fields: if not recipient.additional_fields: raise Exception( 'expected additional recipient fields in the csv file but none found' ) for field in config.additional_per_recipient_fields: cert = jsonpath_helpers.set_field( cert, field['path'], recipient.additional_fields[field['csv_column']]) else: if recipient.additional_fields: # throw an exception on this in case it's a user error. We may decide to remove this if it's a nuisance raise Exception( 'there are fields in the csv file that are not expected by the additional_per_recipient_fields configuration' )
def guest(): # User reached route via POST if request.method == "POST": # Ensure there is a key in session if "keys" not in session: session["keys"] = randomkey() # CHANGE password's algorithm key if request.form.get("change"): session["keys"] = randomkey() flash( "Guest Mode: Password's algorithm key changed, but will be lost after the session ends." ) return redirect("/guest") # GET password if request.form.get("keyword"): keyword = request.form.get("keyword") keys = session["keys"] password = encode(keyword, keys) flash( "Guest Mode: The current password's algorithm key will be lost after the session ends." ) return render_template("guest.html", password=password) # User reached route via GET else: # Redirect to guest template return render_template("guest.html")
def extract(self): features = {} for movie_id, release, note in self.get_releases(): match = re.match(RELEASE_DATE_DMY_RE, release) if not match or match.lastindex != 2: match = re.match(RELEASE_DATE_MY_RE, release) if not match or match.lastindex != 2: logging.debug("Error parsing (%s): %s" % (movie_id, release)) continue if features.get(movie_id) is None: features[movie_id] = {} movie_feature = features[movie_id] month = match.group(1) year = match.group(2) if note == None: # assume NULL means premiere note = 'premiere' note = note.lower() for part in note.split(') ('): part = part.replace('(', '') part = part.replace(')', '') part = encode(part) movie_feature['release (%s) (%s)' % (part, month)] = 1 movie_feature['release (%s) (%s)' % (part, year)] = 1 movie_feature['release (%s) (%s %s)' % (part, month, year)] = 1 logging.debug('Extracted release date (%s): %s -> %s %s' % (movie_id, part, month, year)) return features
def extract(self): features = {} for movie_id, genre in self.get_genre(): genre = encode(genre) logging.debug("Extracted Genre: %s %s" % (movie_id, genre)) if features.get(movie_id) is None: features[movie_id] = {} features[movie_id]['genere_%s' % (genre)] = 1 return features
def generate_feature_base(self): for movie, rating in self._load_movies_with_ratings(): title = encode(movie.title) logging.info("Generating Base Features for %s (%s)" % (title, rating)) self.features[int(movie.id)] = { 'rating': float(rating), 'rating_rounded': int(round(float(rating))), 'title': title, 'features': {} }
def extract(self): features = {} # appearances is how many movies the person has appeared in for movie_id, person_id, role_id, role, name, appearances in self.with_appearances( self.get_cast(), self.MINIMUM_APPEARANCES, lambda x: x[1], # count of: person_id lambda x: x[0] # that appears in: movie_id ): name = encode(name) role = encode(role) logging.debug( "Extracted Actor: %s %s %s %s %s %s" % (movie_id, person_id, role_id, role, name, appearances) ) if features.get(movie_id) is None: features[movie_id] = {} features[movie_id]['cast_%s_%s' % (person_id, role_id)] = 1 return features
def child_data(self, data): if self.is_data_allowed: if self.current_mode == "Users": self.current_node[-1][1].append(encode(data)) elif self.current_mode == "LDAP": self.ldapf.write(data) elif self.current_mode == "Groups": ERROR("Group are unsupported")
def extract(self): features = {} appearances_per_movie = defaultdict(lambda: defaultdict(list)) average_rating_per_movie = defaultdict(lambda: defaultdict(list)) cast = self.get_cast() movie_ratings_map = self.load_movie_ratings_map() person_movie_rating_map = defaultdict(dict) for movie_id, person_id, role_id, role, name in cast: person_movie_rating_map[person_id][movie_id] = movie_ratings_map[movie_id] # appearances is how many movies the person has appeared in for movie_id, person_id, role_id, role, name, appearances in self.with_appearances( cast, 0, # Ignore minimum appearances lambda x: x[1], # count of: person_id lambda x: x[0] # that appears in: movie_id ): name = encode(name) role = encode(role) logging.debug( "Extracted Actor: %s %s %s %s %s %s" % (movie_id, person_id, role_id, role, name, appearances) ) if features.get(movie_id) is None: features[movie_id] = {} if appearances >= self.MINIMUM_APPEARANCES: features[movie_id]['cast_%s_%s' % (person_id, role_id)] = 1 appearances_per_movie[role_id][movie_id].append(appearances) person_ratings = [ float(rating) for rated_movie_id, rating in person_movie_rating_map[person_id].iteritems() if not rated_movie_id == movie_id ] if person_ratings: average_rating_per_movie[role_id][movie_id].append(numpy.mean(person_ratings)) self._add_bucket_features('appearances', features, appearances_per_movie) self._add_bucket_features('crew_ratings', features, average_rating_per_movie) return features
def generate_feature_base(self): for movie, rating in self._load_movies_with_ratings(): title = encode(movie.title) logging.info("Generating Base Features for %s (%s)" % (title, rating)) self.features[int(movie.id)] = { 'rating': float(rating), 'rating_rounded': int(round(float(rating))), 'title': title, 'features': {}, 'util_features': {} }
def write_attributes(attributes, indent): write_xml("Attributes", indent=indent) for key, value in attributes.items(): if isinstance(value, list): value = "\n".join(value) write_xml( "Attribute", attrs={"Name": key}, data=clean_data(encode(value)), indent=indent+2, close=True ) write_xml("Attributes", indent=indent, closing=True)
def extract(self): features = {} # appearances is how many movies the keyword has been applied to for keyword, movie_id, appearances in self.with_appearances( self.get_movie_keywords(), self.KEYWORD_COUNT, lambda x: x[0], # count of: keyword lambda x: x[1] # that appears in: movie_id ): keyword = encode(keyword) logging.debug("Extracted Keyword: %s %s %s" % (keyword, movie_id, appearances)) if features.get(movie_id) is None: features[movie_id] = {} features[movie_id][keyword] = 1 return features
def extract(self): features = {} # appearances is how many movies the keyword has been applied to for keyword, movie_id, appearances in self.with_appearances( self.get_movie_keywords(), self.KEYWORD_COUNT, lambda x: x[0], # count of: keyword lambda x: x[1] # that appears in: movie_id ): keyword = encode(keyword) logging.debug( "Extracted Keyword: %s %s %s" % (keyword, movie_id, appearances) ) if features.get(movie_id) is None: features[movie_id] = {} features[movie_id][keyword] = 1 return features
def end(self): global ACTION_EXT # remove unnecessary symbols from data and encode it for key, value in self.data.items(): self.data[key] = encode(clean_data("".join(value))) # detect application programming language ACTION_EXT = { "python": ".py", "vscript": ".vb" }.get(self.data["ScriptingLanguage"].lower(), "python") INFO("Sripts extention will be '*%s'", ACTION_EXT) INFO("Completed: Application Information") self.save() super(InformationTagHandler, self).end()
def child_data(self, data): if self.is_data_allowed: self.current_node["Params"][-1][1].append(encode(data))
def child_data(self, data): if not self.is_cdata_section: return if self.current_action: self.current_action["file"].write(encode(data))
def child_data(self, data): if self.current: self.current["file"].write(encode(data))
def user(): # User reached route via POST if request.method == "POST": # CHANGE password's algorithm key if request.form.get("change"): session["keys"] = randomkey() flash("Password's algorithm key Changed.") return redirect("/user") # GET password if request.form.get("keyword"): keyword = request.form.get("keyword") keys = session["keys"] password = encode(keyword, keys) session['password'] = password # Store in session for update need return redirect("/user") # SAVE password's algorithm key if request.form.get("save"): keyname = request.form.get("save") dt = datetime.now() n = session["keys"]["n"] number = session["keys"]["number"] upper = session["keys"]["upper"] lower = session["keys"]["lower"] symbol = session["keys"]["symbol"] db.execute( "INSERT INTO data (userid, datetime, n, number, upper, lower, symbol, keyname) VALUES (:userid, :datetime, :n, :number, :upper, :lower, :symbol, :keyname)", userid=session["userid"], datetime=dt, n=n, number=number, upper=upper, lower=lower, symbol=symbol, keyname=keyname) return redirect("/user") # SELECT stored password's algorithm key if request.form.get("select"): session["keys"] = db.execute( "SELECT n, number, upper, lower, symbol FROM data WHERE userid=:userid AND id=:id", userid=session["userid"], id=request.form.get("select") )[0] # The "[0]"" is fo take the dictionary out of the list for compatibility return redirect("/user") # DELETE stored password's algorithm key if request.form.get("delete"): db.execute("DELETE FROM data WHERE userid=:userid AND id=:id", userid=session["userid"], id=request.form.get("delete")) return redirect("/user") # DELETE ALL store password's algorithm key if request.form.get("deleteall"): db.execute("DELETE FROM data WHERE userid=:userid", userid=session["userid"]) return redirect("/user") # User reached route via GET else: # Ensure there are no keys are stored in session if not 'keys' in session: # Query database rows = db.execute( "SELECT * FROM data WHERE userid=:userid ORDER BY datetime", userid=session["userid"]) # Ensure no keys are stored in database if len(rows) == 0: session["keys"] = randomkey() else: session["keys"] = rows[0] # Query database for stored keys id and datetime idkeyname = db.execute( "SELECT id, datetime, keyname FROM data WHERE userid = :userid", userid=session["userid"]) # Ensure no password is stored in session password = None if 'password' in session: password = session['password'] # Redirect to user with all collected values return render_template("user.html", idkeyname=idkeyname, password=password)