def __init__(self): ''' Constructor ''' s = TreeSet() s.add( 'hello' ) s.add( 'world' ) print s
def __init__(self): ''' Constructor ''' s = TreeSet() s.add('hello') s.add('world') print s
class BaseWmiQueryBuilder: """ This is a base class for all QueryBuilders. QueryBuilder is a class which provides single interface to compose WMI query regardless to the underlying protocol """ def __init__(self, objectName): "@param objectName: the name of the queried CIM class" self.queryElements = TreeSet(ColumnNameBasedComparator()) self.objectName = objectName self.whereClause = None def addQueryElement(self, columnName, attributeName=None, elementType='string'): """ @deprecated: This method should not be used by clients @see: addWmiObjectProperties method instead """ if not attributeName: attributeName = columnName queryElement = QueryElement(columnName, attributeName, elementType) self.queryElements.add(queryElement) def addWmiObjectProperties(self, *columnNames): """ @types: *str -> BaseWmiQueryBuilder @param columnNames: the list of the names of the queried properties, order of properties if not important. """ for columnName in columnNames: self.addQueryElement(columnName) return self def addWhereClause(self, whereClause): """ This method allows to add 'WHERE' clause to the WMI query @types: str -> None """ self.whereClause = whereClause def buildQuery(self): """ Abstract method for query buidling """ raise NotImplemented("buildQuery") def parseResults(self, resultSet): """ Abstract method for results parsing """ raise NotImplemented("parseResults") def getObjectName(self): """ Returns queried CIM class name """ return self.objectName def usePathCommand(self, value): logger.warn("path command supported only for wmic query builder")
def __init__(self, path, src, runs): self.tags = TreeSet() self.buffer_ = [] self.sourceOffset = 0 self.source = src for run in runs: self.tags.add(StyleApplier.StartTag(run, self)) self.tags.add(StyleApplier.EndTag(run, self))
def testJava(): print "Hello world!" foo = TreeSet() hello = 'hello' foo.add(hello) foo.add("world") print foo print CompareUtils.compare(3, 4) print "Goodbye world!" print "sys.path = " + str(sys.path)
def parseMappingString(mappingString): bitPositions = TreeSet() bytesNumber = len(mappingString) / SYMBOLS_PER_BYTE for i in range(bytesNumber): currentPosition = i * SYMBOLS_PER_BYTE currentByteString = mappingString[currentPosition : currentPosition + SYMBOLS_PER_BYTE] currentByte = Integer.parseInt(currentByteString, 16) for j in range(BITS_IN_SYMBOL): if (currentByte & 1) == 1: bitPositions.add(i * BITS_IN_SYMBOL + BITS_IN_SYMBOL - j) currentByte = currentByte >> 1 return list(ArrayList(bitPositions))
def parseMappingString(mappingString): bitPositions = TreeSet(); bytesNumber = len(mappingString) / SYMBOLS_PER_BYTE; for i in range(bytesNumber): currentPosition = i * SYMBOLS_PER_BYTE; currentByteString = mappingString[currentPosition : currentPosition + SYMBOLS_PER_BYTE]; currentByte = Integer.parseInt(currentByteString, 16); for j in range(BITS_IN_SYMBOL): if (currentByte & 1) == 1: bitPositions.add(i*BITS_IN_SYMBOL + BITS_IN_SYMBOL - j); currentByte = currentByte >> 1; return list(ArrayList(bitPositions))
def get_doc_phrase_freq(self, phrase, field, slop, ordered): """ Returns collection frequency for a given phrase and field. :param phrase: str :param field: field name :param slop: number of terms in between :param ordered: If true, term occurrences should be ordered :return: dictionary {doc: freq, ...} """ # creates span near query span_near_query = self.get_span_query(phrase.split(" "), field, slop=slop, ordered=ordered) # extracts document frequency self.open_searcher() index_reader_context = self.searcher.getTopReaderContext() term_contexts = HashMap() terms = TreeSet() span_near_query.extractTerms(terms) for term in terms: term_contexts.put(term, TermContext.build(index_reader_context, term)) leaves = index_reader_context.leaves() doc_phrase_freq = {} # iterates over all atomic readers for atomic_reader_context in leaves: bits = atomic_reader_context.reader().getLiveDocs() spans = span_near_query.getSpans(atomic_reader_context, bits, term_contexts) while spans.next(): lucene_doc_id = spans.doc() doc_id = atomic_reader_context.reader().document(lucene_doc_id).get(self.FIELDNAME_ID) if doc_id not in doc_phrase_freq: doc_phrase_freq[doc_id] = 1 else: doc_phrase_freq[doc_id] += 1 return doc_phrase_freq
def __init__(self, ont = '', file_path=''): self.manager = OWLManager.createOWLOntologyManager() if not ont: if file_path: self.ont = self.manager.loadOntologyFromOntologyDocument(File(file_path)) else: warnings.warn("Constructor failed. Empty args") else: self.ont = ont self.factory = self.manager.getOWLDataFactory() self.simple_sfp = SimpleShortFormProvider() # .getShortForm(iri) ontset = TreeSet() ontset.add(self.ont) #public BidirectionalShortFormProviderAdapter(OWLOntologyManager man, #java.util.Set<OWLOntology> ontologies, #ShortFormProvider shortFormProvider) # Providing the manager, means that this listens for changes. self.bi_sfp = BidirectionalShortFormProviderAdapter(self.manager, ontset, self.simple_sfp) # .getShortForm(iri); .getEntity()
def generate(self, idx, abspath): from Analyzer import Analyzer from Binding import Binding if isinstance(idx, Analyzer): mt = idx.loadFile(abspath) if mt is None: return ArrayList() scope, path = mt.getTable(), abspath else: scope, path = idx, abspath # alt impl. result = ArrayList() entries = TreeSet() for b in scope.values(): if not b.isSynthetic() and not b.isBuiltin() and path == b.getFile(): entries.add(b) entries = sorted(entries, lambda a,b: a.compareTo(b)) for nb in entries: kids = None if nb.getKind() == Binding.Kind.CLASS: realType = nb.getType(); if realType.isUnionType(): for t in realType.asUnionType().getTypes(): if t.isClassType(): realType = t break kids = self.generate(realType.getTable(), path) kid = Outliner.Branch() if (kids is not None) else Outliner.Leaf(); kid.setOffset(nb.getStart()) kid.setQname(nb.getQname()) kid.setKind(nb.getKind()) if kids is not None: kid.setChildren(kids) result.append(kid) return result
def __activate__(self, context): formData = context["formData"] services = context["Services"] response = context["response"] query = "keywords:[* TO *]" q = formData.get("q") if q: query += " AND keywords:(%(q)s OR %(q)s*)" % { "q": q } req = SearchRequest(query) req.setParam("fl", "keywords") req.setParam("rows", "50") keywords = TreeSet() indexer = services.getIndexer() out = ByteArrayOutputStream() indexer.search(req, out) result = SolrResult(ByteArrayInputStream(out.toByteArray())) for doc in result.getResults(): for keyword in doc.getList("keywords"): if keyword.startswith(q): keywords.add(keyword) writer = response.getPrintWriter("text/plain; charset=UTF-8") writer.println("\n".join(keywords)) writer.close()
def __init__(self, ont='', file_path='', uri=''): self.manager = OWLManager.createOWLOntologyManager() if not ont: if file_path: self.ont = self.manager.loadOntologyFromOntologyDocument( File(file_path)) elif uri: self.ont = self.manager.loadOntologyFromIRI( IRI.create(uri)) # check this! else: warnings.warn("Constructor failed. Empty args") else: self.ont = ont self.factory = self.manager.getOWLDataFactory() self.simple_sfp = SimpleShortFormProvider() # .getShortForm(iri) self.simple_iri_sfp = SimpleIRIShortFormProvider() ontset = TreeSet() ontset.add(self.ont) #public BidirectionalShortFormProviderAdapter(OWLOntologyManager man, #java.util.Set<OWLOntology> ontologies, #ShortFormProvider shortFormProvider) # Providing the manager, means that this listens for changes. self.bi_sfp = BidirectionalShortFormProviderAdapter( self.manager, ontset, self.simple_sfp) # .getShortForm(iri); .getEntity()
def wrap(cls, topLevelReaderContext, query): termContexts = HashMap() terms = TreeSet() query.extractTerms(terms) for term in terms: termContexts.put(term, TermContext.build(topLevelReaderContext, term)) leaves = topLevelReaderContext.leaves() if leaves.size() == 1: ctx = leaves.get(0) return query.getSpans(ctx, ctx.reader().getLiveDocs(), termContexts) return MultiSpansWrapper(leaves, query, termContexts)
def saveModels(mol, files, type): active = mol.getActiveStructures() if type == 'cif': mol.resetActiveStructures() if 'final' not in files[ -1]: #don't write out reference structure if in file list sNums = [i for i in range(len(files) - 1)] treeSet = TreeSet(sNums) mol.setActiveStructures(treeSet) molName = mol.getName() cifFile = os.path.join(os.getcwd(), molName + "_all.cif") out = FileWriter(cifFile) MMcifWriter.writeAll(out, molName) elif type == 'pdb': for (i, file) in zip(active, files): (dir, fileName) = os.path.split(file) newFileName = 'sup_' + fileName newFile = os.path.join(dir, newFileName) molio.savePDB(mol, newFile, i)
coregroups = TreeMap() for i in range(numberOfCoreGroups): coregroupname = "BridgedCoreGroup" + str(i) if (i == 0): coregroupname = "DefaultCoreGroup" if (proxyCoreGroup == 1 and i == 1): coregroupname = "BridgedCoreGroupODR" coregroups.put(coregroupname, CoreGroup(coregroupname)) # # process all servers # servers = TreeMap() clusters = TreeMap() coregroupBridges = TreeSet() print "Retrieving existing coregroups" coregroupIds = convertToList(AdminConfig.list("CoreGroup")) for coregroup in coregroupIds: print "Existing coregroup: " + AdminConfig.showAttribute(coregroup, "name") cgname = AdminConfig.showAttribute(coregroup, "name") cg = coregroups.get(cgname) #if full reconfigure is selected, existing coregroups will be deleted and not be added to the coregroups list if (fullReconfigure == 0): if (cg == None): cg = CoreGroup(cgname) coregroups.put(cgname, cg) if (cg != None): cg.configid = coregroup cgservers = convertToList(AdminConfig.list("CoreGroupServer", coregroup)) for cgs in cgservers:
def getSortedKeySet(self): return TreeSet(self.metadata.getJsonObject().keySet())
class SnmpQueryBuilder: def __init__(self, tableOidOffset): self.queryElements = TreeSet(OffsetBasedComparator()) self.tableOidOffset = tableOidOffset def addQueryElement(self, offset, name, type='string'): queryElement = QueryElement(offset, name, type) self.queryElements.add(queryElement) def __buildQueryParts(self, productOidBase, queryElements): ''' Build query parts and returns base query part and parts for each query element (OID) @types: str, java.util.TreeSet -> tuple(str, list(str))''' if productOidBase: tableOidBase = self.__glue_(productOidBase, self.tableOidOffset, '.') else: tableOidBase = self.tableOidOffset iterator = self.queryElements.iterator() queryElement = iterator.next() oidNoType = self.__glue_(tableOidBase, queryElement.offset, '.') surrogateOid = self.__glue_(tableOidBase, queryElement.offset + 1, '.') oidNoType = self.__glue_(oidNoType, surrogateOid) queryBase = self.__glue_(oidNoType, queryElement.type) oidParts = [] while iterator.hasNext(): queryElement = iterator.next() oidNoType = self.__glue_(tableOidBase, queryElement.offset, '.') oid = self.__glue_(oidNoType, queryElement.type) oidParts.append(oid) return queryBase, oidParts def produceQuery(self, productOidBase): '@types: str -> str' queryBase, oidParts = self.__buildQueryParts(productOidBase, self.queryElements) # make single query where query base is joined with parts related to # each query element return reduce(self.__glue_, (queryBase,) + tuple(oidParts)) def producePartialQueries(self, productOidBase): queryBase, oidParts = self.__buildQueryParts(productOidBase, self.queryElements) # zi = zip(queryBase * len(oidParts), oidParts) # return map(lambda pair, _ = self: _.__glue_(pair[0], pair[1]), zi) queries = [] for elementPart in oidParts: queries.append(self.__glue_(queryBase, elementPart)) return queries def parseResults(self, resultSet): table = resultSet.asTable() return self.produceResults(table) def produceResults(self, table): resultItems = [] for rowIndex in range(len(table)): columnIndex = 1 resultItem = ResultItem() iterator = self.queryElements.iterator() while iterator.hasNext(): queryElement = iterator.next() name = queryElement.name setattr(resultItem, name, table[rowIndex][columnIndex]) columnIndex += 1 try: setattr(resultItem, 'meta_data', table[rowIndex][0]) except: pass resultItems.append(resultItem) return resultItems def mergeAndParseResults(self, resultSets): resultTable = [] numberOfResults = len(resultSets) if numberOfResults > 0: firstTable = resultSets[0].asTable() numberOfRows = len(firstTable) for rowIndex in xrange(numberOfRows): resultTable.append([firstTable[rowIndex][0], firstTable[rowIndex][1], firstTable[rowIndex][2]]) if numberOfResults > 1: for i in xrange(1, numberOfResults): table = resultSets[i].asTable() for rowIndex in xrange(numberOfRows): resultTable[rowIndex].append(table[rowIndex][2]) return self.produceResults(resultTable) def __glue_(self, base, offset, separator=','): return ('%s%s%s') % (base, separator, offset)
class StyleApplier(object): """ generated source for class StyleApplier """ # Empirically, adding the span tags multiplies length by 6 or more. SOURCE_BUF_MULTIPLIER = 6 # class Tag(Comparable, Tag): class Tag(object): """ generated source for class Tag """ def __init__(self): pass def compareTo(self, other): return self.__cmp__(other) def __cmp__(self, other): if self is other: return 0 if self.offset < other.offset: return -1 if other.offset < self.offset: return 1 #return self.offset - other.offset return hash(self) - hash(other) """ def __eq__(self, other): return self is other def __ne__(self, other): return self is not other def __lt__(self, other): return self.offset < other.offset def __le__(self, other): return self.offset <= other.offset def __gt__(self, other): return self.offset > other.offset def __ge__(self, other): return self.offset >= other.offset """ def insert(self): # Copy source code up through this tag. if self.offset > self.applier.sourceOffset: self.applier.copySource(self.applier.sourceOffset, self.offset) class StartTag(Tag): def __init__(self, style, applier): super(StyleApplier.StartTag, self).__init__() self.applier = applier self.offset = style.start() self.style = style def insert(self): super(StyleApplier.StartTag, self).insert() if self.style.type_ == ANCHOR: self.applier.buffer_.append('<a name="' + self.style.url + '" ') self.applier.buffer_.append('id="' + self.style.id + '"') if self.style.highlight is not None and len( self.style.highlight) > 0: ids = _.joinWithSep(self.style.highlight, "\',\'", "\'", "\'") self.applier.buffer_.append('onmouseover="highlight(') self.applier.buffer_.append(ids) self.applier.buffer_.append(')" ') elif self.style.type_ == LINK: self.applier.buffer_.append('<a href="' + self.style.url + '"') self.applier.buffer_.append(' id="' + self.style.id + '"') if self.style.highlight is not None and len( self.style.highlight) > 0: ids = _.joinWithSep(self.style.highlight, "\',\'", "\'", "\'") self.applier.buffer_.append('onmouseover="highlight(') self.applier.buffer_.append(ids) self.applier.buffer_.append(')" ') else: self.applier.buffer_.append('<span class="') self.applier.buffer_.append(self.applier.toCSS(self.style)) self.applier.buffer_.append('" ') if self.style.message is not None: self.applier.buffer_.append(' title="') self.applier.buffer_.append(self.style.message) self.applier.buffer_.append('" ') self.applier.buffer_.append(">") class EndTag(Tag): def __init__(self, style, applier): super(StyleApplier.EndTag, self).__init__() self.applier = applier self.offset = style.end() self.style = style def insert(self): super(StyleApplier.EndTag, self).insert() if self.style.type_ == ANCHOR or self.style.type_ == LINK: self.applier.buffer_.append("</a>") else: self.applier.buffer_.append("</span>") def __init__(self, path, src, runs): self.tags = TreeSet() self.buffer_ = [] self.sourceOffset = 0 self.source = src for run in runs: self.tags.add(StyleApplier.StartTag(run, self)) self.tags.add(StyleApplier.EndTag(run, self)) def apply(self): def sortFn(a, b): return a.compareTo(b) self.buffer_ = [] self.tags = sorted(self.tags, sortFn) for tag in self.tags: tag.insert() if self.sourceOffset < len(self.source): self.copySource(self.sourceOffset, len(self.source)) return u''.join(map(lambda s: s.encode('utf-8'), self.buffer_)) def copySource(self, begin, end): inner = self.source[0:begin] if (end == -1) else self.source[begin:end] src = self.escape(inner) self.buffer_.append(src) self.sourceOffset = end def escape(self, s): return s.replace("&", "&").replace("'", "'").replace( "\"", """).replace("<", "<").replace(">", ">") def toCSS(self, style): return style.type_.__str__().lower().replace("_", "-")
def __init__(self, objectName): "@param objectName: the name of the queried CIM class" self.queryElements = TreeSet(ColumnNameBasedComparator()) self.objectName = objectName self.whereClause = None
from com.xebialabs.deployit.plugin.api.udm.base import BaseDeployable from com.xebialabs.deployit.plugin.api.reflect import Type oldType = request.query['p1'] appId = request.query['p2'] oldVer = request.query['p3'] newVer = request.query['p4'] migratorModule = __import__('typeMigrator.' + oldType, fromlist=['']) # Create a new deployment package repositoryService.copy("%s/%s" % (appId, oldVer), "%s/%s" % (appId, newVer)) # Read the new deployment package app = repositoryService.read("%s/%s" % (appId, newVer)) # Loop through the deployables result = [] for item in app.getProperty('deployables'): deployable = repositoryService.read(item.id) if deployable.type == oldType: newDeployable = BaseDeployable() newDeployable.setId("%s/%s/%s" % (appId, newVer, "New" + deployable.name)) newDeployable.setTags(TreeSet()) migratorModule.mapProperties(deployable, newDeployable) result.append(newDeployable.getType().toString()) repositoryService.create("%s/%s/%s" % (appId, newVer, "New" + deployable.name), newDeployable) repositoryService.delete(deployable.id) response.entity = result
out = renderResponse.getPortletOutputStream() custom = Custom(renderRequest, renderResponse) out.write(""" <b>Using the JDK</b> <br /><br /> The following set has been generated with java.util.TreeSet. <br /><br /> \n """) set = TreeSet() set.add("foo") set.add("Bar") set.add("baz") for v in set: out.write(v + "\n") out.write(""" <br /><br /> <b>Invoking Liferay Services</b> <br /><br /> \n """)
def __init__(self, tableOidOffset): self.queryElements = TreeSet(OffsetBasedComparator()) self.tableOidOffset = tableOidOffset
class SnmpQueryBuilder: def __init__(self, tableOidOffset): self.queryElements = TreeSet(OffsetBasedComparator()) self.tableOidOffset = tableOidOffset def addQueryElement(self, offset, name, type='string'): queryElement = QueryElement(offset, name, type) self.queryElements.add(queryElement) def __buildQueryParts(self, productOidBase, queryElements): ''' Build query parts and returns base query part and parts for each query element (OID) @types: str, java.util.TreeSet -> tuple(str, list(str))''' if productOidBase: tableOidBase = self.__glue_(productOidBase, self.tableOidOffset, '.') else: tableOidBase = self.tableOidOffset iterator = self.queryElements.iterator() queryElement = iterator.next() oidNoType = self.__glue_(tableOidBase, queryElement.offset, '.') surrogateOid = self.__glue_(tableOidBase, queryElement.offset + 1, '.') oidNoType = self.__glue_(oidNoType, surrogateOid) queryBase = self.__glue_(oidNoType, queryElement.type) oidParts = [] while iterator.hasNext(): queryElement = iterator.next() oidNoType = self.__glue_(tableOidBase, queryElement.offset, '.') oid = self.__glue_(oidNoType, queryElement.type) oidParts.append(oid) return queryBase, oidParts def produceQuery(self, productOidBase): '@types: str -> str' queryBase, oidParts = self.__buildQueryParts(productOidBase, self.queryElements) # make single query where query base is joined with parts related to # each query element return reduce(self.__glue_, (queryBase, ) + tuple(oidParts)) def producePartialQueries(self, productOidBase): queryBase, oidParts = self.__buildQueryParts(productOidBase, self.queryElements) # zi = zip(queryBase * len(oidParts), oidParts) # return map(lambda pair, _ = self: _.__glue_(pair[0], pair[1]), zi) queries = [] for elementPart in oidParts: queries.append(self.__glue_(queryBase, elementPart)) return queries def parseResults(self, resultSet): table = resultSet.asTable() return self.produceResults(table) def produceResults(self, table): resultItems = [] for rowIndex in range(len(table)): columnIndex = 1 resultItem = ResultItem() iterator = self.queryElements.iterator() while iterator.hasNext(): queryElement = iterator.next() name = queryElement.name setattr(resultItem, name, table[rowIndex][columnIndex]) columnIndex += 1 try: setattr(resultItem, 'meta_data', table[rowIndex][0]) except: pass resultItems.append(resultItem) return resultItems def mergeAndParseResults(self, resultSets): resultTable = [] numberOfResults = len(resultSets) if numberOfResults > 0: firstTable = resultSets[0].asTable() numberOfRows = len(firstTable) for rowIndex in xrange(numberOfRows): resultTable.append([ firstTable[rowIndex][0], firstTable[rowIndex][1], firstTable[rowIndex][2] ]) if numberOfResults > 1: for i in xrange(1, numberOfResults): table = resultSets[i].asTable() for rowIndex in xrange(numberOfRows): resultTable[rowIndex].append(table[rowIndex][2]) return self.produceResults(resultTable) def __glue_(self, base, offset, separator=','): return ('%s%s%s') % (base, separator, offset)
def __init__(self, name): self.name = name self.configid = None self.clusters = TreeSet()
# Calendar.getInstance().get(Calendar.HOUR_OF_DAY), # Calendar.getInstance().get(Calendar.MINUTE), # Calendar.getInstance().get(Calendar.SECOND), # Calendar.getInstance().get(Calendar.MILLISECOND) # ) ADAPTER_NAME = "Hardware Report" FILE_SEPARATOR = "\\" C__FILTERED_CUTSOMER_CLASSIFICATION = ("Green", "Blue") C__FILTERED_SYSTEM_STATUS = ("in production") ############################################################################################## # GLOBALS ############################################################################################## g__NodeWithSWandCPUQty = 0 g__SortedData = TreeSet() adapterConfigBaseDir = "%s%s%s%s" % ( CollectorsParameters.BASE_PROBE_MGR_DIR, CollectorsParameters.getDiscoveryConfigFolder(), FILE_SEPARATOR, ADAPTER_NAME) def quote(stringin): return '"' + str(stringin) + '"' class CPUData: def __init__(self): self.cputype = '' self.cpuspeed = ''
class StyleApplier(object): """ generated source for class StyleApplier """ # Empirically, adding the span tags multiplies length by 6 or more. SOURCE_BUF_MULTIPLIER = 6 # class Tag(Comparable, Tag): class Tag(object): """ generated source for class Tag """ def __init__(self): pass def compareTo(self, other): return self.__cmp__(other) def __cmp__(self, other): if self is other: return 0 if self.offset < other.offset: return -1 if other.offset < self.offset: return 1 #return self.offset - other.offset return hash(self) - hash(other) """ def __eq__(self, other): return self is other def __ne__(self, other): return self is not other def __lt__(self, other): return self.offset < other.offset def __le__(self, other): return self.offset <= other.offset def __gt__(self, other): return self.offset > other.offset def __ge__(self, other): return self.offset >= other.offset """ def insert(self): # Copy source code up through this tag. if self.offset > self.applier.sourceOffset: self.applier.copySource(self.applier.sourceOffset, self.offset) class StartTag(Tag): def __init__(self, style, applier): super(StyleApplier.StartTag, self).__init__() self.applier = applier self.offset = style.start() self.style = style def insert(self): super(StyleApplier.StartTag, self).insert() if self.style.type_==ANCHOR: self.applier.buffer_.append('<a name="' + self.style.url + '" ') self.applier.buffer_.append('id="' + self.style.id + '"') if self.style.highlight is not None and len(self.style.highlight) > 0: ids = _.joinWithSep(self.style.highlight, "\',\'", "\'", "\'"); self.applier.buffer_.append('onmouseover="highlight(') self.applier.buffer_.append(ids) self.applier.buffer_.append(')" ') elif self.style.type_==LINK: self.applier.buffer_.append('<a href="' + self.style.url + '"') self.applier.buffer_.append(' id="' + self.style.id + '"') if self.style.highlight is not None and len(self.style.highlight) > 0: ids = _.joinWithSep(self.style.highlight, "\',\'", "\'", "\'"); self.applier.buffer_.append('onmouseover="highlight(') self.applier.buffer_.append(ids) self.applier.buffer_.append(')" ') else: self.applier.buffer_.append('<span class="') self.applier.buffer_.append(self.applier.toCSS(self.style)) self.applier.buffer_.append('" ') if self.style.message is not None: self.applier.buffer_.append(' title="') self.applier.buffer_.append(self.style.message) self.applier.buffer_.append('" ') self.applier.buffer_.append(">") class EndTag(Tag): def __init__(self, style, applier): super(StyleApplier.EndTag, self).__init__() self.applier = applier self.offset = style.end() self.style = style def insert(self): super(StyleApplier.EndTag, self).insert() if self.style.type_==ANCHOR or self.style.type_==LINK: self.applier.buffer_.append("</a>") else: self.applier.buffer_.append("</span>") def __init__(self, path, src, runs): self.tags = TreeSet() self.buffer_ = [] self.sourceOffset = 0 self.source = src for run in runs: self.tags.add(StyleApplier.StartTag(run, self)) self.tags.add(StyleApplier.EndTag(run, self)) def apply(self): def sortFn(a,b): return a.compareTo(b) self.buffer_ = [] self.tags = sorted(self.tags, sortFn) for tag in self.tags: tag.insert() if self.sourceOffset < len(self.source): self.copySource(self.sourceOffset, len(self.source)) return u''.join(map(lambda s: s.encode('utf-8'), self.buffer_)) def copySource(self, begin, end): inner = self.source[0:begin] if (end == -1) else self.source[begin:end] src = self.escape(inner); self.buffer_.append(src) self.sourceOffset = end def escape(self, s): return s.replace("&", "&").replace("'", "'").replace("\"", """).replace("<", "<").replace(">", ">") def toCSS(self, style): return style.type_.__str__().lower().replace("_", "-")
out = renderResponse.getPortletOutputStream(); custom = Custom(renderRequest, renderResponse); out.write(""" <b>Using the JDK</b> <br /><br /> The following set has been generated with java.util.TreeSet. <br /><br /> \n """); set = TreeSet(); set.add("foo"); set.add("Bar"); set.add("baz"); for v in set: out.write(v + "\n"); out.write(""" <br /><br /> <b>Invoking Liferay Services</b> <br /><br /> \n """);