Exemplo n.º 1
0
def spec_parser(filename):
    """
    extract tests from specification
    """
    sections = []
    buffer = ""
    in_section = False
    for line in open(filename):
        if line.startswith('Test::'):
            in_section = True
            buffer = ""
        elif in_section:
            if line.startswith("  ") or not line.strip():
                buffer += line.lstrip()
            else:
                sections.append(buffer)
                in_section = False
    tests = []
    for section in sections:
        subsections = [t for t in section.strip().split('$ ls') if t]
        for subsection in subsections:
            path, results = subsection.splitlines()[0], subsection.splitlines(
            )[1:]
            path = path.strip()
            items = set(
                [i for i in sre.split('[\t\n]', '\n'.join(results)) if i])
            tests.append((path, items))
    return tests
Exemplo n.º 2
0
def main():
    gaia = wikipedia.getSite(code=u'en', fam=u'gaia')
    plot = wikipedia.getSite(code=u'en', fam=u'plotwiki')

    wikipedia.setAction(wikipedia.translate(gaia, msg))
    wikipedia.setAction(wikipedia.translate(plot, msg))

    final = u'<noinclude><!-- Do not edit this page, this page is automatically created by a Bot. -->\n'
    final += u'==Most Recent Events==</noinclude>\n'

    nonrecent = u'<noinclude>==Older Events==\n'
    end = u'\n\'\'View everything here on the [[Plotwiki:|plotwiki...]]\'\'</noinclude>'

    moreYears = True
    year = 04

    events = []
    temp = []
    while moreYears:
        y = str(year)
        page = wikipedia.Page(plot, u'Template:Pnav%s' % y.zfill(2))

        try:
            text = page.get()

            r = sre.compile(u'^.*<span style=".*normal.*">(.*)</span>.*$',
                            sre.UNICODE | sre.MULTILINE | sre.DOTALL)
            text = sre.sub(r, u'\\1', text)
            r = sre.compile(u'\s+\|\s+',
                            sre.UNICODE | sre.MULTILINE | sre.DOTALL)
            pages = sre.split(r, text)

            r = sre.compile(u'\[\[([^|]*)(\|.*)?\]\]', sre.UNICODE)
            for p in pages:
                temp.append(sre.sub(r, u'\\1', p))

            year += 1
        except wikipedia.NoPage:
            moreYears = False
    for e in temp:
        if not e in events:
            events.append(e)

    events = reversed(list(events))
    x = 1
    for e in events:
        final += u'* [[Plotwiki:%s|]]\n' % e
        x += 1
        if x == 6:
            final += nonrecent
    if x <= 6:
        final += end
    final += end

    page = wikipedia.Page(gaia, u'Plotwiki Current Events')
    page.put(final)
Exemplo n.º 3
0
    def __init__(self, test, params):
        """
        Find paths for transparent hugepages and kugepaged configuration. Also,
        back up original host configuration so it can be restored during
        cleanup.
        """
        self.params = params

        RH_THP_PATH = "/sys/kernel/mm/redhat_transparent_hugepage"
        UPSTREAM_THP_PATH = "/sys/kernel/mm/transparent_hugepage"
        if os.path.isdir(RH_THP_PATH):
            self.thp_path = RH_THP_PATH
        elif os.path.isdir(UPSTREAM_THP_PATH):
            self.thp_path = UPSTREAM_THP_PATH
        else:
            raise THPNotSupportedError("System doesn't support transparent "
                                       "hugepages")

        tmp_list = []
        test_cfg = {}
        test_config = self.params.get("test_config", None)
        if test_config is not None:
            tmp_list = re.split(';', test_config)
        while len(tmp_list) > 0:
            tmp_cfg = tmp_list.pop()
            test_cfg[re.split(":", tmp_cfg)[0]] = sre.split(":", tmp_cfg)[1]
        # Save host current config, so we can restore it during cleanup
        # We will only save the writeable part of the config files
        original_config = {}
        # List of files that contain string config values
        self.file_list_str = []
        # List of files that contain integer config values
        self.file_list_num = []
        for f in os.walk(self.thp_path):
            base_dir = f[0]
            if f[2]:
                for name in f[2]:
                    f_dir = os.path.join(base_dir, name)
                    parameter = file(f_dir, 'r').read()
                    try:
                        # Verify if the path in question is writable
                        f = open(f_dir, 'w')
                        f.close()
                        if re.findall("\[(.*)\]", parameter):
                            original_config[f_dir] = re.findall("\[(.*)\]",
                                                           parameter)[0]
                            self.file_list_str.append(f_dir)
                        else:
                            original_config[f_dir] = int(parameter)
                            self.file_list_num.append(f_dir)
                    except IOError:
                        pass

        self.test_config = test_cfg
        self.original_config = original_config
Exemplo n.º 4
0
def main():
	gaia = wikipedia.getSite(code=u'en', fam=u'gaia')
	plot = wikipedia.getSite(code=u'en', fam=u'plotwiki')
	
	wikipedia.setAction(wikipedia.translate(gaia, msg))
	wikipedia.setAction(wikipedia.translate(plot, msg))
	
	final = u'<noinclude><!-- Do not edit this page, this page is automatically created by a Bot. -->\n'
	final+= u'==Most Recent Events==</noinclude>\n'
	
	nonrecent = u'<noinclude>==Older Events==\n'
	end = u'\n\'\'View everything here on the [[Plotwiki:|plotwiki...]]\'\'</noinclude>'
	
	moreYears = True
	year = 04
	
	events = []
	temp = []
	while moreYears:
		y = str(year)
		page = wikipedia.Page(plot, u'Template:Pnav%s' % y.zfill(2))
		
		try:
			text = page.get()
			
			r = sre.compile(u'^.*<span style=".*normal.*">(.*)</span>.*$', sre.UNICODE | sre.MULTILINE | sre.DOTALL)
			text = sre.sub(r, u'\\1', text)
			r = sre.compile(u'\s+\|\s+', sre.UNICODE | sre.MULTILINE | sre.DOTALL)
			pages = sre.split(r, text)
			
			r = sre.compile(u'\[\[([^|]*)(\|.*)?\]\]', sre.UNICODE)
			for p in pages:
				temp.append(sre.sub(r, u'\\1', p))
			
			year+=1
		except wikipedia.NoPage:
			moreYears = False
	for e in temp:
		if not e in events:
			events.append(e)
	
	events = reversed(list(events));
	x = 1
	for e in events:
		final+=u'* [[Plotwiki:%s|]]\n' % e
		x+=1
		if x==6:
			final+=nonrecent
	if x<=6:
		final+=end
	final+=end
	
	page = wikipedia.Page(gaia, u'Plotwiki Current Events')
	page.put(final)
def read_matlab(file):

    import sre
    f = open(file, 'r')
    data = []
    str = f.readline()
    while str:
        l = sre.split(' ', str)
        del (l[-1])
        data.append(map(float, l))
        str = f.readline()

    return Numeric.array(data)
Exemplo n.º 6
0
def read_matlab(file):

    import sre
    f = open(file,'r')
    data = []
    str = f.readline()
    while str:
        l = sre.split(' ',str)
        del(l[-1])
        data.append(map(float,l))
        str = f.readline()

    return numpy.array(data)
Exemplo n.º 7
0
def read_matlab(file):
    """
    Read a file containing an array in MatLab text (.dat) format, and
    return the corresponding array.
    """
    import sre
    f = open(file, 'r')
    data = []
    str = f.readline()
    while str:
        l = sre.split(' ', str)
        del (l[-1])
        data.append(map(float, l))
        str = f.readline()

    return numpy.array(data)
def cacheText(files, cache):
    for f in files:
        fh = file(f)
        for line in fh:
            for word in sre.split("\s+", line):
                modWord = word.lower()
                modWord = modWord.rstrip(".)`']>\":;,!?")
                modWord = modWord.lstrip("([<`\"':")

                if "http://" in modWord:
                    continue

                if len(modWord) < 2:
                    continue

                #print modWord
                cache.add(modWord)
Exemplo n.º 9
0
def main():
	#Setup Familys for Wikia Involved
	anime = wikipedia.getSite(code=u'en', fam=u'anime')
	wikipedia.setAction(wikipedia.translate(anime, msg))
	siteList = []
	
	#Get Project Wiki Listing
	wikiaIds = []
	page = wikipedia.Page(anime, u'Bots/Wiki', None, None, 4)#4=Project Namespace
	try:
		text = page.get()
		r = sre.compile(u'^.*<!-- \|\|START\|\| -->\n?', sre.UNICODE | sre.DOTALL)
		text = sre.sub(r, u'', text)
		r = sre.compile(u'\n?<!-- \|\|END\|\| -->.*$', sre.UNICODE | sre.DOTALL)
		text = sre.sub(r, u'', text)
		r = sre.compile(u'\n', sre.UNICODE | sre.MULTILINE | sre.DOTALL)
		wikilist = sre.split(r, text)
		for wiki in wikilist:
			if wiki != u'':
				wikiaIds.append(wiki)
	except wikipedia.NoPage:
		moreYears = False
	
	for wiki in wikiaIds:
		siteList.append(wikipedia.getSite(code=u'en', fam=wiki))
	
	commonstart = u'@import "http://en.anime.wikia.com/index.php?title=MediaWiki:Anime-Common.css&action=raw&ctype=text/css";'
	monobookstart = u'@import "http://en.anime.wikia.com/index.php?title=MediaWiki:Anime-Monobook.css&action=raw&ctype=text/css";'
	
	for site in siteList:
		common = wikipedia.Page(site, u'Common.css', None, None, 8)#8=MediaWiki Namespace
		monobook = wikipedia.Page(site, u'Monobook.css', None, None, 8)#8=MediaWiki Namespace

				siteSource = u''
				try:
					siteSource = sitePage.get()
				except wikipedia.NoPage:
					wikipedia.output(u'Site %s has no %s template, creating it' % (site, template))
				if siteSource != templateSource:
					wikipedia.output(u'Site \'%s\' template status: Needs Updating' % site)
					wikipedia.output(u'Updating template on %s' % site)
					sitePage.put(templateSource)
				else:
					wikipedia.output(u'Site \'%s\' template status: Ok' % site)
Exemplo n.º 10
0
    def interfaceScreen(self):
        'Use a popup to display the opening text'
        if (CyGame().isPitbossHost()):
            return

        self.calculateSizesAndPositions()

        self.player = gc.getPlayer(gc.getGame().getActivePlayer())
        self.EXIT_TEXT = localText.getText("TXT_KEY_SCREEN_CONTINUE", ())

        # Create screen

        screen = CyGInterfaceScreen("CvDawnOfMan", self.iScreenID)
        screen.showScreen(PopupStates.POPUPSTATE_QUEUED, False)
        screen.showWindowBackground(False)
        screen.setDimensions(self.X_SCREEN, screen.centerY(self.Y_SCREEN),
                             self.W_SCREEN, self.H_SCREEN)
        screen.enableWorldSounds(false)

        # Create panels

        # Main
        szMainPanel = "DawnOfManMainPanel"
        screen.addPanel(szMainPanel, "", "", true, true, self.X_MAIN_PANEL,
                        self.Y_MAIN_PANEL, self.W_MAIN_PANEL,
                        self.H_MAIN_PANEL, PanelStyles.PANEL_STYLE_MAIN)

        # Top
        szHeaderPanel = "DawnOfManHeaderPanel"
        screen.addPanel(szHeaderPanel, "", "", true, false,
                        self.X_HEADER_PANEL, self.Y_HEADER_PANEL,
                        self.W_HEADER_PANEL, self.H_HEADER_PANEL,
                        PanelStyles.PANEL_STYLE_DAWNTOP)

        # Bottom
        szTextPanel = "DawnOfManTextPanel"
        screen.addPanel(szTextPanel, "", "", true, true, self.X_TEXT_PANEL,
                        self.Y_TEXT_PANEL, self.W_TEXT_PANEL,
                        self.H_TEXT_PANEL, PanelStyles.PANEL_STYLE_DAWNBOTTOM)

        # Add contents

        # Leaderhead graphic
        szLeaderPanel = "DawnOfManLeaderPanel"
        screen.addPanel(szLeaderPanel, "", "", true, false,
                        self.X_LEADER_ICON - 3, self.Y_LEADER_ICON - 5,
                        self.W_LEADER_ICON + 6, self.H_LEADER_ICON + 8,
                        PanelStyles.PANEL_STYLE_DAWNTOP)
        screen.addLeaderheadGFC("LeaderHead", self.player.getLeaderType(),
                                AttitudeTypes.ATTITUDE_PLEASED,
                                self.X_LEADER_ICON + 5, self.Y_LEADER_ICON + 5,
                                self.W_LEADER_ICON - 10,
                                self.H_LEADER_ICON - 10,
                                WidgetTypes.WIDGET_GENERAL, -1, -1)

        # Info/"Stats" text

        szNameText = "<color=255,255,0,255><font=3b>%s</font>\n- %s -" % (
            gc.getLeaderHeadInfo(
                self.player.getLeaderType()).getDescription().upper(),
            self.player.getCivilizationDescription(0))
        screen.addMultilineText(
            "NameText", szNameText, self.X_LEADER_TITLE_TEXT,
            self.Y_LEADER_TITLE_TEXT, self.W_LEADER_TITLE_TEXT,
            self.H_LEADER_TITLE_TEXT, WidgetTypes.WIDGET_GENERAL, -1, -1,
            CvUtil.FONT_CENTER_JUSTIFY)

        szSpecialText = CyGameTextMgr().parseLeaderTraits(
            self.player.getLeaderType(), -1, False, True)
        szSpecialText = (sre.split('\n', szSpecialText, maxsplit=1))[1]
        szSpecialText = remLinks.sub("", szSpecialText)
        TextArray = (sre.split("\<color\=", szSpecialText))
        self.Text_BoxText = ""
        X_Trait = self.X_STATS_TEXT
        Y_Trait = self.Y_STATS_TEXT - 5
        iLoop = 0
        for szTraitText in TextArray:
            if (szTraitText == ""):
                continue
            szBodyText = "<font=2><color=%s</font>" % (szTraitText)
            screen.addMultilineText("HeaderText%02d" % (iLoop), szBodyText,
                                    X_Trait, Y_Trait, 260,
                                    self.H_STATS_TEXT + 50,
                                    WidgetTypes.WIDGET_GENERAL, -1, -1,
                                    CvUtil.FONT_LEFT_JUSTIFY)
            X_Trait += 260
            iLoop += 1

        screen.addMultilineText(
            "HeaderText2",
            "<font=2>%s:</font>" % (localText.getText("TXT_KEY_FREE_TECHS",
                                                      ())),
            self.X_STATS_TEXT - 180, self.Y_ICON_PANEL, self.W_STATS_TEXT,
            self.H_STATS_TEXT, WidgetTypes.WIDGET_GENERAL, -1, -1,
            CvUtil.FONT_LEFT_JUSTIFY)

        screen.addPanel("HeaderText3", "", "", false, true,
                        self.X_STATS_TEXT - 180, self.Y_ICON_PANEL + 20,
                        self.W_TECH, self.H_TECH,
                        PanelStyles.PANEL_STYLE_EMPTY)

        for iTech in xrange(gc.getNumTechInfos()):
            if (gc.getCivilizationInfo(
                    self.player.getCivilizationType()).isCivilizationFreeTechs(
                        iTech)):
                screen.attachCheckBoxGFC("HeaderText3", "",
                                         gc.getTechInfo(iTech).getButton(), "",
                                         64, 64,
                                         WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH,
                                         iTech, 1,
                                         ButtonStyles.BUTTON_STYLE_IMAGE)

        # Unique Unit
        self.Text_BoxText = "<font=2>%s:</font>" % (localText.getText(
            "TXT_KEY_FREE_UNITS", ()))

        screen.addMultilineText("HeaderText4", self.Text_BoxText,
                                self.X_STATS_TEXT + 40, self.Y_ICON_PANEL,
                                self.W_STATS_TEXT - (self.iMarginSpace * 3),
                                self.H_STATS_TEXT - (self.iMarginSpace * 4),
                                WidgetTypes.WIDGET_GENERAL, -1, -1,
                                CvUtil.FONT_LEFT_JUSTIFY)

        screen.addPanel("HeaderText5", "", "", false, true,
                        self.X_STATS_TEXT + 40, self.Y_ICON_PANEL + 20,
                        self.W_TECH, self.H_TECH,
                        PanelStyles.PANEL_STYLE_EMPTY)

        for iUnit in xrange(gc.getNumUnitClassInfos()):
            iUniqueUnit = gc.getCivilizationInfo(
                self.player.getCivilizationType()).getCivilizationUnits(iUnit)
            iDefaultUnit = gc.getUnitClassInfo(iUnit).getDefaultUnitIndex()
            if (iDefaultUnit > -1 and iUniqueUnit > -1
                    and iDefaultUnit != iUniqueUnit):
                screen.attachImageButton(
                    "HeaderText5", "",
                    gc.getUnitInfo(iUniqueUnit).getButton(),
                    GenericButtonSizes.BUTTON_SIZE_CUSTOM,
                    WidgetTypes.WIDGET_PEDIA_JUMP_TO_UNIT, iUniqueUnit, 1,
                    False)

        # Unique Building
        self.Text_BoxText = "<font=2>%s:</font>" % (localText.getText(
            "TXT_KEY_UNIQUE_BUILDINGS", ()))

        screen.addMultilineText("HeaderText6", self.Text_BoxText,
                                self.X_STATS_TEXT + 190, self.Y_ICON_PANEL,
                                self.W_STATS_TEXT - (self.iMarginSpace * 3),
                                self.H_STATS_TEXT - (self.iMarginSpace * 4),
                                WidgetTypes.WIDGET_GENERAL, -1, -1,
                                CvUtil.FONT_LEFT_JUSTIFY)

        screen.addPanel("HeaderText7", "", "", false, true,
                        self.X_STATS_TEXT + 190, self.Y_ICON_PANEL + 20,
                        self.W_TECH, self.H_TECH,
                        PanelStyles.PANEL_STYLE_EMPTY)

        for iBuilding in xrange(gc.getNumBuildingClassInfos()):
            iUniqueBuilding = gc.getCivilizationInfo(
                self.player.getCivilizationType()).getCivilizationBuildings(
                    iBuilding)
            iDefaultBuilding = gc.getBuildingClassInfo(
                iBuilding).getDefaultBuildingIndex()
            if (iDefaultBuilding > -1 and iUniqueBuilding > -1
                    and iDefaultBuilding != iUniqueBuilding):
                screen.attachImageButton(
                    "HeaderText7", "",
                    gc.getBuildingInfo(iUniqueBuilding).getButton(),
                    GenericButtonSizes.BUTTON_SIZE_CUSTOM,
                    WidgetTypes.WIDGET_PEDIA_JUMP_TO_BUILDING, iUniqueBuilding,
                    1, False)

        # Fancy icon things
        # < Dawn Of Man Start >
        screen.addDDSGFC(
            "IconLeft",
            ArtFileMgr.getCivilizationArtInfo(
                gc.getCivilizationInfo(self.player.getCivilizationType()).
                getArtDefineTag()).getButton(), self.X_FANCY_ICON1,
            self.Y_FANCY_ICON, self.WH_FANCY_ICON, self.WH_FANCY_ICON,
            WidgetTypes.WIDGET_GENERAL, -1, -1)
        screen.addDDSGFC(
            "IconRight",
            ArtFileMgr.getCivilizationArtInfo(
                gc.getCivilizationInfo(self.player.getCivilizationType()).
                getArtDefineTag()).getButton(), self.X_FANCY_ICON2,
            self.Y_FANCY_ICON, self.WH_FANCY_ICON, self.WH_FANCY_ICON,
            WidgetTypes.WIDGET_GENERAL, -1, -1)
        # < Dawn Of Man End   >

        # Main Body text
        szDawnTitle = u"<font=3>%s</font>" % (localText.getText(
            "TXT_KEY_DAWN_OF_MAN_SCREEN_TITLE", ()).upper())
        screen.setLabel("DawnTitle", "Background", szDawnTitle,
                        CvUtil.FONT_CENTER_JUSTIFY,
                        self.X_TEXT_PANEL + (self.W_TEXT_PANEL / 2),
                        self.Y_TEXT_PANEL + 15, -2.0, FontTypes.GAME_FONT,
                        WidgetTypes.WIDGET_GENERAL, -1, -1)
        bodyString = localText.getText(
            "TXT_KEY_DAWN_OF_MAN_TEXT",
            (CyGameTextMgr().getTimeStr(gc.getGame().getGameTurn(), false),
             self.player.getCivilizationAdjectiveKey(),
             self.player.getNameKey()))
        if (Version.CGETestVersion):
            bodyString += "\n" + localText.getText(
                "TXT_KEY_CGE_TEST_VERSION_WARNING", ())
        screen.addMultilineText(
            "BodyText", bodyString, self.X_TEXT_PANEL + self.iMarginSpace,
            self.Y_TEXT_PANEL + self.iMarginSpace + self.iTEXT_PANEL_MARGIN,
            self.W_TEXT_PANEL - (self.iMarginSpace * 2),
            self.H_TEXT_PANEL - (self.iMarginSpace * 2) - 75,
            WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)

        screen.setButtonGFC("Exit", self.EXIT_TEXT, "", self.X_EXIT,
                            self.Y_EXIT, self.W_EXIT, self.H_EXIT,
                            WidgetTypes.WIDGET_CLOSE_SCREEN, -1, -1,
                            ButtonStyles.BUTTON_STYLE_STANDARD)

        pActivePlayer = gc.getPlayer(CyGame().getActivePlayer())
        pLeaderHeadInfo = gc.getLeaderHeadInfo(pActivePlayer.getLeaderType())
        screen.setSoundId(CyAudioGame().Play2DSoundWithId(
            pLeaderHeadInfo.getDiploPeaceMusicScriptIds(0)))
Exemplo n.º 11
0
    print 'Running tests on sre.subn'

try:
    assert sre.subn("(?i)b+", "x", "bbbb BBBB") == ('x x', 2)
    assert sre.subn("b+", "x", "bbbb BBBB") == ('x BBBB', 1)
    assert sre.subn("b+", "x", "xyz") == ('xyz', 0)
    assert sre.subn("b*", "x", "xyz") == ('xxxyxzx', 4)
    assert sre.subn("b*", "x", "xyz", 2) == ('xxxyz', 2)
except AssertionError:
    raise TestFailed, "sre.subn"

if verbose:
    print 'Running tests on sre.split'

try:
    assert sre.split(":", ":a:b::c") == ['', 'a', 'b', '', 'c']
    assert sre.split(":*", ":a:b::c") == ['', 'a', 'b', 'c']
    assert sre.split("(:*)", ":a:b::c") == ['', ':', 'a', ':', 'b', '::', 'c']
    assert sre.split("(?::*)", ":a:b::c") == ['', 'a', 'b', 'c']
    assert sre.split("(:)*", ":a:b::c") == ['', ':', 'a', ':', 'b', ':', 'c']
    assert sre.split("([b:]+)", ":a:b::c") == ['', ':', 'a', ':b::', 'c']
    assert sre.split("(b)|(:+)", ":a:b::c") == \
           ['', None, ':', 'a', None, ':', '', 'b', None, '', None, '::', 'c']
    assert sre.split("(?:b)|(?::+)", ":a:b::c") == ['', 'a', '', '', 'c']
except AssertionError:
    raise TestFailed, "sre.split"

try:
    assert sre.split(":", ":a:b::c", 2) == ['', 'a', 'b::c']
    assert sre.split(':', 'a:b:c:d', 2) == ['a', 'b', 'c:d']
Exemplo n.º 12
0
	def interfaceScreen(self):
		'Use a popup to display the opening text'
		if ( CyGame().isPitbossHost() ):
			return

		self.calculateSizesAndPositions()

		self.player = gc.getPlayer(gc.getGame().getActivePlayer())
		self.EXIT_TEXT = localText.getText("TXT_KEY_SCREEN_CONTINUE", ())

		# Create screen

		screen = CyGInterfaceScreen( "CvDawnOfMan", self.iScreenID )
		screen.showScreen(PopupStates.POPUPSTATE_QUEUED, False)
		screen.showWindowBackground( False )
		screen.setDimensions(self.X_SCREEN, screen.centerY(self.Y_SCREEN), self.W_SCREEN, self.H_SCREEN)
		screen.enableWorldSounds( false )

		# Create panels

		# Main
		szMainPanel = "DawnOfManMainPanel"
		screen.addPanel( szMainPanel, "", "", true, true,
			self.X_MAIN_PANEL, self.Y_MAIN_PANEL, self.W_MAIN_PANEL, self.H_MAIN_PANEL, PanelStyles.PANEL_STYLE_MAIN )

		# Top
		szHeaderPanel = "DawnOfManHeaderPanel"
		screen.addPanel( szHeaderPanel, "", "", true, false,
			self.X_HEADER_PANEL, self.Y_HEADER_PANEL, self.W_HEADER_PANEL, self.H_HEADER_PANEL, PanelStyles.PANEL_STYLE_DAWNTOP )

		# Bottom
		szTextPanel = "DawnOfManTextPanel"
		screen.addPanel( szTextPanel, "", "", true, true,
			self.X_TEXT_PANEL, self.Y_TEXT_PANEL, self.W_TEXT_PANEL, self.H_TEXT_PANEL, PanelStyles.PANEL_STYLE_DAWNBOTTOM )

		# Add contents

		# Leaderhead graphic
		szLeaderPanel = "DawnOfManLeaderPanel"
		screen.addPanel( szLeaderPanel, "", "", true, false,
			self.X_LEADER_ICON - 3, self.Y_LEADER_ICON - 5, self.W_LEADER_ICON + 6, self.H_LEADER_ICON + 8, PanelStyles.PANEL_STYLE_DAWNTOP )
		screen.addLeaderheadGFC("LeaderHead", self.player.getLeaderType(), AttitudeTypes.ATTITUDE_PLEASED,
			self.X_LEADER_ICON + 5, self.Y_LEADER_ICON + 5, self.W_LEADER_ICON - 10, self.H_LEADER_ICON - 10, WidgetTypes.WIDGET_GENERAL, -1, -1)

		# Info/"Stats" text

		szNameText = "<color=255,255,0,255><font=3b>%s</font>\n- %s -"%(gc.getLeaderHeadInfo(self.player.getLeaderType()).getDescription().upper(), self.player.getCivilizationDescription(0))
		screen.addMultilineText( "NameText", szNameText, self.X_LEADER_TITLE_TEXT, self.Y_LEADER_TITLE_TEXT, self.W_LEADER_TITLE_TEXT, self.H_LEADER_TITLE_TEXT, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_CENTER_JUSTIFY)

		szSpecialText = CyGameTextMgr().parseLeaderTraits(self.player.getLeaderType(), -1, False, True)
		szSpecialText = (sre.split('\n', szSpecialText, maxsplit=1))[1]
		szSpecialText = remLinks.sub("", szSpecialText)
		TextArray = (sre.split("\<color\=", szSpecialText))
		self.Text_BoxText =""
		X_Trait = self.X_STATS_TEXT
		Y_Trait = self.Y_STATS_TEXT - 5
		iLoop = 0
		for szTraitText in TextArray:
			if (szTraitText == ""):
				continue
			szBodyText = "<font=2><color=%s</font>"%(szTraitText)
			screen.addMultilineText( "HeaderText%02d"%(iLoop), szBodyText, X_Trait, Y_Trait, 260, self.H_STATS_TEXT + 50, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)
			X_Trait += 260
			iLoop += 1

		screen.addMultilineText( "HeaderText2", "<font=2>%s:</font>"%(localText.getText("TXT_KEY_FREE_TECHS", ())), self.X_STATS_TEXT - 180, self.Y_ICON_PANEL, self.W_STATS_TEXT, self.H_STATS_TEXT, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)

		screen.addPanel( "HeaderText3", "", "", false, true, self.X_STATS_TEXT - 180, self.Y_ICON_PANEL + 20, self.W_TECH, self.H_TECH, PanelStyles.PANEL_STYLE_EMPTY )

		for iTech in xrange(gc.getNumTechInfos()):
			if (gc.getCivilizationInfo(self.player.getCivilizationType()).isCivilizationFreeTechs(iTech)):
				screen.attachCheckBoxGFC("HeaderText3", "", gc.getTechInfo(iTech).getButton(), "", 64, 64, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, iTech, 1, ButtonStyles.BUTTON_STYLE_IMAGE)

		# Unique Unit
		self.Text_BoxText = "<font=2>%s:</font>"%(localText.getText("TXT_KEY_FREE_UNITS", ()))

		screen.addMultilineText( "HeaderText4", self.Text_BoxText, self.X_STATS_TEXT + 40, self.Y_ICON_PANEL, self.W_STATS_TEXT - (self.iMarginSpace * 3), self.H_STATS_TEXT - (self.iMarginSpace * 4), WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)

		screen.addPanel( "HeaderText5", "", "", false, true, self.X_STATS_TEXT + 40, self.Y_ICON_PANEL + 20, self.W_TECH, self.H_TECH, PanelStyles.PANEL_STYLE_EMPTY )

		for iUnit in xrange(gc.getNumUnitClassInfos()):
			iUniqueUnit = gc.getCivilizationInfo(self.player.getCivilizationType()).getCivilizationUnits(iUnit);
			iDefaultUnit = gc.getUnitClassInfo(iUnit).getDefaultUnitIndex();
			if (iDefaultUnit > -1 and iUniqueUnit > -1 and iDefaultUnit != iUniqueUnit):
				screen.attachImageButton( "HeaderText5", "", gc.getUnitInfo(iUniqueUnit).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_UNIT, iUniqueUnit, 1, False )

		# Unique Building
		self.Text_BoxText = "<font=2>%s:</font>"%(localText.getText("TXT_KEY_UNIQUE_BUILDINGS", ()))

		screen.addMultilineText( "HeaderText6", self.Text_BoxText, self.X_STATS_TEXT + 190, self.Y_ICON_PANEL, self.W_STATS_TEXT - (self.iMarginSpace * 3), self.H_STATS_TEXT - (self.iMarginSpace * 4), WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)

		screen.addPanel( "HeaderText7", "", "", false, true, self.X_STATS_TEXT + 190, self.Y_ICON_PANEL + 20, self.W_TECH, self.H_TECH, PanelStyles.PANEL_STYLE_EMPTY )

		for iBuilding in xrange(gc.getNumBuildingClassInfos()):
			iUniqueBuilding = gc.getCivilizationInfo(self.player.getCivilizationType()).getCivilizationBuildings(iBuilding);
			iDefaultBuilding = gc.getBuildingClassInfo(iBuilding).getDefaultBuildingIndex();
			if (iDefaultBuilding > -1 and iUniqueBuilding > -1 and iDefaultBuilding != iUniqueBuilding):
				screen.attachImageButton("HeaderText7", "", gc.getBuildingInfo(iUniqueBuilding).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BUILDING, iUniqueBuilding, 1, False )

		# Fancy icon things
		# < Dawn Of Man Start >
		screen.addDDSGFC( "IconLeft", ArtFileMgr.getCivilizationArtInfo(gc.getCivilizationInfo(self.player.getCivilizationType()).getArtDefineTag()).getButton(), self.X_FANCY_ICON1 , self.Y_FANCY_ICON , self.WH_FANCY_ICON, self.WH_FANCY_ICON, WidgetTypes.WIDGET_GENERAL, -1, -1 )
		screen.addDDSGFC( "IconRight", ArtFileMgr.getCivilizationArtInfo(gc.getCivilizationInfo(self.player.getCivilizationType()).getArtDefineTag()).getButton(), self.X_FANCY_ICON2 , self.Y_FANCY_ICON , self.WH_FANCY_ICON, self.WH_FANCY_ICON, WidgetTypes.WIDGET_GENERAL, -1, -1 )
		# < Dawn Of Man End   >

		# Main Body text
		szDawnTitle = u"<font=3>%s</font>"%(localText.getText("TXT_KEY_DAWN_OF_MAN_SCREEN_TITLE", ()).upper())
		screen.setLabel("DawnTitle", "Background", szDawnTitle, CvUtil.FONT_CENTER_JUSTIFY, self.X_TEXT_PANEL + (self.W_TEXT_PANEL / 2), self.Y_TEXT_PANEL + 15, -2.0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
		bodyString = localText.getText("TXT_KEY_DAWN_OF_MAN_TEXT", (CyGameTextMgr().getTimeStr(gc.getGame().getGameTurn(), false), self.player.getCivilizationAdjectiveKey(), self.player.getNameKey()))
		if (Version.CGETestVersion):
			bodyString += "\n" + localText.getText("TXT_KEY_CGE_TEST_VERSION_WARNING", ())
		screen.addMultilineText( "BodyText", bodyString, self.X_TEXT_PANEL + self.iMarginSpace, self.Y_TEXT_PANEL + self.iMarginSpace + self.iTEXT_PANEL_MARGIN, self.W_TEXT_PANEL - (self.iMarginSpace * 2), self.H_TEXT_PANEL - (self.iMarginSpace * 2) - 75, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)

		screen.setButtonGFC("Exit", self.EXIT_TEXT, "", self.X_EXIT, self.Y_EXIT, self.W_EXIT, self.H_EXIT, WidgetTypes.WIDGET_CLOSE_SCREEN, -1, -1, ButtonStyles.BUTTON_STYLE_STANDARD )

		pActivePlayer = gc.getPlayer(CyGame().getActivePlayer())
		pLeaderHeadInfo = gc.getLeaderHeadInfo(pActivePlayer.getLeaderType())
		screen.setSoundId(CyAudioGame().Play2DSoundWithId(pLeaderHeadInfo.getDiploPeaceMusicScriptIds(0)))
Exemplo n.º 13
0
def treepages(url, level):

    global treeglob, urlfields, postfields, treedurls, levels, server, vulnlogfile, scanlimit, ignorefileext
    print ">>>>>>>>", level, "<<<<<<<<"

    print " ---> " + url

    pageinfo = getpage(url)
    if listempty(pageinfo): return

    body = pageinfo[1].lower()

    print "AA"

    # select/option, textarea
    # check for forms
    bodyarr = sre.split("<form", body)
    for i in range(len(bodyarr)):

        frmsect = bodyarr[i][:bodyarr[i].find(">")]
        frmbody = bodyarr[i][bodyarr[i].find(">"):][:bodyarr[i].find("</form>"
                                                                     )]

        actionurl = getattrval(frmsect, "action")
        if actionurl == "" or actionurl == frmsect or actionurl == "\"\"":
            actionurl = pageinfo[2]
        if actionurl.count(";") > 0:
            actionurl = actionurl[actionurl.find(";") + 1:]
        if actionurl[:11].lower() == "javascript:": continue
        actionurl = fullpath(actionurl, pageinfo[2])

        print "ACTION:", actionurl

        # get the input variables
        poststring = ""
        inputarr = sre.sub("(.*?)\<input([^\>]*)\>(.*?)", "\\2|ZZaaXXaaZZ|",
                           frmbody).split("|ZZaaXXaaZZ|")
        for j in range(len(inputarr)):

            name = getattrval(inputarr[j], "name")
            if name == inputarr[j] or name == "" or name == "\"\"": continue

            value = getattrval(inputarr[j], "value")
            if value == inputarr[j] or value == "" or value == "\"\"":
                value = ""

            if poststring != "": poststring += "&"
            poststring += name + "=" + value

        # get select/option tags
        selectarr = sre.sub("(.*?)\<select([^\>]*)\>(.*?)", "\\2|ZZaaXXaaZZ|",
                            frmbody).split("|ZZaaXXaaZZ|")
        for j in range(len(selectarr)):

            name = getattrval(selectarr[j], "name")
            if name == selectarr[j] or name == "" or name == "\"\"": continue

            value = sre.sub(
                "(.*?)\<option([^\>]*)value=(\"|'|)([^\\3\ ]*)\\3([^\>]*)\>(.*?)",
                "\\2", selectarr[j])
            if value == selectarr[j] or value == "" or value == "\"\"":
                value = ""

            if poststring != "": poststring += "&"
            poststring += name + "=" + value
            print "sel/opt: " + name + "=" + value

        if poststring == "": continue

        if sre.search("method=([\'\"]|)post([\'\"]|)",
                      frmsect[:frmsect.find(">")].lower()) == None:
            if actionurl.find("?") != -1: actionurl += "&"
            else: actionurl += "?"
            actionurl += poststring
            body += '<a href="' + actionurl + '">'
            print 'GETT <a href="' + actionurl + '">'
            continue

        # determine if it needs to be scanned, and if so, scan it
        postscan = 0
        postvars = poststring.split("&")
        if postfields.has_key(actionurl):
            for j in range(len(postvars)):
                postvars[j] = postvars[j][:postvars[j].find("=")]
                if postfields[actionurl].count(postvars[j]) == 0:
                    postfields[actionurl].append(postvars[j])
                    postscan = 1
        else:
            for j in range(len(postvars)):
                postvars[j] = postvars[j][:postvars[j].find("=")]
            postfields[actionurl] = postvars
            postscan = 1

        if postscan == 1:
            vulns = checkvars(actionurl, poststring)
            if not listempty(vulns): dispvulns(vulns, actionurl)

    print "BB"

    # check for urls in "href" tags
    # ? # part of 3? (src|href|location|window.open)= and http://
    urlreg = "(\'|\")(?!javascript:)(([^\>]+?)(?!\.(" + ignorefileext.replace(
        ",", "|") + "))(.{3,8}?)(|\?([^\>]+?)))"
    urlarr = sre.sub(
        "(?s)(?i)(.+?)((src|href)=|location([\ ]*)=([\ ]*)|window\.open\()" +
        urlreg + "\\6", "\\7|ZZaaXXaaZZ|", body).split("|ZZaaXXaaZZ|")
    del urlarr[len(urlarr) - 1]
    urlarr.append(
        sre.sub("(?s)(?i)(.+?)(src|href)=" + urlreg + "\\3", "\\4|ZZaaXXaaZZ|",
                body).split("|ZZaaXXaaZZ|"))
    del urlarr[len(urlarr) - 1]
    for i in range(len(urlarr)):

        theurl = fullpath(urlarr[i], pageinfo[2])
        if not checkserver(servername(theurl)): continue

        # determine if it needs scanned and/or treed, and if so, scan and/or tree it
        getscan = 0
        if theurl.count("?") != 0:
            nqurl = theurl[:theurl.find("?")]
            query = theurl[theurl.find("?") + 1:]
            query = sre.sub("\&amp\;", "\&", query)
            qryvars = query.split("&")
            if urlfields.has_key(nqurl):
                for j in range(len(qryvars)):
                    qryvars[j] = qryvars[j][:qryvars[j].find("=")]
                    if urlfields[nqurl].count(qryvars[j]) == 0:
                        urlfields[nqurl].append(qryvars[j])
                        getscan = 1
            else:
                for j in range(len(qryvars)):
                    qryvars[j] = qryvars[j][:qryvars[j].find("=")]
                urlfields[nqurl] = qryvars
                getscan = 1
        else:
            if urlfields.has_key(theurl) == False: urlfields[theurl] = []
            nqurl = theurl

        if getscan == 1:
            vulns = checkvars(theurl)
            if not listempty(vulns): dispvulns(vulns, theurl)
        tree = treeglob
        if treedurls.has_key(nqurl):
            if treedurls[nqurl].count(theurl) == 0 and len(
                    treedurls[nqurl]) <= scanlimit:
                treedurls[nqurl].append(theurl)
            else:
                tree = 0

        else:
            treedurls[nqurl] = [theurl]
        if tree == 1 and level < levels:
            realurl = getpage(theurl, realpage=1)
            if theurl != realurl and realurl != None:
                body += ' href="' + realurl + '" '
            print "treeee"
            try:
                treepages(theurl, level + 1)
            except KeyboardInterrupt:
                treeglob = 0
                print "TREEGLOB CHANGED TO ZERO"
                treepages(theurl, level + 1)
Exemplo n.º 14
0
def treepages(url,level):

	global treeglob,urlfields,postfields,treedurls,levels,server,vulnlogfile,scanlimit,ignorefileext
	print ">>>>>>>>",level,"<<<<<<<<"

	print " ---> "+url

	pageinfo=getpage(url)
	if listempty(pageinfo): return

	body=pageinfo[1].lower()

	print "AA"

	# select/option, textarea
	# check for forms
	bodyarr=sre.split("<form",body)
	for i in range(len(bodyarr)):

		frmsect=bodyarr[i][:bodyarr[i].find(">")]
		frmbody=bodyarr[i][bodyarr[i].find(">"):][:bodyarr[i].find("</form>")]

		actionurl=getattrval(frmsect,"action")
		if actionurl=="" or actionurl==frmsect or actionurl=="\"\"": actionurl=pageinfo[2]
		if actionurl.count(";")>0: actionurl=actionurl[actionurl.find(";")+1:]
		if actionurl[:11].lower()=="javascript:": continue
		actionurl=fullpath(actionurl,pageinfo[2])

		print "ACTION:",actionurl

		# get the input variables
		poststring=""
		inputarr=sre.sub("(.*?)\<input([^\>]*)\>(.*?)","\\2|ZZaaXXaaZZ|",frmbody).split("|ZZaaXXaaZZ|")
		for j in range(len(inputarr)):

			name=getattrval(inputarr[j],"name")
			if name==inputarr[j] or name=="" or name=="\"\"": continue

			value=getattrval(inputarr[j],"value")
			if value==inputarr[j] or value=="" or value=="\"\"": value=""

			if poststring!="": poststring+="&"
			poststring+=name+"="+value

		# get select/option tags
		selectarr=sre.sub("(.*?)\<select([^\>]*)\>(.*?)","\\2|ZZaaXXaaZZ|",frmbody).split("|ZZaaXXaaZZ|")
		for j in range(len(selectarr)):

			name=getattrval(selectarr[j],"name")
			if name==selectarr[j] or name=="" or name=="\"\"": continue

			value=sre.sub("(.*?)\<option([^\>]*)value=(\"|'|)([^\\3\ ]*)\\3([^\>]*)\>(.*?)","\\2",selectarr[j])
			if value==selectarr[j] or value=="" or value=="\"\"": value=""

			if poststring!="": poststring+="&"
			poststring+=name+"="+value
			print "sel/opt: "+name+"="+value

		if poststring=="": continue

		if sre.search("method=([\'\"]|)post([\'\"]|)",frmsect[:frmsect.find(">")].lower())==None:
			if actionurl.find("?")!=-1: actionurl+="&"
			else: actionurl+="?"
			actionurl+=poststring
			body+='<a href="'+actionurl+'">'
			print 'GETT <a href="'+actionurl+'">'
			continue

		# determine if it needs to be scanned, and if so, scan it
		postscan=0
		postvars=poststring.split("&")
		if postfields.has_key(actionurl):
			for j in range(len(postvars)):
				postvars[j]=postvars[j][:postvars[j].find("=")]
				if postfields[actionurl].count(postvars[j])==0:
					postfields[actionurl].append(postvars[j])
					postscan=1
		else:
			for j in range(len(postvars)): postvars[j]=postvars[j][:postvars[j].find("=")]
			postfields[actionurl]=postvars
			postscan=1

		if postscan==1:
			vulns=checkvars(actionurl,poststring)
			if not listempty(vulns): dispvulns(vulns,actionurl)

	print "BB"

	# check for urls in "href" tags
	# ? # part of 3? (src|href|location|window.open)= and http://
	urlreg="(\'|\")(?!javascript:)(([^\>]+?)(?!\.("+ignorefileext.replace(",","|")+"))(.{3,8}?)(|\?([^\>]+?)))"
	urlarr=sre.sub("(?s)(?i)(.+?)((src|href)=|location([\ ]*)=([\ ]*)|window\.open\()"+urlreg+"\\6","\\7|ZZaaXXaaZZ|",body).split("|ZZaaXXaaZZ|")
	del urlarr[len(urlarr)-1]
	urlarr.append(sre.sub("(?s)(?i)(.+?)(src|href)="+urlreg+"\\3","\\4|ZZaaXXaaZZ|",body).split("|ZZaaXXaaZZ|"))
	del urlarr[len(urlarr)-1]
	for i in range(len(urlarr)):

		theurl=fullpath(urlarr[i],pageinfo[2])
		if not checkserver(servername(theurl)): continue

		# determine if it needs scanned and/or treed, and if so, scan and/or tree it
		getscan=0
		if theurl.count("?")!=0:
			nqurl=theurl[:theurl.find("?")]
			query=theurl[theurl.find("?")+1:]
			query=sre.sub("\&amp\;","\&",query)
			qryvars=query.split("&")
			if urlfields.has_key(nqurl):
				for j in range(len(qryvars)):
					qryvars[j]=qryvars[j][:qryvars[j].find("=")]
					if urlfields[nqurl].count(qryvars[j])==0:
						urlfields[nqurl].append(qryvars[j])
						getscan=1
			else:
				for j in range(len(qryvars)): qryvars[j]=qryvars[j][:qryvars[j].find("=")]
				urlfields[nqurl]=qryvars
				getscan=1
		else:
			if urlfields.has_key(theurl)==False: urlfields[theurl]=[]
			nqurl=theurl

		if getscan==1:
			vulns=checkvars(theurl)
			if not listempty(vulns): dispvulns(vulns,theurl)
		tree=treeglob
		if treedurls.has_key(nqurl):
			if treedurls[nqurl].count(theurl)==0 and len(treedurls[nqurl])<=scanlimit:
				treedurls[nqurl].append(theurl)
			else: tree=0

		else: treedurls[nqurl]=[theurl]
		if tree==1 and level<levels:
			realurl=getpage(theurl,realpage=1)
			if theurl!=realurl and realurl!=None:
				body+=' href="'+realurl+'" '
			print "treeee"
			try: treepages(theurl,level+1)
			except KeyboardInterrupt:
				treeglob=0
				print "TREEGLOB CHANGED TO ZERO"
				treepages(theurl,level+1)