コード例 #1
0
    def check(indent, expected):
        d1 = dson.dumps(h, indent=indent)
        assert d1 == expected

        sio = StringIO()
        dson.dump(h, sio, indent=indent)
        assert sio.getvalue() == expected
コード例 #2
0
ファイル: dogeon.py プロジェクト: jekil/cuckoo-fu
 def run(self, results):
     """Writes report.
     @param results: Cuckoo results dict.
     @raise CuckooReportError: if fails to write report.
     """
     try:
         path = os.path.join(self.reports_path, "report.doge")
         report = codecs.open(path, "w", "utf-8")
         dson.dump(results, report, indent=4)
         report.close()
     except (UnicodeError, TypeError, IOError) as e:
         raise CuckooReportError("Failed to generate Dogeon report: %s" % e)
コード例 #3
0
ファイル: dogeon.py プロジェクト: jekil/cuckoo-fu
 def run(self, results):
     """Writes report.
     @param results: Cuckoo results dict.
     @raise CuckooReportError: if fails to write report.
     """
     try:
         path = os.path.join(self.reports_path, "report.doge")
         report = codecs.open(path, "w", "utf-8")
         dson.dump(results, report, indent=4)
         report.close()
     except (UnicodeError, TypeError, IOError) as e:
         raise CuckooReportError("Failed to generate Dogeon report: %s" % e)
コード例 #4
0
ファイル: test_dump.py プロジェクト: soasme/dogeon
def test_dump():
    sio = StringIO()
    dson.dump({}, sio)
    assert sio.getvalue() == 'such wow'
コード例 #5
0
ファイル: test_dump.py プロジェクト: soasme/dogeon
def test_dump():
    sio = StringIO()
    dson.dump({}, sio)
    assert sio.getvalue() == 'such wow'
コード例 #6
0
def parseCMD(msg):
	cmds = msg.split(); cmd = SearchableString(len(cmds) > 0 and cmds[0] or "")
	curArea = Areas[States["area"]]
	if cmd == "load":
		SaveName = len(cmds) > 1 and cmds[1] or raw_input("Save name: >")
		if SaveName:
			NewStates, NewInventory = dson.load(open(SaveName+".dson","r"))
			States.clear(); Inventory.clear()
			States.update(NewStates); Inventory.update(NewInventory)
			print("== Progress loaded from '"+SaveName+".dson' ==")
	elif cmd == "save":
		SaveName = len(cmds) > 1 and cmds[1] or raw_input("Save name: >")
		if SaveName:
			dson.dump((States, Inventory), open(SaveName+".dson","w"), indent=2)
			print("== Progress saved to '"+SaveName+".dson' ==")
	elif cmd in ("clear", "cls"):
		consolelib.clear()
		print(" ")
	elif cmd in ("h", "help"):
		print ("You consider for a moment the verbs you've learned:\n"
			"go/enter [room]\n"
			"back/return/last goes to previous room\n"
			"look/examine/view [object]\n"
			"grab/pick/get/take [object]\n"
			"use [object] on [object]\n"
			"lockpick [object]\n"
			"time\n"
			"map\n"
			"i/inventory\n"
			"save [filename]\n"
			"load [filename]")
	elif cmd in ("i", "inventory"):
		if "backpack" in States:
			print("You stop and look at the contents of your leather backpack:")
			for item in Inventory.values():
				print("\t- "+item)
			print("\t- Lockpicking pins: "+str(States["pins"]))
			print("\t- Money: $%.2f" % States["money"])
		else:
			say("There isn't anything in your pockets. You try to start missions light.")
	elif cmd in ("time", "watch"):
		if "watch" in States: say("You glance at your Booker's display of the current local time: "+getTime())
		else: say("Your booker's internal clock hasn't been configured for this locale, and is still displaying your home time: " + str(int(States["time"]/1.44)))
	elif cmd in ("map",):
		say("You review your Booker's spatial layouting program.")
		with consolelib.lineByLine(0.03):
			openMap(curArea.zone)
	elif cmd == "" or (cmd in LOOK and len(cmds) == 1):
		curArea.describe()
	elif cmd in ("back", "return", "last") or "go back" in msg:
		if "lastarea" in States: setArea(States["lastarea"])
		else: say("You just walked into the building, you can't leave yet.")
	elif cmd in GO:
		curArea.GO(cmd, cmds, msg)
	elif cmd in LOOK:
		if ("booker", "arm") in msg:
			say("The Booker on your arm is an advanced Personal Information Processor. The 2000 model premiered in the year 8AA, and is primarily built from salvaged Old world components modified to support an MF power core. Its many features include a watch, 3D scanner, 1w laser pointer (doubles as a microwelder), journal logging, and flying toasters screensaver.")
		elif ("keyhole") in msg: say("You peer through the door's keyhole, but can't see anything, since there's a lock in the way.")
		else:
			curArea.LOOK(cmd, cmds, msg)
	elif cmd in GET:
		curArea.GET(cmd, cmds, msg)
	elif cmd in USE:
		with consolelib.listenPrints() as printedString:
			curArea.USE(cmd, cmds, msg)
		if printedString[0]: pass
		elif "magazines" in Inventory and ("maga", "zine") in msg:
			say("Is now the best time to be doing that?")
		elif "crochetagebook" in Inventory and "crochet" in msg:
			say("You flip through the booklet, but you can't understand the language. The diagrams detail the basics of picking locks.")
		elif ("water", "hydra", "bottle") in msg and "waterbottle" in Inventory:
			say("You're not thirsty at the moment.")
	elif cmd in LOCKPICK:
		if len(cmds) == 1:
			say("What locked object do you want to pick?")
		else:
			curArea.LOCKPICK(cmd, cmds, msg)
	elif "bumbl" in cmd:
		say("Bumbling around into furniture isn't really productive."
			"Besides, you're supposed to follow 'leave no trace' when Seeking.")
	elif ("break", "kick", "smash") in cmd:
		say("Seekers can't just go around breaking things, especially not in old ruins.")
	elif ("hello", "hi", "hey") in cmd: say("Ello.")
	elif ("yes") in cmd: say("Nope.")
	elif ("no") in cmd: say("Yep.")
コード例 #7
0
			time.sleep(0.18)
		time.sleep(0.8)
		consolelib.clear()
		time.sleep(0.3)
		
	if "time" not in States:
		#New game!
		States["time"] = 9*60
		States["pins"] = 0
		States["money"] = 3
		consolelib.clear()
		if(raw_input("""\n\n\n\n\n\n\n\n\n\n\n
                      There is much to see in this world,
                  take care to `look` at everything you find.
\n\n\n\n\n\n
                          [Press Enter to Start Game]
                   [Type 'help' at any time to list commands]
\n""") == "help"): parseCMD("help")
		setArea("lobby")
	
	WasKBInterrupt = False
	try:
		main()
	except KeyboardInterrupt:
		WasKBInterrupt = True
	finally:
		if not WasKBInterrupt:
			print("Eeek we crashed! Emergency saving to crash.dson...")
			dson.dump((States, Inventory), open("crash.dson","w"))
			print("Save successful! Printing stacktrace:\n")
コード例 #8
0
ファイル: fade.py プロジェクト: Nebual/fade
def parseCMD(msg):
    msg = SearchableString(msg.lower())
    cmds = msg.split()
    cmd = SearchableString(len(cmds) > 0 and cmds[0] or "")

    curArea = Areas[States["area"]]
    if cmd == "load":
        SaveName = len(cmds) > 1 and cmds[1] or input("Save name: >")
        if SaveName:
            NewStates, NewInventory = dson.load(
                open(getSaveDir() + SaveName + ".dson", "r"))
            States.clear()
            Inventory.clear()
            States.update(NewStates)
            Inventory.update(NewInventory)
            print("== Progress loaded from '" + SaveName + ".dson' ==")
    elif cmd == "save":
        SaveName = len(cmds) > 1 and cmds[1] or input("Save name: >")
        if SaveName:
            dson.dump((States, Inventory),
                      open(getSaveDir() + SaveName + ".dson", "w"),
                      indent=2)
            print("== Progress saved to '" + SaveName + ".dson' ==")
    elif cmd in ("clear", "cls"):
        consolelib.clear()
        print(" ")
    elif cmd in ("h", "help"):
        print("You consider for a moment the verbs you've learned:\n"
              "go/enter [room]\n"
              "back/return/last goes to previous room\n"
              "look/examine/view [object]\n"
              "grab/pick/get/take [object]\n"
              "use [object] on [object]\n"
              "lockpick [object]\n"
              "time\n"
              "map\n"
              "i/inventory\n"
              "save [filename]\n"
              "load [filename]")
    elif cmd in ("i", "inventory"):
        if "backpack" in States:
            print(
                "You stop and look at the contents of your leather backpack:")
            for item in Inventory.values():
                print("\t- " + item)
            print("\t- Lockpicking pins: " + str(States["pins"]))
            print("\t- Money: $%.2f" % States["money"])
        else:
            say("There isn't anything in your pockets. You try to start missions light."
                )
    elif cmd in ("time", "watch"):
        if "watch" in States:
            say("You glance at your Booker's display of the current local time: "
                + getTime())
        else:
            say("Your booker's internal clock hasn't been configured for this locale, and is still displaying your home time: "
                + str(int(States["time"] / 1.44)))
    elif cmd in ("map", ):
        say("You review your Booker's spatial layouting program.")
        with consolelib.lineByLine(0.03):
            openMap(curArea.zone)
    elif cmd == "" or (cmd in LOOK and len(cmds) == 1):
        curArea.describe()
    elif cmd in ("back", "return", "last") or "go back" in msg:
        if "lastarea" in States: setArea(States["lastarea"])
        else: say("You just walked into the building, you can't leave yet.")
    elif cmd in GO:
        curArea.GO(cmd, cmds, msg)
    elif cmd in LOOK:
        if ("booker", "arm") in msg:
            say("The Booker on your arm is an advanced Personal Information Processor. The 2000 model premiered in the year 8AA, and is primarily built from salvaged Old world components modified to support an MF power core. Its many features include a watch, 3D scanner, 1w laser pointer (doubles as a microwelder), journal logging, and flying toasters screensaver."
                )
        elif ("keyhole") in msg:
            say("You peer through the door's keyhole, but can't see anything, since there's a lock in the way."
                )
        else:
            curArea.LOOK(cmd, cmds, msg)
    elif cmd in GET:
        curArea.GET(cmd, cmds, msg)
    elif cmd in USE:
        with consolelib.listenPrints() as printedString:
            curArea.USE(cmd, cmds, msg)
        if printedString[0]: pass
        elif "magazines" in Inventory and ("maga", "zine") in msg:
            say("Is now the best time to be doing that?")
        elif "crochetagebook" in Inventory and "crochet" in msg:
            say("You flip through the booklet, but you can't understand the language. The diagrams detail the basics of picking locks."
                )
        elif ("water", "hydra",
              "bottle") in msg and "waterbottle" in Inventory:
            say("You're not thirsty at the moment.")
    elif cmd in LOCKPICK:
        if len(cmds) == 1:
            say("What locked object do you want to pick?")
        else:
            curArea.LOCKPICK(cmd, cmds, msg)
    elif "bumbl" in cmd:
        say("Bumbling around into furniture isn't really productive."
            "Besides, you're supposed to follow 'leave no trace' when Seeking."
            )
    elif ("break", "kick", "smash") in cmd:
        say("Seekers can't just go around breaking things, especially not in old ruins."
            )
    elif ("hello", "hi", "hey") in cmd:
        say("Ello.")
    elif ("yes") in cmd:
        say("Nope.")
    elif ("no") in cmd:
        say("Yep.")
コード例 #9
0
ファイル: fade.py プロジェクト: Nebual/fade
        consolelib.clear()
        if (input("""\n\n\n\n\n\n\n\n\n\n\n
                      There is much to see in this world,
                  take care to `look` at everything you find.
\n\n\n\n\n\n
                          [Press Enter to Start Game]
                   [Type 'help' at any time to list commands]
\n""") == "help"):
            parseCMD("help")
        setArea("lobby")

    WasKBInterrupt = False
    try:
        main()
    except KeyboardInterrupt:
        WasKBInterrupt = True
    finally:
        if not WasKBInterrupt:
            print("Eeek we crashed! Emergency saving to crash.dson... ",
                  end="")
            dson.dump((States, Inventory),
                      open(getSaveDir() + "crash.dson", "w"),
                      indent=2)
            print("Save successful! Printing stacktrace:\n")
        else:
            print("Exiting; saving progress to last.dson... ", end="")
            dson.dump((States, Inventory),
                      open(getSaveDir() + "last.dson", "w"),
                      indent=2)
            print("Done. Seeya!")
コード例 #10
0
ファイル: fade.py プロジェクト: Nebual/fade
		
	if "time" not in States:
		#New game!
		States["time"] = 9*60
		States["pins"] = 0
		States["money"] = 3
		consolelib.clear()
		if(input("""\n\n\n\n\n\n\n\n\n\n\n
                      There is much to see in this world,
                  take care to `look` at everything you find.
\n\n\n\n\n\n
                          [Press Enter to Start Game]
                   [Type 'help' at any time to list commands]
\n""") == "help"): parseCMD("help")
		setArea("lobby")
	
	WasKBInterrupt = False
	try:
		main()
	except KeyboardInterrupt:
		WasKBInterrupt = True
	finally:
		if not WasKBInterrupt:
			print("Eeek we crashed! Emergency saving to crash.dson... ", end="")
			dson.dump((States, Inventory), open(getSaveDir() + "crash.dson","w"), indent=2)
			print("Save successful! Printing stacktrace:\n")
		else:
			print("Exiting; saving progress to last.dson... ", end="")
			dson.dump((States, Inventory), open(getSaveDir() + "last.dson", "w"), indent=2)
			print("Done. Seeya!")