def __loader_maker__(self, fields, name, delimiter='\\t'): builder = MutableString() builder += 'LOAD TABLE #{0} (\n'.format(name) builder += string.join([' {0:<32}'.format(aux.name) for aux in fields], '\'{0}\',\n'.format(delimiter)) + '\'\\x0d\\x0a\'\n' builder += ') FROM \'{{file}}\'\n' builder += 'ESCAPES OFF QUOTES OFF'; return builder.__str__()
def strip_whitespace_and_adjacent_duplicate_letter(text): """This is purely for the sake of the exercise because MutableString is deprecated in Python 3. The proper solution still needs to be in C/C++. >>> strip_whitespace_and_adjacent_duplicate_letter("abb cddpddef gh") 'abcdpdefgh' >>> strip_whitespace_and_adjacent_duplicate_letter("aaaadam mmmm") 'adam' """ mutable_text = MutableString(text) num_of_whitespace = mutable_text.count(' ') for i in xrange(0, num_of_whitespace): mutable_text.remove(' ') mutable_text_length = len(mutable_text) i = 0 while i < mutable_text_length - 1: if mutable_text[i] == mutable_text[i + 1]: del mutable_text[i + 1] mutable_text_length -= 1 i = 0 else: i += 1 return mutable_text
def __repr__(self): out_buffer=MutableString() for r in range(self.rows): for c in range(self.cols): out_buffer.append(self.__matrix[r][c]) out_buffer.append('\n') return str(out_buffer)
def testRepr(self): board=Board(10,12) ocean = '~' expected = MutableString() for _ in range(10): expected.append(ocean*12) expected.append('\n') self.assertEqual(expected, str(board))
def __table_maker__(self, fields, name): builder = MutableString() builder = 'CREATE TABLE #{0} (\n'.format(name) builder += string.join([' {0:<32} : {1}'.format(aux.name, self.get_type(aux)) for aux in fields], ',\n') builder += ');\n' builder += 'COMMIT;' return builder.__str__()
def toString (self): result = MutableString() result.append("Archaive type: %s" % self.myArchaiveType) result.append("Archaive errors allowed: %s" % self.myErrorsAllowed) result.append("Archaive consolidation span: %d" % self.myConsolidationSpan) result.append("Archaive rows to keep: %d" % self.myRowsToKeep) return result.data
def execute(cls, *args, **kwargs): if len(args) == 1 and args[0] == "long": temp = MutableString() for line in subprocess.check_output(["fortune", "-l"]).split("\n"): temp += str(line) temp += ' ' kwargs['client'].msg(kwargs['user'], temp) else: temp = MutableString() for line in subprocess.check_output("fortune").split("\n"): temp += str(line) temp += ' ' return temp
def load(durl, greet): def remove_tags(text): text = TAG_RE.sub('', text) text = re.sub("\n", "", text) text = re.sub("\"", "\\\"", text) return "".join(filter(lambda x: ord(x) < 128, text)) content = MutableString() content = [] opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/24.0')] MEMCACHE_GREETINGS = greet data = cache.get(MEMCACHE_GREETINGS) time = 1800 if data is None: file = urllib2.urlopen(durl) data = file.read() file.close() cache.add(MEMCACHE_GREETINGS, data, time) doc = ET.fromstring(data) # logging.debug("value of 16 my var is %s", str(data)) gg = doc.findall('channel/item') # logging.debug("value of 1 my var is %s", str(gg)) for node in gg: title = node.find('./title').text description = node.find('./description').text url = node.find('./link').text info = {} info['title'] = remove_tags(title) info['description'] = remove_tags(description) info['url'] = url # submitterobj = User.objects.get(username='******') # submitter = submitterobj.username info['submitter'] = User.objects.filter( username='******')[0].id info['linksource'] = urlparse(url).netloc # info['submitter'] = User.objects.filter(is_superuser=1)[1].id info['votes'] = randrange(20) logging.debug( "value of user my var is %s", str( User.objects.filter( username='******')[0].get_username())) # info[title] = Wikifetch(title, description, url) content.append(info) # logging.debug("value of 1 my var is %s", str(title)) # logging.debug("value of 2 my var is %s", str(link)) return content
def method2(): from UserString import MutableString out_str = MutableString() for num in xrange(loop_count): out_str += `num` ps_stats() return out_str
def reverse_version_mutable_string(string_input): new_str = MutableString() for i in range(len(string_input) - 1, -1, -1): # new_str = "%s%s" % (new_str, string_input[i]) new_str += string_input[i] return new_str
def trackGARequests(path, remoteAddr, referer=''): logging.debug('trackRSSRequests: calling GA GIF service') var_utmac = AppConfig.googleAnalyticsKey # enter the new urchin code var_utmhn = AppConfig.appDomain # enter your domain var_utmn = str(random.randint(1000000000, 9999999999)) # random request number var_cookie = str(random.randint(10000000, 99999999)) # random cookie number var_random = str(random.randint(1000000000, 2147483647)) # number under 2147483647 var_today = str(int(time.time())) # today var_referer = referer # referer url var_uservar = '-' # enter your own user defined variable var_utmp = '%s/%s' % (path, remoteAddr) # this example adds a fake page request to the (fake) rss directory (the viewer IP to check for absolute unique RSS readers) #build URL urchinUrl = MutableString() urchinUrl = 'http://www.google-analytics.com/__utm.gif?utmwv=1&utmn=' + var_utmn urchinUrl += '&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' urchinUrl += var_utmhn + '&utmr=' + var_referer + '&utmp=' + var_utmp urchinUrl += '&utmac=' + var_utmac + '&utmcc=__utma%3D' + var_cookie urchinUrl += '.' + var_random + '.' + var_today + '.' + var_today + '.' urchinUrl += var_today + '.2%3B%2B__utmb%3D' + var_cookie urchinUrl += '%3B%2B__utmc%3D' + var_cookie + '%3B%2B__utmz%3D' + var_cookie urchinUrl += '.' + var_today urchinUrl += '.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D' urchinUrl += var_cookie + '.' + var_uservar + '%3B' #async request to GA's GIF service rpcGA = None try: rpcGA = urlfetch.create_rpc() urlfetch.make_fetch_call(rpcGA, urchinUrl) except Exception, exT: logging.error('trackRSSRequests: Errors calling GA GIF service : %s' % exT)
def eliminarIndiceImpar(cadena): cad = MutableString(cadena) for i in range(len(cadena)): if i%2!=0: cad[i]='' return cad
def parseMessageFromBot(self, message, mesFrom): jid = mesFrom mesText = message.body.strip() if mesFrom.lower() == JUICK_BOT.lower() or mesFrom.lower( ) == PSTO_BOT.lower() or mesFrom.lower() != PSTO_ANOTHER_BOT.lower( ): # or mesFrom.lower() == BNW_BOT.lower() or mesFrom.lower() == NYA_BOT.lower() : # Send it to user. mesTo = message.to.split('/')[0] user = User.all().filter('local', mesTo.lower().lower()).get() if user is None: logging.debug("We've got unknown message: " + mesFrom + "->" + mesTo + ">" + mesText) else: from UserString import MutableString mesFooter = MutableString() mesFooter += "\nTo reply to this message, start your message with " if mesFrom.lower() == JUICK_BOT.lower(): mesFooter += "-j" else: mesFooter += "-p" mesFooter += " modificator.\nIf you fail to do so, your message will be sent to both juick and psto." status = xmpp.send_message( user.jid, (mesFrom + "> " + mesText + mesFooter).encode( 'utf-8', 'xmlcharrefreplace')) else: # Logging. logging.debug("We've got unknown message: " + mesFrom + "> " + mesText)
def __init__(self): # save the linetype self.tokentype = "CombinedText" # use MutableString for efficiency self._text = MutableString()
def toString(self): result = MutableString() result.append("Property name: %s" % self.myName) result.append("Property variable type: %s" % self.myVariableType) #Get the correct format according to the variable type frmt = "Property value: %s" % VariableTypes.FORMAT_BY_NAMES[ self.myVariableType] result.append(frmt % self.myValue) return result.data
def getNotes(fileUrl): note = MutableString() note += fileUrl logging.debug('note={0}'.format(note)) return str(note)
def solve(a): a = MutableString(a) ans = 0 while len(a) > 0: a = a.replace("{}","") if a and "{}" not in a: if a[0] == '}' and a[-1] == '{': ans += 2 a[0] = '{' a[-1] = '}' elif a[0] == '}': ans += 1 a[0] = '{' elif a[-1] == '{': ans += 1 a[-1] = '}' return ans
def as_string(self,show_hit=True,show_ship=True,show_miss=True): out_buffer = MutableString() for r in range(self.rows): for c in range(self.cols): coord = r, c if coord in self.hit and show_hit: result = Board.HIT elif coord in self.hidden_ships and show_ship: result = Board.SHIP elif coord in self.miss and show_miss: result = Board.MISS else: result = Board.OCEAN out_buffer.append(result) out_buffer.append('\n') return out_buffer
def run_02(): """# 방법2: MutableString 이용한 방법 - DEPRECATED : UserString은 더이상 지원않는 클래스 """ from UserString import MutableString out_str = MutableString() for num in range(10): out_str += 'num--' return out_str
def getText(self): # use MutableString for efficiency comedy_text = MutableString() for token in self.tokens: comedy_text += token.getText() return str(comedy_text)
def getText(self): # use MutableString for efficiency comedy_text = MutableString() for line in self.lines: comedy_text += line.getText() + ' ' return str(comedy_text)
def _getTags(self, results, file): tags = MutableString() # Digital Signature # isProbablyPacked try: if results["Info"] and results["Info"]["file"]: tags += results["Info"]["file"]["digitalSignature"] tags += ", " tags += "isProbablyPacked: " + str(results["Info"]["file"]["isProbablyPacked"]) tags += ", " except KeyError: # Key is not present pass # URL if results["Info"] and results["Info"]["url"]: tags += results["Info"]["url"]["hostname"] tags += ", " # Packer Ident if results.get("PEID", None): tags += results["PEID"][0] tags += ", " # VirusTotal try: if results["VirusTotal"] and results["VirusTotal"]["file"] and results["VirusTotal"]["file"]["positives"]: tags += "VirusTotal: " tags += results["VirusTotal"]["file"]["positives"] tags += "/" tags += results["VirusTotal"]["file"]["total"] tags += ", " except KeyError: # Key is not present pass # CountryCode try: if results["InetSourceAnalysis"] and results["InetSourceAnalysis"]["URLVoid"]: tags += results["InetSourceAnalysis"]["URLVoid"]["urlResult"][1]["CountryCode"] tags += ", " except KeyError: # Key is not present pass # FileType tags += file.get_type() tags += ", " tags += "ragpicker" #TODO: Unpacked Tag einfuegen!!! log.info("tags=" + tags) return str(tags)
def toString (self): result = MutableString() result.append("Property name: %s" % self.myName) result.append("Property variable type: %s" % self.myVariableType) #Get the correct format according to the variable type frmt = "Property value: %s" % VariableTypes.FORMAT_BY_NAMES[self.myVariableType] result.append(frmt % self.myValue) return result.data
def multiplyChar(char, n): retVal = MutableString() I = 0 if n == 0: return "" elif n < 0: return char for i in range(n): retVal += char return retVal
def formatCreateCommand (self, counter, rrdPath): cmd = "create %s --step %d" % (rrdPath, counter.mySamplingRate) #Format archaives string archaivesString = MutableString() for archaive in counter.myArchaives: archaivesString.append(" RRA:%s:%f:%d:%d" % (archaive.myArchaiveType, archaive.myErrorsAllowed,archaive.myConsolidationSpan,archaive.myRowsToKeep)) #Format DS cmd += " DS:%d:%s:%d:%s:%s %s" % \ (counter.myCounterId, counter.myCounterType, counter.myMinHeartbeat, counter.getMinStr(), counter.getMaxStr(), archaivesString.data) return cmd
def load(durl, greet): def remove_tags(text): text = TAG_RE.sub('', text) text = re.sub("\n", "", text) text = re.sub("\"", "\\\"", text) return "" . join(filter(lambda x: ord(x)<128, text)) content = MutableString() content = [] opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/24.0')] MEMCACHE_GREETINGS = greet data = cache.get(MEMCACHE_GREETINGS) time = 1800 if data is None: file = urllib2.urlopen(durl) data = file.read() file.close() cache.add(MEMCACHE_GREETINGS, data, time) doc = ET.fromstring(data) # logging.debug("value of 16 my var is %s", str(data)) gg = doc.findall('channel/item') # logging.debug("value of 1 my var is %s", str(gg)) for node in gg: title = node.find('./title').text description = node.find('./description').text url = node.find('./link').text info = {} info['title'] = remove_tags(title) info['description'] = remove_tags(description) info['url'] = url # submitterobj = User.objects.get(username='******') # submitter = submitterobj.username info['submitter'] = User.objects.filter(username='******')[0].id info['linksource'] = urlparse(url).netloc # info['submitter'] = User.objects.filter(is_superuser=1)[1].id info['votes'] = randrange(20) logging.debug("value of user my var is %s", str(User.objects.filter(username='******')[0].get_username())) # info[title] = Wikifetch(title, description, url) content.append(info) # logging.debug("value of 1 my var is %s", str(title)) # logging.debug("value of 2 my var is %s", str(link)) return content
def parseParameters(self, vardict): # use MutableString for efficiency parameters = MutableString() # build a string with html tags: <key>value</key> for key, value in vardict.items(): parameters += "\n <%s>%s</%s>" % (key, value, key) return str(parameters)
def load(durl, greet): def remove_tags(text): text = TAG_RE.sub('', text) text = re.sub("\n", "", text) text = re.sub("\"", "\\\"", text) text = re.sub(u"(\u2018|\u2019)", "'", text) return "".join(filter(lambda x: ord(x) < 128, text)) content = MutableString() content = [] def entry_to_link_dict(entry): s = MLStripper() s.feed(entry.description) link = { "title": remove_tags(entry.title), "url": entry.link, "linksource": urlparse(entry.link).netloc, "votes": "1", "description": remove_tags(s.get_data()), } return link try: user_id = User.objects.filter(username='******')[0].id except IndexError: return for entry in parse(durl).entries: link = entry_to_link_dict(entry) link["submitter"] = user_id info = link logging.debug( "value of user my var is %s", str( User.objects.filter( username='******')[0].get_username())) # info[title] = Wikifetch(title, description, url) content.append(info) # logging.debug("value of 1 my var is %s", str(title)) # logging.debug("value of 2 my var is %s", str(link)) return content
def test_parse_format_changed(self): from UserString import MutableString header = MutableString('lo') format = [('field', 2)] test_parser = make_packet_parser(header, format) self.do_parse_test(test_parser, ['lo\x00\x00'], [{'field': '\x00\x00'}], ['6C6F 0000'], ) format += [('field2', 2)] header.append('l') self.do_parse_test(test_parser, ['lo\x00\x00'], [{'field': '\x00\x00'}], ['6C6F 0000'], )
def getTags(fileUrl): tags = MutableString() tags += time.strftime(baseConfig.dateFormat) tags += ', ' tags += urlparse(fileUrl).hostname tags += ', ' tags += 'ph0neutria' logging.debug('tags={0}'.format(tags)) return str(tags)
def decimal_to_number(cls, number, base): converted_num = MutableString() is_neg = number < 0 number = abs(number) while number > 0: digit = number % base converted_num = cls.number_to_alphabet_map.get( digit, str(digit)) + converted_num number /= base if not converted_num: return "0" return ("-" if is_neg else "") + converted_num
def getText(self): # use MutableString for efficiency comedy_text = MutableString() # check if the reset tag is needed tagAdded = False # get the values speed = self.speed shape = self.shape volume = self.volume voice = self.voice # if it is a punch line # set the punch line defauls but not override if self.punch: if speed is None: speed = punch_default_speed if shape is None: shape = punch_default_shape if volume is None: volume = punch_default_volume # check for voice tags (if not None or default) if speed and speed != 100: comedy_text += '\\rspd=' + str(speed) + '\\' tagAdded = True if shape and shape != 100: comedy_text += '\\vct=' + str(shape) + '\\' tagAdded = True if volume and volume != 100: comedy_text += '\\vol=' + str(volume) + '\\' tagAdded = True if voice: comedy_text += '\\vce=speaker=' + voice + '\\' tagAdded = True # add the text comedy_text += self.text # add the reset at the end if tagAdded: comedy_text += '\\rst\\' return str(comedy_text)
class WikiCorpus: '''Class construct that takes a filehandler as argument. This must have been initialized: filehandler = open(filename) where filename is the name of the text file storing the corpus. labeled should be True if the corpus we are reading contains the topic labels of the articles.''' def __init__(self, filehandler, labeled=False): self.filehandler = filehandler self.labeled = labeled ## Cursor position currentTitle = "" currentCategory = "" currentText = MutableString() def __iter__(self): while True: nextLine = next(self.filehandler, None) if nextLine == None or nextLine == '\n': if self.currentTitle != '': if self.labeled: yield Document(str(self.currentTitle), str(self.currentText), str(self.currentCategory)) else: yield Document(str(self.currentTitle), str(self.currentText)) if nextLine == None: break else: self.currentTitle = "" self.currentCategory = "" self.currentText = MutableString() elif len(self.currentTitle) == 0: self.currentTitle = nextLine.strip('\n') elif self.labeled and len(self.currentCategory) == 0: self.currentCategory = nextLine.strip('\n') else: self.currentText.append(nextLine)
def formatCreateCommand(self, counter, rrdPath): cmd = "create %s --step %d" % (rrdPath, counter.mySamplingRate) #Format archaives string archaivesString = MutableString() for archaive in counter.myArchaives: archaivesString.append( " RRA:%s:%f:%d:%d" % (archaive.myArchaiveType, archaive.myErrorsAllowed, archaive.myConsolidationSpan, archaive.myRowsToKeep)) #Format DS cmd += " DS:%d:%s:%d:%s:%s %s" % \ (counter.myCounterId, counter.myCounterType, counter.myMinHeartbeat, counter.getMinStr(), counter.getMaxStr(), archaivesString.data) return cmd
def main(): b1 = 26 if len(sys.argv) == 2: pattern_to_decode = sys.argv[1] else: number_len = random.randint(1, 6) pattern_to_decode = MutableString() for _ in range(number_len): digit = random.randint(0, 26) pattern_to_decode += SpreadsheetEncodingDecoder.number_to_alphabet_map.get( digit, str(digit)) decoded_pattern = SpreadsheetEncodingDecoder.number_to_decimal( str(pattern_to_decode), b1) print('n = %s decoded n = %s' % (pattern_to_decode, decoded_pattern))
class WikiCorpus : '''Class construct that takes a filehandler as argument. This must have been initialized: filehandler = open(filename) where filename is the name of the text file storing the corpus. labeled should be True if the corpus we are reading contains the topic labels of the articles.''' def __init__(self, filehandler, labeled = False) : self.filehandler = filehandler self.labeled = labeled ## Cursor position currentTitle = "" currentCategory = "" currentText = MutableString() def __iter__(self) : while True : nextLine = next(self.filehandler, None) if nextLine == None or nextLine == '\n' : if self.currentTitle != '' : if self.labeled : yield Document(str(self.currentTitle), str(self.currentText), str(self.currentCategory)) else : yield Document(str(self.currentTitle), str(self.currentText)) if nextLine == None : break else : self.currentTitle = "" self.currentCategory = "" self.currentText = MutableString() elif len(self.currentTitle) == 0 : self.currentTitle = nextLine.strip('\n') elif self.labeled and len(self.currentCategory) == 0 : self.currentCategory = nextLine.strip('\n') else : self.currentText.append(nextLine)
def load(durl, greet): def remove_tags(text): text = TAG_RE.sub('', text) text = re.sub("\n", "", text) text = re.sub("\"", "\\\"", text) text = re.sub(u"(\u2018|\u2019)", "'", text) return "" . join(filter(lambda x: ord(x)<128, text)) content = MutableString() content = [] def entry_to_link_dict(entry): s = MLStripper() s.feed(entry.description) link = { "title": remove_tags(entry.title), "url": entry.link, "linksource": urlparse(entry.link).netloc, "votes": "1", "description": remove_tags(s.get_data()), } return link try: user_id = User.objects.filter(username='******')[0].id except IndexError: return for entry in parse(durl).entries: link = entry_to_link_dict(entry) link["submitter"] = user_id info = link logging.debug("value of user my var is %s", str(User.objects.filter(username='******')[0].get_username())) # info[title] = Wikifetch(title, description, url) content.append(info) # logging.debug("value of 1 my var is %s", str(title)) # logging.debug("value of 2 my var is %s", str(link)) return content
def getParagraphCommentSiblings(node): nodeText = MutableString() if (node): #get first paragraph nodeText = str(node.font) nextSib = node.nextSibling if (nextSib and "<p>" in str(nextSib)): while (nextSib and "<p>" in str(nextSib)): tmpStr = str(nextSib) if (nodeText): nodeText += "__BR__%s" % tmpStr else: nodeText = tmpStr nextSib = nextSib.nextSibling return nodeText
def __iter__(self): while True: nextLine = next(self.filehandler, None) if nextLine == None or nextLine == '\n': if self.currentTitle != '': if self.labeled: yield Document(str(self.currentTitle), str(self.currentText), str(self.currentCategory)) else: yield Document(str(self.currentTitle), str(self.currentText)) if nextLine == None: break else: self.currentTitle = "" self.currentCategory = "" self.currentText = MutableString() elif len(self.currentTitle) == 0: self.currentTitle = nextLine.strip('\n') elif self.labeled and len(self.currentCategory) == 0: self.currentCategory = nextLine.strip('\n') else: self.currentText.append(nextLine)
def check_for_urls_in_files(app, reporter): """Check that URLs do not include redirect or requests from external web sites. """ # It's a little verbose but with the explicit-ness comes # References # http://tools.ietf.org/html/rfc3986 # http://stackoverflow.com/questions/4669692/valid-characters-for-directory-part-of-a-url-for-short-links url_regex_pattern = ("(\w*://)+" # Captures protocol "([\w\d\-]+\.[\w\d\-\.]+)+" # Captures hostname "(:\d*)?" # Captures port "(\/[^\s\?]*)?" # Captures path "(\?[^\s]*)?") # Capture query string url_regex_object = re.compile(url_regex_pattern, re.IGNORECASE) excluded_types = [".csv", ".gif", ".jpeg", ".jpg", ".md", ".org", ".pdf", ".png", ".svg", ".txt"] excluded_directories = ["samples"] url_matches = app.search_for_pattern(url_regex_pattern, excluded_dirs=excluded_directories, excluded_types=excluded_types) if url_matches: # {url_pattern: {filename: [lineno_list]}} result_dict = {} for (fileref_output, match) in url_matches: url_match = match.group() filename, line_number = fileref_output.rsplit(":", 1) if url_match not in result_dict: result_dict[url_match] = {} if filename not in result_dict[url_match]: result_dict[url_match][filename] = [] result_dict[url_match][filename].append(str(line_number)) reporter_output = ("A file was detected that contains that a url." " Match: {}" " File: {}" " Line: {}" ).format(url_match, filename, line_number) reporter.manual_check(reporter_output, filename, line_number) # create some extra manual checks in order to see results in a more convenient way for (url_match, file_dict) in result_dict.items(): reporter_output = MutableString() reporter_output.append("A url {} was detected in the following files".format(url_match)) for (file_name, lineno_list) in file_dict.items(): reporter_output.append(", (File: {}, Linenolist: [{}])".format(file_name, ', '.join(lineno_list))) # don't need filename and line_number here, since it is an aggregated result reporter.manual_check(str(reporter_output))
def getText(self): # use MutableString for efficiency comedy_text = MutableString() # intro comedy_text += self.comedy_intro.getText() # sequence for item in self.comedy_joke_sequence: comedy_text += item.getText() # outro comedy_text += self.comedy_outro.getText() return str(comedy_text)
def __processConfigurationMonitor(self, words): #print "entered __processConfigurationMonitor" result = MutableString() result += '\t\t' result += '\n\t\t' #if words[1] == '0' if len(words[4]) == 0: result += CONSTANT_CONFIGURATION_MONITOR_HEADER + CONSTANT_NEWLINE + '\t\t\t' + \ CONSTANT_MONTITOR_METADATA_EMPTY + CONSTANT_NEWLINE + '\t\t' + \ CONSTANT_CONFIGURATION_MONITOR_FOOTER else: omittedMonitorFlag = CONSTANT_FALSE_STR if words[0].strip() in self.__omittedMonitors: omittedMonitorFlag = CONSTANT_TRUE_STR imageFile = "" if words[4].strip() == "scti_FlashFlood.xbm": imageFile = CONSTANT_FLASH_FLOOD elif words[4].strip() == "FOGbutton.xbm": imageFile = CONSTANT_FOG elif words[4].strip() == "SSbutton.xbm": imageFile = CONSTANT_SAFE_SEAS elif words[4].strip() == "SNOWbutton.xbm": imageFile = CONSTANT_SNOW elif words[4].strip() == "SCANbutton.xbm": imageFile = CONSTANT_SCAN #elif words[4].strip() == "scti_SPCguidance.xbm": #imageFile = result_0 = CONSTANT_CONFIGURATION_MONITOR_HEADER + CONSTANT_NEWLINE result_1 = '\t\t\t' + \ CONSTANT_MONTITOR_METADATA % {"image_file": imageFile, \ "omitted_flag": omittedMonitorFlag, "tcl_script": words[2].strip(), \ "interval": words[3].strip()} + CONSTANT_NEWLINE # result_2 = '\t\t' + CONSTANT_CONFIGURATION_MONITOR_FOOTER result += result_0 + result_1 + result_2 result += CONSTANT_NEWLINE #print "exiting __processConfigurationMonitor" return result
def get(self, format='json'): #set content-type self.response.headers['Content-Type'] = Formatter.contentType(format) returnData = MutableString() returnData = APIContent.getHackerNewsRSS(format) referer = '' if ('HTTP_REFERER' in os.environ): referer = os.environ['HTTP_REFERER'] #track this request GAHelper.trackGARequests('/rss', self.request.remote_addr, referer) #output to the browser self.response.out.write( Formatter.dataWrapper(format, returnData, self.request.get('callback')))
def main(): if len(sys.argv) == 4: number_to_convert = sys.argv[1] b1 = int(sys.argv[2]) b2 = int(sys.argv[3]) else: number_len = random.randint(1, 16) b1 = random.randint(1, 15) b2 = random.randint(1, 15) number_to_convert = MutableString() for _ in range(number_len): digit = random.randint(0, b1 - 1) number_to_convert += BaseConverter.number_to_alphabet_map.get( digit, str(digit)) converted_number = BaseConverter.decimal_to_number( BaseConverter.number_to_decimal(str(number_to_convert), b1), b2) print('n = %s, base = %d converted n = %s, base - %d' % (number_to_convert, b1, converted_number, b2))
def __iter__(self) : while True : nextLine = next(self.filehandler, None) if nextLine == None or nextLine == '\n' : if self.currentTitle != '' : if self.labeled : yield Document(str(self.currentTitle), str(self.currentText), str(self.currentCategory)) else : yield Document(str(self.currentTitle), str(self.currentText)) if nextLine == None : break else : self.currentTitle = "" self.currentCategory = "" self.currentText = MutableString() elif len(self.currentTitle) == 0 : self.currentTitle = nextLine.strip('\n') elif self.labeled and len(self.currentCategory) == 0 : self.currentCategory = nextLine.strip('\n') else : self.currentText.append(nextLine)
def pretty_print_CNF(input_string): """ SymPy returns the CNF information in a form that is more line with its implementation that what is easily readable Modify the string to make it more readable in text. :returns: Converted CNF string. """ output_str = MutableString() input_string_mutable = MutableString(input_string) # Remove nots and white space. input_string_mutable = input_string_mutable.replace("Not", "!") input_string_mutable = input_string_mutable.replace(" ", "") # Remove outer "And" input_string_mutable = input_string_mutable.replace("And(", "") # Remove trailing parenthesis input_string_mutable = input_string_mutable[: len(input_string_mutable) - 1] # Split based off OR all_clauses = input_string_mutable.split("),Or(") for clause in all_clauses: # Remove any preceding ors clause = clause.replace("Or(", "") # Remove any trailing parenthesis if clause[len(clause) - 1] == ")": clause = clause[: len(clause) - 1] clause = clause.replace(",", "+") clause = clause.replace("(", "") clause = clause.replace(")", "") # Build output string. if len(output_str) == 0: output_str += "(" + clause + ")" else: output_str += "&(" + clause + ")" # Replace period with commas output_str = output_str.replace(".", ",") return str(output_str)
def __repr__(self): outstr = MutableString("") for r in self.__matrix: outstr.append("".join(r)+"\n") return str(outstr)
def toString (self): result = MutableString() result.append("Process name: %s " % self.myCounterProcess) result.append("Counter path: %s " % self.myCounterPath) result.append("Counter name: %s " % self.myCounterName) result.append("Counter name: %s " % self.myCounterSamplingName) result.append("Sampling rate: %s " % self.mySamplingRate) result.append("Counter Type: %s " % self.myCounterType) result.append("Counter Units: %s " % self.myMeasuredUnits) result.append("Counter present per second is: %s " % str(self.myPresentCounterPerSecond)) result.append("Counter Id: %d " % self.myCounterId) result.append("Is rate? %s" % str(self.myIsRate)) result.append("Counter short description: %s " % self.myCounterShortDescriptionString) result.append("Counter short description override flag: %s " % str(self.myCounterDescriptionIsOverride)) result.append("Counter value variable type: %s " % self.myVariableType) result.append("Meta-Counter arithmetic expression: %s " % self.myMetaCounterExpression) result.append("Communication method: %s " % self.myCommMethod) result.append("RRD min heartbeat: %s " % self.myMinHeartbeat) for arch in self.myArchaives: result.append(arch.toString()) for prop in self.myProperties: result.append(prop.toString()) return result.data
def print_board(self): raw_string = self.as_string(show_ship=False) str_buf_1 = MutableString() str_buf_2 = MutableString() str_buf_1.append(" ") str_buf_2.append(" ") for i in range(self.cols): if i%10!=0 or i<10: str_buf_1.append(' ') else: str_buf_1.append("%d"%(i/10)) str_buf_2.append(str(i%10)) print str_buf_1 print str_buf_2 row_num=0 for row in raw_string.splitlines(): if len(row)>0: print "%2d %s" %(row_num,row) row_num+=1