rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
"Test Epetra.Vector __setattr__ method for 'array'"
"Test Epetra.MultiVector __setattr__ method for 'array'"
def testSetArray(self): "Test Epetra.Vector __setattr__ method for 'array'" ev = Epetra.Vector(self.map) self.assertRaises(AttributeError, ev.__setattr__, "array", "junk")
localGIDs = ravel(self.gids[:,self.start:self.end]) inPlaceGIDs = ravel(self.gids[self.start:self.end,self.start:self.end]) remoteGIDs = [gid for gid in localGIDs if gid not in inPlaceGIDs] lists = self.map1.RemoteIDList(remoteGIDs) remoteLIDs = lists[1] result = self.importer.RemoteLIDs()
remoteGIDs = [] for p in range(self.numProc): if p!= self.myPID: start = p * self.myN end = start + self.myN remoteGIDs.extend(ravel(self.gids[start:end,self.start:self.end])) lists = self.map1.RemoteIDList(remoteGIDs) remoteLIDs = lists[1] result = self.importer.RemoteLIDs()
def testRemoteLIDs(self): "Test Epetra.Import/Export RemoteLIDs method" localGIDs = ravel(self.gids[:,self.start:self.end]) inPlaceGIDs = ravel(self.gids[self.start:self.end,self.start:self.end]) remoteGIDs = [gid for gid in localGIDs if gid not in inPlaceGIDs] lists = self.map1.RemoteIDList(remoteGIDs) remote...
for i in range(len(result)): self.assertEqual(result[i], remoteLIDs[i])
for i in range(len(result)): self.assertEqual(result[i] in remoteLIDs, True)
def testRemoteLIDs(self): "Test Epetra.Import/Export RemoteLIDs method" localGIDs = ravel(self.gids[:,self.start:self.end]) inPlaceGIDs = ravel(self.gids[self.start:self.end,self.start:self.end]) remoteGIDs = [gid for gid in localGIDs if gid not in inPlaceGIDs] lists = self.map1.RemoteIDList(remoteGIDs) remote...
self.assertEqual(result[i], remoteLIDs[i])
self.assertEqual(result[i] in remoteLIDs, True)
def testRemoteLIDs(self): "Test Epetra.Import/Export RemoteLIDs method" localGIDs = ravel(self.gids[:,self.start:self.end]) inPlaceGIDs = ravel(self.gids[self.start:self.end,self.start:self.end]) remoteGIDs = [gid for gid in localGIDs if gid not in inPlaceGIDs] lists = self.map1.RemoteIDList(remoteGIDs) remote...
removeContinuationLines(lines)
joinContinuationLines(lines)
def parseMakefile(filename): """Open filename, read in the text and return a dictionary of make variable names and values. If an include statement is found, this routine will be called recursively.""" lines = open(filename,"r").readlines() # Read in the lines of the Makefile lines = [s.split("#")[0] for s in lines...
tempDict = dict tempDict["include files"] = match.group(1).strip() makeSubstitutions(tempDict) for file in tempDict["include files"].split():
files = evaluate(match.group(1),dict).split() for file in files:
def parseMakefile(filename): """Open filename, read in the text and return a dictionary of make variable names and values. If an include statement is found, this routine will be called recursively.""" lines = open(filename,"r").readlines() # Read in the lines of the Makefile lines = [s.split("#")[0] for s in lines...
shellCmd = match.group(1) start = match.start(1)-8 end = match.end(1) +1
(start,end) = findBlock(value,match.start()) start -= 1 shellCmd = value[start+8:end-1]
def evaluate(value, dict): """Evaluate the string 'value' by applying the following algorithm: if value contains substring '$(VARNAME)' and dict has key VARNAME, substitute dict[VARNAME] for the variable reference. If VARNAME is not a key for the dictionary, substitute the null string. If value contains substring '$(...
if (shellCmd == newShellCmd): (status,subValue) = commands.getstatusoutput(shellCmd) if status: print >>sys.stderr, "WARNING: %s gives\n%s" % (shellCmd, subValue) subValue = "" value = value[:start] + subValue + value[end:] else: value = value[:start] + newShellCmd + value[end:]
while newShellCmd != shellCmd: shellCmd = newShellCmd newShellCmd = evaluate(shellCmd,dict) (status,subValue) = commands.getstatusoutput(shellCmd) if status: print >>sys.stderr, "WARNING: %s gives\n%s" % (shellCmd, subValue) subValue = "" value = value[:start] + subValue + value[end:]
def evaluate(value, dict): """Evaluate the string 'value' by applying the following algorithm: if value contains substring '$(VARNAME)' and dict has key VARNAME, substitute dict[VARNAME] for the variable reference. If VARNAME is not a key for the dictionary, substitute the null string. If value contains substring '$(...
dict[varName] = evaluate(dict[varName],dict)
value = dict[varName] dict[varName] = evaluate(value,dict)
def makeSubstitutions(dict): """Loop over the items of a dictionary of variable names and string values. If the value contains the substring(s) '$(VARNAME)' and VARNAME is a key in the dictionary, then substitute the appropriate value. If VARNAME is not a key in the dictionary, then substitute the null string. For ci...
dict = processFile(args[0])
dict = processMakefile(args[0])
def main(): """This is the routine that gets called if MakefileVariable.py is invoked from the shell. Process any command-line options that may be given, take the first argument as a filename, process it to obtain a dictionary of variable name/value pairs, and output the results.""" # Initialization (progDir,progName...
print "creating", filename
def buildInitFile(pyTrilinosModules,filename,depfile): build = False if os.path.isfile(filename): if os.path.getmtime(filename) < os.path.getmtime(depfile): build = True else: build = True if build: print "\nEnabled modules:" for module in pyTrilinosModules: print " ", module print print "creating", filename open(fil...
open(os.path.join(installDir,initFileName),"w").write(open(initFileDir,"r").read()) except:
open(os.path.join(installDir,initFileName),"w").write(open(initFileName,"r").read()) except IOError:
def buildInitFile(pyTrilinosModules,filename,depfile): build = False if os.path.isfile(filename): if os.path.getmtime(filename) < os.path.getmtime(depfile): build = True else: build = True if build: print "\nEnabled modules:" for module in pyTrilinosModules: print " ", module print print "creating", filename open(fil...
Comm = Epetra.PyComm();
Comm = Epetra.PyComm()
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Type = args[0];
Type = args[0]
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Epetra.Copy, Map, 0); Indices = Epetra.IntSerialDenseVector(3); Values = Epetra.SerialDenseVector(3); Values[0] = 2.0; Value...
NumGlobalRows = 10 Map = Epetra.Map(NumGlobalRows, 0, Comm) LHS_exact = Epetra.MultiVector(Map, 1) LHS = Epetra.MultiVector(Map, 1) RHS = Epetra.MultiVector(Map, 1) Matrix = Epetra.CrsMatrix(Epetra.Copy, Map, 0) Indices = Epetra.IntSerialDenseVector(3) Values = Epetra.SerialDenseVector(3) Values[0] = 2.0 Values[1] = -...
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Indices[0] = i;
Indices[0] = i
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
NumEntries = 2; Indices[1] = i + 1;
NumEntries = 2 Indices[1] = i + 1
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
NumEntries = 2; Indices[1] = i - 1;
NumEntries = 2 Indices[1] = i - 1
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
NumEntries = 3; Indices[1] = i - 1; Indices[2] = i + 1; Matrix.InsertGlobalValues(i, NumEntries, Values, Indices); ierr = Matrix.FillComplete();
NumEntries = 3 Indices[1] = i - 1 Indices[2] = i + 1 Matrix.InsertGlobalValues(i, NumEntries, Values, Indices) ierr = Matrix.FillComplete()
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
LHS_exact.Random(); Matrix.Multiply(False, LHS_exact, RHS); LHS.PutScalar(1.0);
LHS_exact.Random() Matrix.Multiply(False, LHS_exact, RHS) LHS.PutScalar(1.0)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Problem = Epetra.LinearProblem(Matrix, LHS, RHS);
Problem = Epetra.LinearProblem(Matrix, LHS, RHS)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Solver = Amesos.Lapack(Problem);
Solver = Amesos.Lapack(Problem)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Solver = Amesos.Klu(Problem);
Solver = Amesos.Klu(Problem)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Solver = Amesos.Umfpack(Problem);
Solver = Amesos.Umfpack(Problem)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Solver = Amesos.Superlu(Problem);
Solver = Amesos.Superlu(Problem)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Solver = Amesos.Superludist(Problem);
Solver = Amesos.Superludist(Problem)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Solver = Amesos.Dscpack(Problem);
Solver = Amesos.Dscpack(Problem)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
Solver = Amesos.Mumps(Problem);
Solver = Amesos.Mumps(Problem)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
PrintHelp(); sys.exit(-2);
print __doc__ sys.exit(-2)
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
}; Solver.SetParameters(AmesosList); Solver.SymbolicFactorization(); Solver.NumericFactorization(); ierr = Solver.Solve();
} Solver.SetParameters(AmesosList) Solver.SymbolicFactorization() Solver.NumericFactorization() ierr = Solver.Solve()
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
main();
main()
def main(): Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: Type = "Amesos_Lapack" else: Type = args[0]; NumGlobalRows = 10; Map = Epetra.Map(NumGlobalRows, 0, Comm); LHS_exact = Epetra.MultiVector(Map, 1); LHS = Epetra.MultiVector(Map, 1); RHS = Epetra.MultiVector(Map, 1); Matrix = Epetra.CrsMatrix(Ep...
crsm = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3)
crsm = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3, False)
def testScale(self): "Test Epetra.CrsMatrix Scale method" crsm = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3) self.fillMatrixGlobal(crsm) crsm.Scale(10) for lrid in range(crsm.NumMyRows()): grid = crsm.GRID(lrid) refValues = [-10,20,-10] if grid == 0 : refValues.pop( 0) if grid == self.size-1: re...
crsm2 = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3)
crsm2 = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3, False)
def testRangeMap(self): "Test Epetra.CrsMatrix RangeMap method" crsm1 = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, 3) rangeMap1 = crsm1.RangeMap() self.failUnless(self.rowMap.SameAs(rangeMap1)) crsm2 = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3) rangeMap2 = crsm2.RangeMap() self.failUnless(self.rowMap.Sa...
crsm2 = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3)
crsm2 = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3, False)
def testOperatorRangeMap(self): "Test Epetra.CrsMatrix OperatorRangeMap method" crsm1 = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, 3) rangeMap1 = crsm1.OperatorRangeMap() self.failUnless(self.rowMap.SameAs(rangeMap1)) crsm2 = Epetra.CrsMatrix(Epetra.Copy, self.rowMap, self.colMap, 3) rangeMap2 = crsm2.OperatorRangeMap(...
"\n*********************\nTesting Epetra.Object\n*********************\n"
"\n**********************\nTesting NOX.StatusTest\n**********************\n"
def testComboOr(self): "Test NOX.StatusTest.Combo constructor with OR option" combo = NOX.StatusTest.Combo(NOX.StatusTest.Combo.OR) combo.addStatusTest(self.maxIters) combo.addStatusTest(self.stagnate) combo.addStatusTest(self.finiteVal)
print "ERRRRORRRR"
try: Map, Matrix, LHS, RHS, Exact = Triutils.ReadHB(args[0], Comm); except: print "Specified matrix cannot be found" exit(0)
def main(): # read the matrix from file in H/B format. The filename is specified by the # first argument in the compile line. If no filename is specified, then the # code build a matrix using matrix gallery. Comm = Epetra.PyComm(); args = sys.argv[1:] if len(args) == 0: nx = 30; ny = 30 GaleriList = { "n": nx * ny, "...
Problem = Epetra.LinearProblem(Matrix, LHS, RHS) Solver = AztecOO.AztecOO(Problem)
Solver = AztecOO.AztecOO(Matrix, LHS, RHS)
def main(): n = 10 Comm = Epetra.PyComm() if Comm.NumProc() != 1: print "This example is only serial, sorry" return Matrix = Laplace1D(n, Comm) # Use Multivectors, not vectors! LHS = Epetra.MultiVector(Matrix.Map(), 1) RHS = Epetra.MultiVector(Matrix.Map(), 1) LHS. PutScalar(0.0) RHS. PutScalar(1.0) Problem = Epetra...
self.assertEquals(result, -1) self.assertEquals(emv[0,lid], 0.5)
self.assertEquals(result, 1)
def testReplaceGlobalValue1(self): "Test Epetra.MultiVector ReplaceGlobalValue method" emv = Epetra.MultiVector(self.map,self.numPyArray) gid = 4 lid = self.map.LID(gid) self.assertEquals(emv[0,gid], 0.5) result = emv.ReplaceGlobalValue(gid,0,5.0) if lid >= 0: self.assertEquals(result, 0) self.assertEquals(emv[0,lid], ...
self.assertEquals(result, -1) self.assertEquals(emv[0,lid,1], 0.5)
self.assertEquals(result, 1)
def testReplaceGlobalValue2(self): "Test Epetra.MultiVector ReplaceGlobalValue method for BlockMaps" map = Epetra.BlockMap(3*self.comm.NumProc(),3,0,self.comm) self.numPyArray.shape = (1,3,3) # 1 vector, 3 elements, 3 points per element emv = Epetra.MultiVector(map,self.numPyArray) gid = 1 lid = self.map.LID(gid) self...
self.assertEquals(result, -1) self.assertEquals(emv[0,lid], 0.5)
self.assertEquals(result, 1)
def testSumIntoGlobalValue1(self): "Test Epetra.MultiVector SumIntoGlobalValue method" emv = Epetra.MultiVector(self.map,self.numPyArray) gid = 4 lid = self.map.LID(gid) self.assertEquals(emv[0,gid], 0.5) result = emv.SumIntoGlobalValue(gid,0,0.5) if lid >= 0: self.assertEquals(result, 0) self.assertEquals(emv[0,lid], ...
self.assertEquals(result, -1) self.assertEquals(emv[0,lid,1], 0.5)
self.assertEquals(result, 1)
def testSumIntoGlobalValue2(self): "Test Epetra.MultiVector SumIntoGlobalValue method for BlockMaps" map = Epetra.BlockMap(3*self.comm.NumProc(),3,0,self.comm) self.numPyArray.shape = (1,3,3) # 1 vector, 3 elements, 3 points per element emv = Epetra.MultiVector(map,self.numPyArray) gid = 1 lid = self.map.LID(gid) self...
sql = c.fetchone()[0] if 'feed_desc' not in sql:
sql = c.fetchone() if sql and 'feed_desc' not in sql[0]:
def populate_tables(self): import os os.system('sqlite3 rss.db < ddl.sql')
keymap = {'channel': 'feed', 'items': 'entries', 'guid': 'id', 'date': 'updated', 'date_parsed': 'updated_parsed', 'description': ['subtitle', 'summary'], 'url': ['href'], 'modified': 'updated', 'modified_parsed': 'updated_parsed', 'issued': 'published', 'issued_parsed': 'published_parsed', 'copyright': 'rights', 'copy...
def __getitem__(self, key): keymap = {'channel': 'feed', 'items': 'entries', 'guid': 'id', 'date': 'updated', 'date_parsed': 'updated_parsed', 'description': ['subtitle', 'summary'], 'url': ['href'], 'modified': 'updated', 'modified_parsed': 'updated_parsed', 'issued': 'published', 'issued_parsed': 'published_parsed', ...
realkey = keymap.get(key, key)
realkey = self.keymap.get(key, key)
def __getitem__(self, key): keymap = {'channel': 'feed', 'items': 'entries', 'guid': 'id', 'date': 'updated', 'date_parsed': 'updated_parsed', 'description': ['subtitle', 'summary'], 'url': ['href'], 'modified': 'updated', 'modified_parsed': 'updated_parsed', 'issued': 'published', 'issued_parsed': 'published_parsed', ...
return hasattr(self, key) or UserDict.has_key(self, key)
try: return hasattr(self, key) or UserDict.has_key(self, key) except AttributeError: return False
def has_key(self, key): return hasattr(self, key) or UserDict.has_key(self, key)
'http://www.w3.org/2005/atom': '',
'http://www.w3.org/2005/Atom': '',
def _ebcdic_to_ascii(s): global _ebcdic_to_ascii_map if not _ebcdic_to_ascii_map: emap = ( 0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15, 16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31, 128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7, 144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26, 32,160,161,...
'http://backend.userland.com/blogchannelmodule': 'blogChannel',
'http://backend.userland.com/blogChannelModule': 'blogChannel',
def _ebcdic_to_ascii(s): global _ebcdic_to_ascii_map if not _ebcdic_to_ascii_map: emap = ( 0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15, 16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31, 128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7, 144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26, 32,160,161,...
'http://backend.userland.com/creativecommonsrssmodule': 'creativeCommons',
'http://backend.userland.com/creativeCommonsRssModule': 'creativeCommons',
def _ebcdic_to_ascii(s): global _ebcdic_to_ascii_map if not _ebcdic_to_ascii_map: emap = ( 0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15, 16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31, 128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7, 144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26, 32,160,161,...
'http://www.itunes.com/dtds/podcast-1.0.dtd': 'itunes', 'http://example.com/dtds/podcast-1.0.dtd': 'itunes', 'http://xmlns.com/foaf/0.1/': 'foaf', 'http://freshmeat.net/rss/fm/': 'fm',
'http://www.itunes.com/DTDs/PodCast-1.0.dtd': 'itunes', 'http://example.com/DTDs/PodCast-1.0.dtd': 'itunes',
def _ebcdic_to_ascii(s): global _ebcdic_to_ascii_map if not _ebcdic_to_ascii_map: emap = ( 0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15, 16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31, 128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7, 144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26, 32,160,161,...
'http://wellformedweb.org/commentapi/': 'wfw',
'http://wellformedweb.org/commentAPI/': 'wfw',
def _ebcdic_to_ascii(s): global _ebcdic_to_ascii_map if not _ebcdic_to_ascii_map: emap = ( 0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15, 16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31, 128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7, 144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26, 32,160,161,...
'http://schemas.xmlsoap.org/soap/envelope/': 'soap',
def _ebcdic_to_ascii(s): global _ebcdic_to_ascii_map if not _ebcdic_to_ascii_map: emap = ( 0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15, 16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31, 128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7, 144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26, 32,160,161,...
'http://www.w3.org/xml/1998/namespace': 'xml'
'http://www.w3.org/XML/1998/namespace': 'xml', 'http://schemas.pocketsoap.com/rss/myDescModule/': 'szf'
def _ebcdic_to_ascii(s): global _ebcdic_to_ascii_map if not _ebcdic_to_ascii_map: emap = ( 0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15, 16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31, 128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7, 144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26, 32,160,161,...
can_be_relative_uri = ['link', 'id', 'wfw_comment', 'wfw_commentrss', 'docs', 'url', 'href', 'comments', 'license']
_matchnamespaces = {} can_be_relative_uri = ['link', 'id', 'wfw_comment', 'wfw_commentrss', 'docs', 'url', 'href', 'comments', 'license', 'icon', 'logo']
def _ebcdic_to_ascii(s): global _ebcdic_to_ascii_map if not _ebcdic_to_ascii_map: emap = ( 0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15, 16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31, 128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7, 144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26, 32,160,161,...
self.baseuri = urlparse.urljoin(self.baseuri, baseuri)
self.baseuri = _urljoin(self.baseuri, baseuri)
def unknown_starttag(self, tag, attrs): if _debug: sys.stderr.write('start %s with %s\n' % (tag, attrs)) # normalize attrs attrs = [(k.lower(), v) for k, v in attrs] attrs = [(k, k in ('rel', 'type') and v.lower() or v) for k, v in attrs] # track xml:base and xml:lang attrsD = dict(attrs) baseuri = attrsD.get('xml:bas...
uri = uri.lower() if (prefix, uri) == (None, 'http://my.netscape.com/rdf/simple/0.9/') and not self.version:
loweruri = uri.lower() if (prefix, loweruri) == (None, 'http://my.netscape.com/rdf/simple/0.9/') and not self.version:
def trackNamespace(self, prefix, uri): uri = uri.lower() if (prefix, uri) == (None, 'http://my.netscape.com/rdf/simple/0.9/') and not self.version: self.version = 'rss090' if uri == 'http://purl.org/rss/1.0/' and not self.version: self.version = 'rss10' if uri == 'http://www.w3.org/2005/atom' and not self.version: self...
if uri == 'http://purl.org/rss/1.0/' and not self.version:
if loweruri == 'http://purl.org/rss/1.0/' and not self.version:
def trackNamespace(self, prefix, uri): uri = uri.lower() if (prefix, uri) == (None, 'http://my.netscape.com/rdf/simple/0.9/') and not self.version: self.version = 'rss090' if uri == 'http://purl.org/rss/1.0/' and not self.version: self.version = 'rss10' if uri == 'http://www.w3.org/2005/atom' and not self.version: self...
if uri == 'http://www.w3.org/2005/atom' and not self.version:
if loweruri == 'http://www.w3.org/2005/atom' and not self.version:
def trackNamespace(self, prefix, uri): uri = uri.lower() if (prefix, uri) == (None, 'http://my.netscape.com/rdf/simple/0.9/') and not self.version: self.version = 'rss090' if uri == 'http://purl.org/rss/1.0/' and not self.version: self.version = 'rss10' if uri == 'http://www.w3.org/2005/atom' and not self.version: self...
if not prefix: return if uri.find('backend.userland.com/rss') <> -1:
if loweruri.find('backend.userland.com/rss') <> -1:
def trackNamespace(self, prefix, uri): uri = uri.lower() if (prefix, uri) == (None, 'http://my.netscape.com/rdf/simple/0.9/') and not self.version: self.version = 'rss090' if uri == 'http://purl.org/rss/1.0/' and not self.version: self.version = 'rss10' if uri == 'http://www.w3.org/2005/atom' and not self.version: self...
if self.namespaces.has_key(uri): self.namespacemap[prefix] = self.namespaces[uri]
loweruri = uri if self._matchnamespaces.has_key(loweruri): self.namespacemap[prefix] = self._matchnamespaces[loweruri] self.namespacesInUse[self._matchnamespaces[loweruri]] = uri else: self.namespacesInUse[prefix or ''] = uri
def trackNamespace(self, prefix, uri): uri = uri.lower() if (prefix, uri) == (None, 'http://my.netscape.com/rdf/simple/0.9/') and not self.version: self.version = 'rss090' if uri == 'http://purl.org/rss/1.0/' and not self.version: self.version = 'rss10' if uri == 'http://www.w3.org/2005/atom' and not self.version: self...
return urlparse.urljoin(self.baseuri or '', uri)
return _urljoin(self.baseuri or '', uri)
def resolveURI(self, uri): return urlparse.urljoin(self.baseuri or '', uri)
if self.encoding and (type(output) == types.StringType):
if self.encoding and type(output) != type(u''):
def pop(self, element, stripWhitespace=1): if not self.elementstack: return if self.elementstack[-1][0] != element: return
def _start_dc_contributor(self, attrsD): self.incontributor = 1 context = self._getContext() context.setdefault('contributors', []) context['contributors'].append(FeedParserDict()) self.push('name', 0) def _end_dc_contributor(self): self._end_name() self.incontributor = 0
def _end_contributor(self): self.pop('contributor') self.incontributor = 0
self.pushContent('description', attrsD, 'text/html', self.infeed or self.inentry or self.insource)
context = self._getContext() if context.has_key('summary'): self._summaryKey = 'content' self._start_content(attrsD) else: self.pushContent('description', attrsD, 'text/html', self.infeed or self.inentry or self.insource)
def _start_description(self, attrsD): self.pushContent('description', attrsD, 'text/html', self.infeed or self.inentry or self.insource)
value = self.popContent('description') context = self._getContext() if self.intextinput: context['textinput']['description'] = value elif self.inimage: context['image']['description'] = value
if self._summaryKey == 'content': self._end_content() else: value = self.popContent('description') context = self._getContext() if self.intextinput: context['textinput']['description'] = value elif self.inimage: context['image']['description'] = value self._summaryKey = None
def _end_description(self): value = self.popContent('description') context = self._getContext() if self.intextinput: context['textinput']['description'] = value elif self.inimage: context['image']['description'] = value
self.pushContent('summary', attrsD, 'text/plain', 1)
context = self._getContext() if context.has_key('summary'): self._summaryKey = 'content' self._start_content(attrsD) else: self._summaryKey = 'summary' self.pushContent(self._summaryKey, attrsD, 'text/plain', 1)
def _start_summary(self, attrsD): self.pushContent('summary', attrsD, 'text/plain', 1)
self.popContent('summary')
if self._summaryKey == 'content': self._end_content() else: self.popContent(self._summaryKey or 'summary') self._summaryKey = None
def _end_summary(self): self.popContent('summary')
namespace = str(namespace or '').lower() if namespace.find('backend.userland.com/rss') <> -1:
lowernamespace = str(namespace or '').lower() if lowernamespace.find('backend.userland.com/rss') <> -1:
def startElementNS(self, name, qname, attrs): namespace, localname = name namespace = str(namespace or '').lower() if namespace.find('backend.userland.com/rss') <> -1: # match any backend.userland.com namespace namespace = 'http://backend.userland.com/rss' prefix = self.namespaces.get(namespace, 'unknown') if prefix: l...
prefix = self.namespaces.get(namespace, 'unknown')
lowernamespace = namespace if qname and qname.find(':') > 0: givenprefix = qname.split(':')[0] else: givenprefix = None prefix = self._matchnamespaces.get(lowernamespace, givenprefix) if givenprefix and (prefix == None or (prefix == '' and lowernamespace == '')) and not self.namespacesInUse.has_key(givenprefix): raise ...
def startElementNS(self, name, qname, attrs): namespace, localname = name namespace = str(namespace or '').lower() if namespace.find('backend.userland.com/rss') <> -1: # match any backend.userland.com namespace namespace = 'http://backend.userland.com/rss' prefix = self.namespaces.get(namespace, 'unknown') if prefix: l...
namespace = (namespace or '').lower() prefix = self.namespaces.get(namespace, '')
lowernamespace = (namespace or '').lower() prefix = self._matchnamespaces.get(lowernamespace, '')
def startElementNS(self, name, qname, attrs): namespace, localname = name namespace = str(namespace or '').lower() if namespace.find('backend.userland.com/rss') <> -1: # match any backend.userland.com namespace namespace = 'http://backend.userland.com/rss' prefix = self.namespaces.get(namespace, 'unknown') if prefix: l...
namespace = str(namespace).lower() prefix = self.namespaces.get(namespace, '')
lowernamespace = str(namespace or '').lower() if qname and qname.find(':') > 0: givenprefix = qname.split(':')[0] else: givenprefix = '' prefix = self._matchnamespaces.get(lowernamespace, givenprefix)
def endElementNS(self, name, qname): namespace, localname = name namespace = str(namespace).lower() prefix = self.namespaces.get(namespace, '') if prefix: localname = prefix + ':' + localname localname = str(localname).lower() self.unknown_endtag(localname)
data = re.sub(r'<(\S+)/>', r'<\1></\1>', data)
data = re.sub(r'<([^<\s]+?)\s*/>', self._shorttag_replace, data)
def feed(self, data): data = re.compile(r'<!((?!DOCTYPE|--|\[))', re.IGNORECASE).sub(r'&lt;!\1', data) data = re.sub(r'<(\S+)/>', r'<\1></\1>', data) data = data.replace('&#39;', "'") data = data.replace('&#34;', '"') if self.encoding and (type(data) == types.UnicodeType): data = data.encode(self.encoding) sgmllib.SGML...
if self.encoding and (type(data) == types.UnicodeType):
if self.encoding and type(data) == type(u''):
def feed(self, data): data = re.compile(r'<!((?!DOCTYPE|--|\[))', re.IGNORECASE).sub(r'&lt;!\1', data) data = re.sub(r'<(\S+)/>', r'<\1></\1>', data) data = data.replace('&#39;', "'") data = data.replace('&#34;', '"') if self.encoding and (type(data) == types.UnicodeType): data = data.encode(self.encoding) sgmllib.SGML...
strattrs = ''.join([' %s="%s"' % (key, value) for key, value in attrs])
uattrs = [] for key, value in attrs: if type(value) != type(u''): value = unicode(value, self.encoding) uattrs.append((unicode(key, self.encoding), value)) strattrs = u''.join([u' %s="%s"' % (key, value) for key, value in uattrs]).encode(self.encoding)
def unknown_starttag(self, tag, attrs): # called for each start tag # attrs is a list of (attr, value) tuples # e.g. for <pre class='screen'>, tag='pre', attrs=[('class', 'screen')] if _debug: sys.stderr.write('_BaseHTMLProcessor, unknown_starttag, tag=%s\n' % tag) strattrs = ''.join([' %s="%s"' % (key, value) for key,...
self.pieces.append('</%(tag)s>' % locals())
self.pieces.append("</%(tag)s>" % locals())
def unknown_endtag(self, tag): # called for each end tag, e.g. for </pre>, tag will be 'pre' # Reconstruct the original end tag. if tag not in self.elements_no_end_tag: self.pieces.append('</%(tag)s>' % locals())
return urlparse.urljoin(self.baseuri, uri)
return _urljoin(self.baseuri, uri)
def resolveURI(self, uri): return urlparse.urljoin(self.baseuri, uri)
if _mxtidy and TIDY_MARKUP: nerrors, nwarnings, data, errordata = _mxtidy.tidy(data, output_xhtml=1, numeric_entities=1, wrap=0, char_encoding='utf8') if data.count('<body'): data = data.split('<body', 1)[1] if data.count('>'): data = data.split('>', 1)[1] if data.count('</body'): data = data.split('</body', 1)[0]
if TIDY_MARKUP: _tidy = None for tidy_interface in PREFERRED_TIDY_INTERFACES: try: if tidy_interface == "uTidy": from tidy import parseString as _utidy def _tidy(data, **kwargs): return str(_utidy(data, **kwargs)) break elif tidy_interface == "mxTidy": from mx.Tidy import Tidy as _mxtidy def _tidy(data, **kwargs): ne...
def _sanitizeHTML(htmlSource, encoding): p = _HTMLSanitizer(encoding) p.feed(htmlSource) data = p.output() if _mxtidy and TIDY_MARKUP: nerrors, nwarnings, data, errordata = _mxtidy.tidy(data, output_xhtml=1, numeric_entities=1, wrap=0, char_encoding='utf8') if data.count('<body'): data = data.split('<body', 1)[1] if da...
class _FeedURLHandler(urllib2.HTTPRedirectHandler, urllib2.HTTPDefaultErrorHandler):
class _FeedURLHandler(urllib2.HTTPDigestAuthHandler, urllib2.HTTPRedirectHandler, urllib2.HTTPDefaultErrorHandler):
def _sanitizeHTML(htmlSource, encoding): p = _HTMLSanitizer(encoding) p.feed(htmlSource) data = p.output() if _mxtidy and TIDY_MARKUP: nerrors, nwarnings, data, errordata = _mxtidy.tidy(data, output_xhtml=1, numeric_entities=1, wrap=0, char_encoding='utf8') if data.count('<body'): data = data.split('<body', 1)[1] if da...
re.compile('(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})\.\d+')
re.compile('(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})(\.\d+)?')
def _parse_date_nate(dateString): '''Parse a string according to the Nate 8-bit date format''' m = _korean_nate_date_re.match(dateString) if not m: return hour = int(m.group(5)) ampm = m.group(4) if (ampm == _korean_pm): hour += 12 hour = str(hour) if len(hour) == 1: hour = '0' + hour w3dtfdate = '%(year)s-%(month)s-%(...
result['url'] = f.url
result['href'] = f.url
def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=[]): '''Parse a feed from a URL, file, stream, or string''' result = FeedParserDict() result['feed'] = FeedParserDict() result['entries'] = [] if _XML_AVAILABLE: result['bozo'] = 0 if type(handlers) == types.InstanceType:...
baseuri = http_headers.get('content-location', result.get('url'))
baseuri = http_headers.get('content-location', result.get('href'))
def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=[]): '''Parse a feed from a URL, file, stream, or string''' result = FeedParserDict() result['feed'] = FeedParserDict() result['entries'] = [] if _XML_AVAILABLE: result['bozo'] = 0 if type(handlers) == types.InstanceType:...
for proposed_encoding in (result['encoding'], xml_encoding, sniffed_xml_encoding, 'utf-8', 'windows-1252'):
for proposed_encoding in (result['encoding'], xml_encoding, sniffed_xml_encoding): if not proposed_encoding: continue
def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=[]): '''Parse a feed from a URL, file, stream, or string''' result = FeedParserDict() result['feed'] = FeedParserDict() result['entries'] = [] if _XML_AVAILABLE: result['bozo'] = 0 if type(handlers) == types.InstanceType:...
if not proposed_encoding: continue
tried_encodings.append(proposed_encoding)
def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=[]): '''Parse a feed from a URL, file, stream, or string''' result = FeedParserDict() result['feed'] = FeedParserDict() result['entries'] = [] if _XML_AVAILABLE: result['bozo'] = 0 if type(handlers) == types.InstanceType:...
known_encoding = 1 use_strict_parser = 1
known_encoding = use_strict_parser = 1
def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=[]): '''Parse a feed from a URL, file, stream, or string''' result = FeedParserDict() result['feed'] = FeedParserDict() result['entries'] = [] if _XML_AVAILABLE: result['bozo'] = 0 if type(handlers) == types.InstanceType:...
tried_encodings.append(proposed_encoding)
if (not known_encoding) and chardet: try: proposed_encoding = chardet.detect(data)['encoding'] if proposed_encoding and (proposed_encoding not in tried_encodings): tried_encodings.append(proposed_encoding) data = _toUTF8(data, proposed_encoding) known_encoding = use_strict_parser = 1 except: pass if (not known_encodin...
def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=[]): '''Parse a feed from a URL, file, stream, or string''' result = FeedParserDict() result['feed'] = FeedParserDict() result['entries'] = [] if _XML_AVAILABLE: result['bozo'] = 0 if type(handlers) == types.InstanceType:...
page = 'pages/' + parts[0].split('/')[1] + '.tmpl'
tmpl = parts[0].split('/')[1] if tmpl.endswith('.css'): self.mime_type = 'text/css' page = 'pages/' + tmpl + '.tmpl'
def process_request(self): if not self.require_auth(param.auth_dict): return try: parts = self.path.split('?', 2) path = parts[0] if self.path in ['', '/']: self.browser_output(301, None, 'This document has moved.', ['Location: /view']) return vars = [] if len(parts) == 2: self.input.update(dict(cgi.parse_qsl(parts[1],...
print 'E' * 16, 'no link in ', item
def normalize(item, f): # get rid of RDF lossage... for key in ['title', 'link', 'created', 'modified', 'author', 'content', 'content_encoded', 'description']: if type(item.get(key)) == list: if len(item[key]) == 1: item[key] = item[key][0] else: # XXX not really sure how to handle these cases print 'E' * 16, 'ambiguou...
if not f['channel']: return 3, None
def add_feed(feed_xml): """Try to add a feed. Return values: tuple (status, feed_uid) -1: unknown error 0: feed added normally 1: feed added via autodiscovery 2: feed not added, already present 3: feed not added, connection or parse error""" from singleton import db c = db.cursor() try: f = feedparser.parse(feed_xml) n...
'htmlUrl': str(f['channel']['link']),
'htmlUrl': str(f.feed['link']),
def add_feed(feed_xml): """Try to add a feed. Return values: tuple (status, feed_uid) -1: unknown error 0: feed added normally 1: feed added via autodiscovery 2: feed not added, already present 3: feed not added, connection or parse error""" from singleton import db c = db.cursor() try: f = feedparser.parse(feed_xml) n...
'title': f['channel']['title'].encode('ascii', 'xmlcharrefreplace'), 'desc': f['channel']['description'].encode('ascii', 'xmlcharrefreplace')
'title': f.feed['title'].encode('ascii', 'xmlcharrefreplace'), 'desc': f.feed['description'].encode('ascii', 'xmlcharrefreplace')
def add_feed(feed_xml): """Try to add a feed. Return values: tuple (status, feed_uid) -1: unknown error 0: feed added normally 1: feed added via autodiscovery 2: feed not added, already present 3: feed not added, connection or parse error""" from singleton import db c = db.cursor() try: f = feedparser.parse(feed_xml) n...
if 'title' not in f['channel'] and 'link' not in f['channel'] and \
if 'title' not in f.feed and 'link' not in f.feed and \
def update_feed(db, c, f, feed_uid, feed_xml, feed_etag, feed_modified): print feed_xml # check for errors - HTTP code 304 means no change if 'title' not in f['channel'] and 'link' not in f['channel'] and \ ('status' not in f or f['status'] not in [304]): # error or timeout - increment error count c.execute("""update f...
for key in f['channel']:
for key in f.feed:
def process_parsed_feed(f, c, feed_uid): # the Radio convention is reverse chronological order f['items'].reverse() for item in f['items']: normalize.normalize(item, f) skip = 0 filter_dict = {} for key in f['channel']: try: filter_dict['feed_' + key] = f['channel'][key] except KeyError: pass filter_dict.update(item) f...
filter_dict['feed_' + key] = f['channel'][key]
filter_dict['feed_' + key] = f.feed[key]
def process_parsed_feed(f, c, feed_uid): # the Radio convention is reverse chronological order f['items'].reverse() for item in f['items']: normalize.normalize(item, f) skip = 0 filter_dict = {} for key in f['channel']: try: filter_dict['feed_' + key] = f['channel'][key] except KeyError: pass filter_dict.update(item) f...
c.execute("""update fm_feeds set feed_status=%d where item_feed_uid=%d""" \
c.execute("""update fm_feeds set feed_status=%d where feed_uid=%d""" \
def set_status(feed_uid, status): feed_uid = int(feed_uid) status = int(status) from singleton import db c = db.cursor() try: c.execute("""update fm_feeds set feed_status=%d where item_feed_uid=%d""" \ % (status, feed_uid)) db.commit() finally: c.close()
if time.mktime(date_tuple) > time.time():
if date_tuple > time.gmtime():
def fix_date(date_tuple): if not date_tuple: return date_tuple if time.mktime(date_tuple) > time.time(): # feedparser's parsed date tuple has no DST indication, we need to force it # because there is no UTC equivalent of mktime() date_tuple = date_tuple[:-1] + (-1,) date_tuple = time.localtime(time.mktime(date_tuple) -...
item['title_words'] = item['title_lc'].translate(punctuation).split()
item['title_words'] = str(item['title_lc']).translate(punctuation).split()
def normalize(item, f): # get rid of RDF lossage... for key in ['title', 'link', 'created', 'modified', 'author', 'content', 'content_encoded', 'description']: if type(item.get(key)) == list and len(item[key]) == 1: item[key] = item[key][0] if isinstance(item.get(key), dict) and 'value' in item[key]: item[key] = item[k...
self.tmpl_cache[tmpl] = __import__(tmpl)
filename = tmpl_dir + tmpl + '.pyc' self.tmpl_cache[tmpl] = imp.load_module( 'tmpl_' + tmpl, open(filename, 'rb'), filename, ('pyc', 'rb', imp.PY_COMPILED))
def use_template(self, tmpl, searchlist): """Use compiled-on-demand versions of Cheetah templates for speed, specially with CGI """ self.set_mime_type(tmpl) tmpl = tmpl.replace('.', '_') modname = 'pages/' + tmpl page = modname + '.tmpl' compiled = modname + '.py' try: compiled_t = os.stat(compiled)[stat.ST_CTIME] exce...
return self.autodiscovery.get(
url = self.autodiscovery.get(
def feed_url(self, page_url): page_data = urllib2.urlopen(page_url).read() self.feed(page_data) # Atom has cleaner semantics than RSS, so give it priority return self.autodiscovery.get( 'atom', self.autodiscovery.get('rss'))
if not f.feed:
if not f.feed or ('link' not in f.feed or 'title' not in f.feed):
def add_feed(feed_xml): """Try to add a feed. Returns a tuple (feed_uid, num_added, num_filtered)""" from singleton import db c = db.cursor() try: # verify the feed f = feedparser.parse(feed_xml) if not f.feed: # try autodiscovery try: feed_xml = AutoDiscoveryHandler().feed_url(feed_xml) except HTMLParser.HTMLParseErro...
def _xmlescape(data,entities={}):
def _xmlescape(data):
def _xmlescape(data,entities={}): data = data.replace('&', '&amp;') data = data.replace('>', '&gt;') data = data.replace('<', '&lt;') for char, entity in entities: data = data.replace(char, entity) return data
for char, entity in entities: data = data.replace(char, entity)
def _xmlescape(data,entities={}): data = data.replace('&', '&amp;') data = data.replace('>', '&gt;') data = data.replace('<', '&lt;') for char, entity in entities: data = data.replace(char, entity) return data