def import_database(self, data): db = self.context if 'settings.yaml' in data: db.annotation['acl'] = yaml.load(data['settings.yaml']).get('acl', None) if 'forms' in data: for (form_id, form_data) in data['forms'].items(): db.context.create_form( yaml.load(form_data[form_id+'.yaml']), form_data[form_id+'.py'], form_data[form_id+'.html'], )
def main(args): arch = lookup_architecture(args.architecture) addresses = yaml.load(args.input) object_sizes = yaml.load(args.object_sizes) register_object_sizes(object_sizes) # create the list of reserved regions. This duplicates the load_images part of the elf loader. Ultimately # we should feed this info to the elf loader rather than doing it dynamically reserved = SortedList() # first the kernel image kernel_elf = ELFFile(args.kernel_elf) kernel_region = get_load_bounds(kernel_elf) # elfloader currently rounds end to page boundary kernel_region = Region(kernel_region.start, round_up(kernel_region.end, PAGE_SIZE)) reserved.add(kernel_region) # now the DTB next_paddr = kernel_region.end if args.dtb_size: dtb_region = Region(next_paddr, round_up(next_paddr + args.dtb_size, PAGE_SIZE)) reserved.add(dtb_region) print("DTB: {0}<-->{1}".format(hex(dtb_region.start), hex(dtb_region.end))) available = SortedList() for a in addresses['memory']: # trim to paddr-top start, end = a['start'], a['end'] if args.paddr_top is not None: start = min(start, args.paddr_top) end = min(end, args.paddr_top) if start != end: available.add(Region(start, end)) # calculate free regions based on available + reserved regions freemem = init_freemem(available, reserved) # create untyped for each region untypeds = [] for f in freemem: untypeds += create_untypeds_for_region(object_sizes, f, arch, False) # create untyped for each device untyped for d in addresses['devices']: untypeds += create_untypeds_for_region(object_sizes, Region(d['start'], d['end']), arch, True) # finally output the file yaml.dump(untypeds, args.output)
def read_yaml(path: Path) -> t.Dict[str, t.Any]: # type: ignore[misc] """ Read a yaml to a dict. Schema is going to get verified later don't worry. :param path: Path to the yaml on disk. :return: Dict representation of yaml """ with open(path) as f: return dict(yaml.load(f, Loader=yaml.FullLoader))
def get_settings(): settings_file = "%s/.touchandgo/settings.yaml" % os.getenv("HOME") if not exists(settings_file): default = join(dirname(__file__), "templates", "settings.yaml") copyfile(default, settings_file) settings = yaml.load(open(settings_file).read()) return settings
def _load_settings(self): yaml_settings = yaml.load(self.app.context.get_block(self.id)) # if not dict provided, we assume the value is the type if 'elements' in yaml_settings: for (id, value) in yaml_settings['elements'].items(): if type(value) is str: yaml_settings['elements'][id] = {'type': value} settings = DEFAULT_SETTINGS.copy() settings.update(yaml_settings) return settings
def get_param(): with open(paramfile, "r") as f: p = yaml.load(f, Loader=yaml.Loader) topics = p.keys() param = {} for topic in topics: elems = p[topic].keys() for e in elems: #print(e, p[topic][e]) param[e] = p[topic][e]["default"] return param
def process_yaml(path, yaml_content): yaml_settings = yaml.load(yaml_content) if not yaml_settings: return if 'view' in yaml_settings: config = yaml_settings['view'] with_theme = False if isinstance(config, dict): id = config['id'] with_theme = config.get('with_theme', False) else: id = config path = '/'.join(path[-path[::-1].index('rapido'):]) path = path.rpartition('.')[0] view = get_block_view(path, with_theme) provideAdapter(view, (Interface, IBrowserRequest), Interface, name=id)
def init_aws_conn(credentials_filepath): """Parse Amazon API credentials and return an API connection object. Args: credentials_filepath: String, path to a yaml with AWS API credentials. Returns: aws_conn: amazonproduct.API object """ CREDS_FILEPATH='/home/royceremer/source/fophl_book_sorter/credentials.yaml' with open(CREDS_FILEPATH,'r') as creds_yaml: creds_dict = yaml.load(creds_yaml) aws_api = amazonproduct.API( creds_dict.get('aws_access_key_id'), creds_dict.get('aws_secret_access_key'), 'en') # 'en' is not a valid region... #TODO: impliment node each time it's invoked so that variable terms get pulled return aws_api
import os from datetime import datetime import json import urllib.request import urllib.parse import re import event_sender from pyaml import yaml import ssl with open("credentials.yaml", "r") as creds_file: config = yaml.load(creds_file) WITH_PROXY = False # on/off proxy. Default is off API_URL = config["group-ib"]["api_url"] API_USER = config["group-ib"]["api_user"] # your user API_KEY = config["group-ib"]["api_key"] # your API KEY DATA_DIR = 'data/' # directory for saving data LIMIT = config["group-ib"]["api_limit"] # limit for most data BIG_DATA_LIMIT = config["group-ib"]["api_big_limit"] # limit for big data LANG_DEF = 1 LANG_RUS = 2 LANG_ENG = 3 DEFAULT_DATES = { "accs": "2019-09-05", "cards": "2019-09-05",
def set_last(self, new, feed): with open(self.last_file, "r") as f: lasts = yaml.load(f) lasts[feed] = new with open(self.last_file, "w") as f: yaml.dump(lasts, f, default_flow_style=False)
def get_last(self, feed): with open(self.last_file, "r") as f: lasts = yaml.load(f) return lasts[feed]
#!/usr/bin/env python3 from pyaml import yaml import os from mastodon import Mastodon with open("fedi.login", "r") as f: login = yaml.load(f.read(), Loader=yaml.FullLoader) if not os.path.exists(".oauth.secret"): Mastodon.create_app( "yuibot", api_base_url=login["instance"], to_file=".oauth.secret" ) if not os.path.exists(".user.secret"): mastodon = Mastodon(client_id=".oauth.secret", api_base_url=login["instance"]) mastodon.log_in(login["username"], login["password"], to_file=".user.secret") mastodon = Mastodon(access_token=".user.secret", api_base_url=login["instance"]) if __name__ == "__main__": with open("cloud.png", "rb") as f: res = mastodon.media_post(f, "image/png") mastodon.status_post("@floatingghost", media_ids=[res["id"]], visibility="direct")
def __init__(self, context): self.context = context self.app_context = context.context self.settings = yaml.load(self.context.get_settings()) self._messages = [] self._blocks = {}
parser = argparse.ArgumentParser(description='Run a glue process between MISP and MISP-Modules') parser.add_argument("-c", "--config", default="misp-glue.yaml", help="Config file location") parser.add_argument("-v", "--verbose", default=False, action="store_true") args = parser.parse_args() # Set up logger logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) log = logging.getLogger(__name__) log.debug("Parsed arguments") try: log.debug("Trying to read config file %s", args.config) with open(args.config, "r") as f: config = yaml.load(f.read()) except FileNotFoundError: raise GlueError("Could not load config file at {}".format(args.config)) except PermissionError: raise GlueError("Could not read config file {} :: PERMISSIONS ERROR".format(args.config)) if not config: raise GlueError("I think your YAML is invalid!") # Set up our ZMQ socket to recieve MISP JSON on publish context = zmq.Context() socket = context.socket(zmq.SUB) log.info("Subscribing to tcp://%s:%s", config["zmq"]["host"], config["zmq"]["port"]) # Connect to the socket
def test_api_index_skip_limit_order_by(client): uid_list = [] for i in range(1, 11): res = client.post("/persons", data=json.dumps({ "first_name": str(i), "last_name": str(i + 1), "phone_number": str(i * 2) }), headers={"Content-Type": "application/json"}) if "uid" in res.json: uid_list.append(res.json["uid"]) assert len(uid_list) == 10 # skip more than available res = client.get("/persons", query_string={"skip": 11}, headers={"Content-Type": "application/json"}) assert res.status_code == 422 assert "errors" in res.json # skip one item and return only one, ordered by first_name res = client.get("/persons", query_string={ "skip": 1, "limit": 1, "order_by": "first_name" }, headers={"Content-Type": "application/json"}) assert res.status_code == 200 assert "people" in res.json assert len(res.json["people"]) == 1 assert res.json["people"][0]["first_name"] == "10" assert res.json["people"][0]["last_name"] == "11" # reverse sort order res = client.get("/persons", query_string={ "skip": 1, "limit": 1, "order_by": "-first_name" }, headers={"Content-Type": "application/json"}) assert res.status_code == 200 assert "people" in res.json # order by non existing property res = client.get("/persons", query_string={ "skip": 1, "limit": 1, "order_by": "prop1" }, headers={"Content-Type": "application/json"}) assert res.status_code == 404 assert "errors" in res.json # get all persons in YAML format res = client.get("/persons", query_string={"order_by": "first_name"}, headers={"Accept": "text/yaml"}) assert res.status_code == 200 data = yaml.load(res.data) assert "people" in data assert len(data["people"]) == 10 assert data["people"][0]["first_name"] == "1" assert data["people"][0]["last_name"] == "2" # get all persons in XML format res = client.get("/persons", query_string={"order_by": "first_name"}, headers={"Accept": "text/xml"}) assert res.status_code == 200 data = ET.fromstring(res.data) assert len(data.findall("people")) == 1 assert len([i for i in data.iter("item")]) == 10 # delete all persons by uid for uid in uid_list: res = client.delete("/persons/" + uid) assert res.status_code == 200 assert res.json == {"result": "OK"}
psi_cell: 0 psi_phi_cell: 0 sim-time: 200 comments: |- all propensity parameters are normalized to cell growth (which is 1.0). """ from matplotlib import pyplot from pyaml import yaml from delay_ssa import run_delayed_ssa from scipy import linspace #RUN the example system and plot the results system = yaml.load(burst_model) result = run_delayed_ssa(system) for i in result['participants']: i[1] = i[1] * 10 pyplot.plot(result['time'], result['participants']) pyplot.legend(result['headers'], bbox_to_anchor=(1.05, 1), loc=2) #pyplot.ylim([0,100]) #pyplot.xlim([0,10]) ''' #RUN for many parameters particles = [ [1,10], [10, 50], [10,100], [20, 100], [30, 100], [50, 100] , [100, 100], [100, 300] , [100, 1000] ] res = [] for p in particles: system['participants']['phi'] = p[0] system['participants']['psi'] = p[1]
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") log.setLevel(logging.DEBUG if args.verbose else logging.INFO) # If we want, print the output to stdout if args.stdout: formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") ch = logging.StreamHandler(sys.stdout) ch.setFormatter(formatter) log.addHandler(ch) # Read in the remote server configurations configFile = "{}/remote-servers.yml".format(os.path.expanduser(args.configdir)) log.debug("Opening config file %s", configFile) with open(configFile, "r") as f: config = yaml.load(f.read()) log.debug("Config read %s", config) # Read in the local server configuration localConfig = "{}/local-server.yml".format(os.path.expanduser(args.configdir)) log.debug("Reading local server config") with open(localConfig, "r") as f: localConfig = yaml.load(f.read()) # Attempt to make contact with the local server log.info("Connecting to local server...") localClient = create_client(host=localConfig["host"], port=localConfig["port"], discovery_path=localConfig["discovery_path"], use_https=localConfig["use_https"], version=localConfig["taxii_version"],
def load_config(config_file): with open(config_file) as f: config = yaml.load(f) return config
from misp_stix_converter.converters import lint_roller import logging # Set up logger log = logging.getLogger(__name__) formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") ch = logging.FileHandler("push.log") ch.setFormatter(formatter) log.addHandler(ch) log.setLevel(logging.DEBUG) log.info("Starting...") # Try to load in config if "OPENTAXII_CONFIG" in os.environ: config = yaml.load(open(os.environ["OPENTAXII_CONFIG"], "r"), Loader=Loader) else: print("OPENTAXII CONFIG NOT EXPORTED") sys.exit() # Set up our ZMQ socket to recieve MISP JSON on publish context = zmq.Context() socket = context.socket(zmq.SUB) log.info("Subscribing to tcp://{}:{}".format(config["zmq"]["host"], config["zmq"]["port"])) # Connect to the socket socket.connect("tcp://{}:{}".format(config["zmq"]["host"], config["zmq"]["port"])) # Set the option to subscribe
#!/usr/bin/env python # -*- coding: utf-8 -*- from pyaml import yaml import os # Module level pokedex with open(os.path.join(os.path.dirname(__file__), 'pokedex.yml')) as f: pokedex = yaml.load(f) templates = { "statement": [ u"My favorite Pokemon is {name}", u"Have you ever seen a {name}?", u"I had a bad experience with {name} once", u"I've heard that {name} can be dangerous", u"I wouldn't want to mess with a {name}", u"Do you know {name}?", u"I wish I saw {name} more often" ], "description": [ u"I know all about {name}. {desc}", u"Have you heard of {name}? {desc}", u"Oh yeah, {name}. {desc} Crazy, huh?", u"My Pokedex on {name} says: {desc}", u'When I asked Professor Oak about {name}, he said: "{desc}"', u"{name}? Hmmm... Lemme check the Pokedex: {desc}", u"Sure, I can tell you about {name}. {desc}", u"Wow, you know {name}? {desc}", u"Nobody has asked about {name} in a while. {desc}", u"Yes, I know {name}. {desc}", u"{name} is a friend of mine. {desc}" ], "type": [
def p5_reference(): with PYP5JS_FILES.p5_yml.open('r') as fd: return yaml.load(fd)
#!/usr/bin/env python3 import praw import pickle from pyaml import yaml import time import os #Load config with open("config.yaml", "r") as f: config = yaml.load(f)["api"] #Load brandlist with open("brandlist.txt", "r") as f: brands = [x for x in f.read().split("\n") if x != ""] #Defaults with open("defaults.txt", "r") as f: defaults = [x for x in f.read().split("\n") if x != ""] print("Loaded {} brands".format(len(brands))) def save_scanned(scanned): """ Save the posts we've already scanned """ with open("already_scanned.dat", "wb") as f: pickle.dump(scanned, f)
def _load_file(self, file_name): with open(file_name, 'r') as file_: settings = yaml.load(file_.read()) return settings
##### import os import pymisp import tempfile import logging from pyaml import yaml log = logging.getLogger("__main__") from opentaxii.signals import (CONTENT_BLOCK_CREATED, INBOX_MESSAGE_CREATED) ## CONFIG if "OPENTAXII_CONFIG" in os.environ: print("Using config from {}".format(os.environ["OPENTAXII_CONFIG"])) CONFIG = yaml.load(open(os.environ["OPENTAXII_CONFIG"], "r")) else: print("Trying to use env variables...") if "MISP_URL" in os.environ: misp_url = os.environ["MISP_URL"] else: print("Unkown misp URL. Set OPENTAXII_CONFIG or MISP_URL.") misp_url = "UNKNOWN" if "MISP_API" in os.environ: misp_api = os.environ["MISP_API"] else: print("Unknown misp API key. Set OPENTAXII_CONFIG or MISP_API.") misp_api = "UNKNOWN" CONFIG = {"misp": {"url": misp_url, "api": misp_api}}
# If we want, print the output to stdout if args.stdout: formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") ch = logging.StreamHandler(sys.stdout) ch.setFormatter(formatter) log.addHandler(ch) # Read in the remote server configurations config_file = "{}/remote-servers.yml".format( os.path.expanduser(args.configdir)) log.debug("Opening config file %s", config_file) with open(config_file, "r") as f: config = yaml.load(f.read(), Loader=Loader) log.debug("Config read %s", config) # Read in the local server configuration local_config = "{}/local-server.yml".format(os.path.expanduser(args.configdir)) log.debug("Reading local server config") with open(local_config, "r") as f: local_config = yaml.load(f.read(), Loader=Loader) # Attempt to make contact with the local server log.info("Connecting to local server...") local_client = create_client(host=local_config["host"], port=local_config["port"], discovery_path=local_config["discovery_path"], use_https=local_config["use_https"], version=local_config["taxii_version"],
import os import sys import requests from mastodon import Mastodon from pyaml import yaml from urllib.parse import urljoin with open("config.yaml", "r") as f: config = yaml.load(f) BASE_URL = config["instance"] user_creds = ".usersecret" app_secret = ".app_secret" if not os.path.exists(user_creds): Mastodon.create_app("reactor", api_base_url=BASE_URL, to_file=app_secret) mastodon = Mastodon(client_id=app_secret, api_base_url=BASE_URL) mastodon.log_in(config["user"], config["password"], to_file=user_creds) mastodon = Mastodon(access_token=user_creds, api_base_url=BASE_URL) token = mastodon.access_token id = sys.argv[1] word = sys.argv[2] base = 127462 letters = "abcdefghijklmnopqrstuvwxyz" mapping = {}
#!/usr/bin/env python # -*- coding: utf-8 -*- from pyaml import yaml import os # Module level pokedex with open(os.path.join(os.path.dirname(__file__), 'pokedex.yml')) as f: pokedex = yaml.load(f) templates = { "statement": [u"My favorite Pokemon is {name}", u"Have you ever seen a {name}?", u"I had a bad experience with {name} once", u"I've heard that {name} can be dangerous", u"I wouldn't want to mess with a {name}", u"Do you know {name}?", u"I wish I saw {name} more often"], "description": [u"I know all about {name}. {desc}", u"Have you heard of {name}? {desc}", u"Oh yeah, {name}. {desc} Crazy, huh?", u"My Pokedex on {name} says: {desc}", u'When I asked Professor Oak about {name}, he said: "{desc}"', u"{name}? Hmmm... Lemme check the Pokedex: {desc}", u"Sure, I can tell you about {name}. {desc}", u"Wow, you know {name}? {desc}", u"Nobody has asked about {name} in a while. {desc}", u"Yes, I know {name}. {desc}", u"{name} is a friend of mine. {desc}"], "type": [u"{name} is a {ptype} Pokemon", u"Did you know that {name} is {ptype} type",