当前位置: 首页>>代码示例>>Python>>正文


Python mytime.MyTime类代码示例

本文整理汇总了Python中mytime.MyTime的典型用法代码示例。如果您正苦于以下问题:Python MyTime类的具体用法?Python MyTime怎么用?Python MyTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MyTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getDate

	def getDate(self, line):
		date = None
		dateMatch = self.matchDate(line)
		if dateMatch:
			try:
				# Try first with 'C' locale
				date = list(time.strptime(dateMatch.group(), self.getPattern()))
			except ValueError:
				# Try to convert date string to 'C' locale
				conv = self.convertLocale(dateMatch.group())
				try:
					date = list(time.strptime(conv, self.getPattern()))
				except ValueError, e:
					# Try to add the current year to the pattern. Should fix
					# the "Feb 29" issue.
					conv += " %s" % MyTime.gmtime()[0]
					pattern = "%s %%Y" % self.getPattern()
					date = list(time.strptime(conv, pattern))
			if date[0] < 2000:
				# There is probably no year field in the logs
				date[0] = MyTime.gmtime()[0]
				# Bug fix for #1241756
				# If the date is greater than the current time, we suppose
				# that the log is not from this year but from the year before
				if time.mktime(date) > MyTime.time():
					date[0] -= 1
				elif date[1] == 1 and date[2] == 1:
					# If it is Jan 1st, it is either really Jan 1st or there
					# is neither month nor day in the log.
					date[1] = MyTime.gmtime()[1]
					date[2] = MyTime.gmtime()[2]
开发者ID:jamesstout,项目名称:fail2ban-0.8.4-OpenSolaris,代码行数:31,代码来源:datetemplate.py

示例2: addBannedIP

    def addBannedIP(self, ip):
        unixTime = MyTime.time()
        for i in xrange(self.failManager.getMaxRetry()):
            self.failManager.addFailure(FailTicket(ip, unixTime))

            # Perform the banning of the IP now.
        try:  # pragma: no branch - exception is the only way out
            while True:
                ticket = self.failManager.toBan()
                self.jail.putFailTicket(ticket)
        except FailManagerEmpty:
            self.failManager.cleanup(MyTime.time())

        return ip
开发者ID:hazg,项目名称:fail2ban,代码行数:14,代码来源:filter.py

示例3: processLineAndAdd

	def processLineAndAdd(self, line):
		for element in self.processLine(line):
			ip = element[0]
			unixTime = element[1]
			logSys.debug("Processing line with time:%s and ip:%s"
						 % (unixTime, ip))
			if unixTime < MyTime.time() - self.getFindTime():
				logSys.debug("Ignore line since time %s < %s - %s"
							 % (unixTime, MyTime.time(), self.getFindTime()))
				break
			if self.inIgnoreIPList(ip):
				logSys.debug("Ignore %s" % ip)
				continue
			logSys.debug("Found %s" % ip)
			self.failManager.addFailure(FailTicket(ip, unixTime))
开发者ID:Lovestick,项目名称:fail2ban,代码行数:15,代码来源:filter.py

示例4: getDate

	def getDate(self, line):
		date = None
		dateMatch = self.matchDate(line)
		if dateMatch:
			# extract part of format which represents seconds since epoch
			date = list(MyTime.localtime(float(dateMatch.group())))
		return date
开发者ID:Glandos,项目名称:fail2ban,代码行数:7,代码来源:datetemplate.py

示例5: run

	def run(self):
		self.setActive(True)
		while self._isActive():
			if not self.getIdle():
				# We cannot block here because we want to be able to
				# exit.
				if self.monitor.event_pending():
					self.monitor.handle_events()

				if self.__modified:
					try:
						while True:
							ticket = self.failManager.toBan()
							self.jail.putFailTicket(ticket)
					except FailManagerEmpty:
						self.failManager.cleanup(MyTime.time())
					self.dateDetector.sortTemplate()
					self.__modified = False
				time.sleep(self.getSleepTime())
			else:
				time.sleep(self.getSleepTime())
		# Cleanup Gamin
		self.__cleanup()
		logSys.debug(self.jail.getName() + ": filter terminated")
		return True
开发者ID:JohnyByk,项目名称:fail2ban,代码行数:25,代码来源:filtergamin.py

示例6: createBanTicket

 def createBanTicket(ticket):
     ip = ticket.getIP()
     # lastTime = ticket.getTime()
     lastTime = MyTime.time()
     banTicket = BanTicket(ip, lastTime, ticket.getMatches())
     banTicket.setAttempt(ticket.getAttempt())
     return banTicket
开发者ID:engeset,项目名称:fail2ban,代码行数:7,代码来源:banmanager.py

示例7: run

	def run(self):
		self.setActive(True)
		while self._isActive():
			if not self.getIdle():
				# Get file modification
				for container in self.getLogPath():
					filename = container.getFileName()
					if self.isModified(filename):
						self.getFailures(filename)
						self.__modified = True

				if self.__modified:
					try:
						while True:
							ticket = self.failManager.toBan()
							self.jail.putFailTicket(ticket)
					except FailManagerEmpty:
						self.failManager.cleanup(MyTime.time())
					self.dateDetector.sortTemplate()
					self.__modified = False
				time.sleep(self.getSleepTime())
			else:
				time.sleep(self.getSleepTime())
		logSys.debug((self.jail and self.jail.getName() or "jailless") +
					 " filter terminated")
		return True
开发者ID:Glandos,项目名称:fail2ban,代码行数:26,代码来源:filterpoll.py

示例8: addBannedIP

	def addBannedIP(self, ip):
		if self.inIgnoreIPList(ip):
			logSys.warning('Requested to manually ban an ignored IP %s. User knows best. Proceeding to ban it.' % ip)

		unixTime = MyTime.time()
		for i in xrange(self.failManager.getMaxRetry()):
			self.failManager.addFailure(FailTicket(ip, unixTime))

		# Perform the banning of the IP now.
		try: # pragma: no branch - exception is the only way out
			while True:
				ticket = self.failManager.toBan()
				self.jail.putFailTicket(ticket)
		except FailManagerEmpty:
			self.failManager.cleanup(MyTime.time())

		return ip
开发者ID:Ricky-Wilson,项目名称:fail2ban,代码行数:17,代码来源:filter.py

示例9: processLineAndAdd

    def processLineAndAdd(self, line):
        """Processes the line for failures and populates failManager
		"""
        for element in self.processLine(line)[1]:
            failregex = element[0]
            ip = element[1]
            unixTime = element[2]
            logSys.debug("Processing line with time:%s and ip:%s" % (unixTime, ip))
            if unixTime < MyTime.time() - self.getFindTime():
                logSys.debug("Ignore line since time %s < %s - %s" % (unixTime, MyTime.time(), self.getFindTime()))
                break
            if self.inIgnoreIPList(ip):
                logSys.debug("Ignore %s" % ip)
                continue
            logSys.debug("Found %s" % ip)
            ## print "D: Adding a ticket for %s" % ((ip, unixTime, [line]),)
            self.failManager.addFailure(FailTicket(ip, unixTime, [line]))
开发者ID:hazg,项目名称:fail2ban,代码行数:17,代码来源:filter.py

示例10: callback

	def callback(self, path):
		self.getFailures(path)
		try:
			while True:
				ticket = self.failManager.toBan()
				self.jail.putFailTicket(ticket)
		except FailManagerEmpty:
			self.failManager.cleanup(MyTime.time())
		self.dateDetector.sortTemplate()
		self.__modified = False
开发者ID:Th4nat0s,项目名称:fail2ban,代码行数:10,代码来源:filterpyinotify.py

示例11: storeAllMenus

    def storeAllMenus(tot_days):
        db.delete(db.GqlQuery("SELECT * FROM MenuDatabase"))
        successCode = "Updated: \n"
        for dh in UrlRepo.dhs:
            #2 = Today and tmrw
            for i in range(tot_days):
                d = MyTime.getTheTimeNowPlus(i)
                menu = MyMenuParser.getMenuFor(dh, d)
                successCode += MenuStorage.store(dh, menu, d)
                successCode += UrlRepo.getUrl(dh, d) + "\n"

        return successCode[:-2] #[:-2] removes the last ", "
开发者ID:Pancia,项目名称:slug-menu-server,代码行数:12,代码来源:storemenu.py

示例12: getTime

	def getTime(self, line):
		try:
			# Try first with 'C' locale
			date = list(time.strptime(line, self.getPattern()))
		except ValueError:
			# Try to convert date string to 'C' locale
			conv = self.convertLocale(line)
			try:
				date = list(time.strptime(conv, self.getPattern()))
			except ValueError:
				# Try to add the current year to the pattern. Should fix
				# the "Feb 29" issue.
				conv += " %s" % MyTime.gmtime()[0]
				pattern = "%s %%Y" % self.getPattern()
				date = list(time.strptime(conv, pattern))
		if date[0] < 2000:
			# There is probably no year field in the logs
			date[0] = MyTime.gmtime()[0]
			# Bug fix for #1241756
			# If the date is greater than the current time, we suppose
			# that the log is not from this year but from the year before
			if time.mktime(date) > MyTime.time():
				date[0] -= 1
		return date
开发者ID:aspiers,项目名称:Fail2Ban,代码行数:24,代码来源:timetemplate.py

示例13: _process_file

	def _process_file(self, path):
		"""Process a given file

		TODO -- RF:
		this is a common logic and must be shared/provided by FileFilter
		"""
		self.getFailures(path)
		try:
			while True:
				ticket = self.failManager.toBan()
				self.jail.putFailTicket(ticket)
		except FailManagerEmpty:
			self.failManager.cleanup(MyTime.time())
		self.dateDetector.sortTemplate()
		self.__modified = False
开发者ID:bfx,项目名称:fail2ban,代码行数:15,代码来源:filterpyinotify.py

示例14: processLineAndAdd

 def processLineAndAdd(self, line):
     try:
         # Decode line to UTF-8
         l = line.decode("utf-8")
     except UnicodeDecodeError:
         l = line
     for element in self.findFailure(l):
         ip = element[0]
         unixTime = element[1]
         if unixTime < MyTime.time() - self.getFindTime():
             break
         if self.inIgnoreIPList(ip):
             logSys.debug("Ignore %s" % ip)
             continue
         logSys.debug("Found %s" % ip)
         self.failManager.addFailure(FailTicket(ip, unixTime))
开发者ID:aspiers,项目名称:Fail2Ban,代码行数:16,代码来源:filter.py

示例15: getMenu

    def getMenu(self):
        dh = self.request.get("dh")
        self.response.headers["Content-Type"] = "application/json"

        if self.request.get('time') == "true":
            self.response.out.write(datetime.now())
            self.response.out.write("\n")
            self.response.out.write(MyTime.getTheTimeNow())
            self.response.out.write("\n")

        #"Hack" to allow first-time storage of menus, 
        #where necessary url-command is: slugmenu.appspot.com/getmenu.py?exe=storeAllMenus[&num_to_store=#]
        if self.request.get('exe') == "storeAllMenus":
            num_dh = 8;
            if self.request.get('num_to_store') != "":
                num_dh = self.request.get('num_to_store')
            self.response.out.write( MenuStorage.storeAllMenus(num_dh) )
            return

        if dh == "":
            self.response.out.write( 
                json.dumps(
                    {"request":{"success":0}, 
                    "response":{"message":"Error! Null Dining Hall!"}
                    }
                )
            )
            return

        if dh not in UrlRepo.dhs:
            self.response.out.write( 
                json.dumps(
                    {"request":{"success":0}, 
                    "response":{"message":"Invalid Dining Hall: "+dh}
                    }
                )
            )
            return

        #For testing!
        
        if self.request.get('debug') == "url":
            self.response.out.write("#URL")
            self.response.out.write("\n")
            self.response.out.write(UrlRepo.getUrl(dh, MyTime.getTheTimeNow()))
            self.response.out.write("\n")

        if self.request.get('debug') == "simple":
            self.response.out.write("#MENU")
            self.response.out.write("\n")
            self.response.out.write(UrlRepo.getUrl(dh, MyTime.getTheTimeNow()))
            self.response.out.write("\n")
            self.response.out.write(
                json.dumps(
                    MyMenuParser.getMenuFor(dh, MyTime.getTheTimeNow())
                    , indent = 4, sort_keys = True
                ))
            self.response.out.write("\n")

        if self.request.get('debug') == "verbose":
            self.response.out.write("#HTML")
            self.response.out.write("\n")
            html = MyMenuParser.getHtmlFrom( UrlRepo.getUrl(dh, MyTime.getTheTimeNow()) )
            self.response.out.write(html)
            self.response.out.write("\n")

        dtdate = 0
        if self.request.get('dtdate') != '':
                dtdate = int(self.request.get('dtdate'))
                if dtdate > 7:
                    self.response.out.write(
                        json.dumps(
                            {"request":{"success":0}, 
                            "response":{"message":"Cannot get more than 1 week ahead!"}
                            }
                        )
                    )
                    return
        
        q = db.GqlQuery(
            "SELECT * FROM MenuDatabase " +
            "WHERE dh=:1 AND time=:2",
                dh, MyTime.getTheTimeNowPlus(dtdate))

        json_str = ''
        for i in q:
            json_str += i.menu

        try:
            self.response.out.write( 
                json.dumps(
                    json.loads(json_str), indent=4, sort_keys=True
                )
            )
        except ValueError as ve:
            self.response.out.write( 
                json.dumps(
                    {"request":{"success":0}, 
                    "response":{"message":ve.args[0]}
                    }
#.........这里部分代码省略.........
开发者ID:Pancia,项目名称:slug-menu-server,代码行数:101,代码来源:getmenu.py


注:本文中的mytime.MyTime类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。