本文整理汇总了Python中Utf8类的典型用法代码示例。如果您正苦于以下问题:Python Utf8类的具体用法?Python Utf8怎么用?Python Utf8使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Utf8类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addCache
def addCache(url, text):
# this line should be moved to a more suitable place
createCacheFolder()
try:
if folderSize(cacheDir) > 4.0 or freeSpace(cacheDir) < 2.0: #10mb
for f in os.listdir(cacheDir):
file = os.path.join(cacheDir, f)
printl("RM: " + str(file), __name__)
os.remove(file)
cacheFile = re.sub(r'\W', "", url).strip()
cacheFileName = cacheDir + u"/" + cacheFile + u".cache"
if text is not None and len(text) > 0:
f = Utf8.Utf8(cacheFileName, "w")
f.write(text)
f.close
if os.path.getsize(Utf8.utf8ToLatin(cacheFileName)) == 0:
os.remove(Utf8.utf8ToLatin(cacheFileName))
except Exception, ex:
printl("Exception (ef): " + str(ex), __name__, "E")
printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
示例2: isNfoAvailable
def isNfoAvailable(self, name):
try:
printl("Check presence of nfo file: " + Utf8.utf8ToLatin(name + u".nfo"), self, "I")
if os.path.isfile(Utf8.utf8ToLatin(name + u".nfo")):
return True
except Exception, ex:
printl("Exception (ef): " + str(ex), self, "E")
示例3: isEnigma2Recording
def isEnigma2Recording(self, name):
try:
if os.path.isfile(Utf8.utf8ToLatin(name + u".meta")):
printl("Found E2 meta file: " + str(Utf8.utf8ToLatin(name + u".meta")), self)
return True
except Exception, ex:
printl("Exception (ef): " + str(ex), self, "E")
示例4: removeFromCache
def removeFromCache(url):
try:
cacheFile = re.sub(r'\W', "", url).strip()
cacheFileName = cacheDir + u"/" + cacheFile + u".cache"
if os.path.isfile(Utf8.utf8ToLatin(cacheFileName)):
os.remove(Utf8.utf8ToLatin(cacheFileName))
except Exception, ex:
printl("Exception (ef): " + str(ex), __name__, "E")
printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
示例5: setValerieInfoLastAccessTime
def setValerieInfoLastAccessTime(self, path):
try:
if os.path.isfile(Utf8.utf8ToLatin(path + u"/valerie.info")):
time = int(os.path.getctime(Utf8.utf8ToLatin(path + u"/valerie.info")))
f = Utf8.Utf8(path + u"/.access", "w")
time = f.write(str(time) + u"\n")
f.close()
elif os.path.isfile(Utf8.utf8ToLatin(path + u"/.access")):
os.remove(Utf8.utf8ToLatin(path + u"/.access"))
except Exception, ex:
printl("Exception (ef): " + str(ex), self, "E")
示例6: getValerieInfoAccessTime
def getValerieInfoAccessTime(self, path):
time = 0
try:
if os.path.isfile(Utf8.utf8ToLatin(path + u"/valerie.info")):
try:
time = int(os.path.getctime(Utf8.utf8ToLatin(path + u"/valerie.info")))
except Exception, ex:
printl("Exception: " + str(ex), self)
printl("\t" + str(Utf8.utf8ToLatin(path + u"/valerie.info")), self)
except Exception, ex:
printl("Exception (ef): " + str(ex), self, "E")
示例7: checkCache
def checkCache(url):
try:
cacheFile = re.sub(r'\W', "", url).strip()
cacheFileName = cacheDir + u"/" + cacheFile + u".cache"
rtv = None
if os.path.isfile(Utf8.utf8ToLatin(cacheFileName)):
if os.path.getsize(Utf8.utf8ToLatin(cacheFileName)) == 0:
os.remove(Utf8.utf8ToLatin(cacheFileName))
return rtv
f = Utf8.Utf8(cacheDir + u"/" + cacheFile + u".cache", "r")
rtv = f.read()
f.close()
except Exception, ex:
printl("Exception (ef): " + str(ex), __name__, "E")
printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
示例8: getGenre
def getGenre(self, info, html):
printl("->", self)
genre = self.getDetails(html)
if genre is None:
printl("<- (if genre is None: a)", self, "W")
return None
#print "genre", genre
pos = genre.find(self.DIV_GENRE_START)
if pos < 0:
printl("Details " + genre, self, "W")
printl("<- (if pos < 0: b)", self, "W")
return None
genre = genre[pos + len(self.DIV_GENRE_START):]
pos = genre.find(self.DIV_GENRE_END)
if pos < 0:
printl("<- (if pos < 0: c)", self, "W")
return None
genre = genre[0:pos]
genre = genre.strip()
if len(genre) < 3:
printl("<- (en(genre) < 3)", self, "W")
return None
info.Genres = u""
genres = genre.split(", ")
for genre in genres:
info.Genres += genre + u"|"
if len(info.Genres) > 1:
info.Genres = info.Genres[:len(info.Genres) - 1]
printl("<- Genres: " + Utf8.utf8ToLatin(info.Genres), self)
return info
示例9: getPlot
def getPlot(self, info, html):
printl("->", self)
plot = self.getDetails(html)
if plot is None:
printl("<- (if plot is None: a)", self, "W")
return None
#print "plot", plot
pos = plot.find(self.DIV_PLOT_START)
if pos < 0:
printl("Details " + plot, self, "W")
printl("<- (if pos < 0: b)", self, "W")
return None
plot = plot[pos + len(self.DIV_PLOT_START):]
pos = plot.find(self.DIV_PLOT_END)
if pos < 0:
printl("<- (if pos < 0: c)", self, "W")
return None
plot = plot[0:pos]
plot = plot.strip()
info.Plot = plot
info.Plot += u" [M.IMDB.COM]"
printl("<- Plot: " + Utf8.utf8ToLatin(plot), self)
return info
示例10: _fillMediaInfo
def _fillMediaInfo(self, m, key_value_dict):
printl("->", self, "S")
printl(key_value_dict, self)
for key in key_value_dict.keys():
try:
typeOfValue = self._getTypeOfValue(key_value_dict[key])
if (typeOfValue == "int"):
# To avoid null Values
if key_value_dict[key] is None or key_value_dict[key] == "" or key_value_dict[key] == "None":
value = None
else:
value = int(key_value_dict[key])
elif (typeOfValue == "none"):
pass
else:
# check is in Utf8
if not isinstance(key_value_dict[key], unicode):
try:
value = Utf8.stringToUtf8(key_value_dict[key])
except Exception, ex:
printl("Key conversion to Utf8 error: "+ repr(key) + " Ex: " + str(ex), self)
value = key_value_dict[key]
else:
value = key_value_dict[key]
示例11: getXml
def getXml(url, rawXml=None, cache=True):
if rawXml is None:
rawXml = getText(url, cache=cache)
if rawXml is None:
return None
decodedXml = None
try:
decodedXml = minidom.parseString(rawXml.encode( "utf-8", 'ignore' ))
printl("encoded utf-8")
return decodedXml
except Exception, ex:
printl("minidom.parseString as utf-8 failed, retrieing as latin-1. Ex: " + str(ex), __name__, "W")
try:
decodedXml = minidom.parseString(rawXml.encode( "latin-1", 'ignore' ))
printl("encoded latin-1")
return decodedXml
except Exception, ex:
printl("minidom.parseString as utf-8 failed, retrieing as windows-1252. Ex: " + str(ex), __name__, "W")
try:
decodedXml = minidom.parseString(rawXml.encode( "windows-1252", 'ignore' ))
printl("encoded iso8859-1")
return decodedXml
except Exception, ex:
printl("minidom.parseString as utf-8 failed, retrieing as utf-8. Ex: " + str(ex), __name__, "W")
try:
decodedXml = minidom.parseString(rawXml.decode("cp1252").encode("utf-8"))
printl("encoded cp1252")
return decodedXml
except Exception, ex:
printl("minidom.parseString as utf-8 and latin-1 failed, ignoring. Ex: " + str(ex), __name__, "E")
printl("URL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
printl("<" + str(type(ex)) + "> Ex: " + str(ex), __name__, "E")
示例12: cleanValuesOfMedia
def cleanValuesOfMedia(self, media):
if media.ImdbId == u"tt0000000":
media.ImdbId = u"";
if media.TheTvDbId == u"0":
media.TheTvDbId = u"";
if media.TmDbId == u"0":
media.TmDbId = u"";
if media.Year == -1:
media.Year = None;
if media.Month == -1:
media.Month = None;
if media.Day == -1:
media.Day = None;
if media.Season == -1:
media.Season = None;
if media.Episode == -1:
media.Episode = None;
if media.Runtime == 0:
media.Runtime = None;
if media.Popularity == 0:
media.Popularity = None;
if media.MediaType is None:
media.MediaType = MediaInfo.UNKNOWN;
# ERR title... don't come in UTF-8
if not isinstance(media.Path, unicode):
media.Path = Utf8.stringToUtf8(media.Path)
if not isinstance(media. Filename, unicode):
media.Filename = Utf8.stringToUtf8(media.Filename)
if not isinstance(media.Extension, unicode):
media.Extension = Utf8.stringToUtf8(media.Extension)
if not isinstance(media.Title, unicode):
media.Title = Utf8.stringToUtf8(media.Title)
if not isinstance(media.Resolution, unicode):
media.Resolution = Utf8.stringToUtf8(media.Resolution)
if not isinstance(media.Sound, unicode):
media.Sound = Utf8.stringToUtf8(media.Sound)
if not isinstance(media.Plot, unicode):
media.Plot = Utf8.stringToUtf8(media.Plot)
if not isinstance(media.Genres, unicode):
media.Genres = Utf8.stringToUtf8(media.Genres)
if not isinstance(media.Tag, unicode):
media.Tag = Utf8.stringToUtf8(media.Tag)
if not isinstance(media.Tag, unicode):
media.Tag = Utf8.stringToUtf8(media.Tag)
示例13: getHtml
def getHtml(url, cache=True):
try:
rawHtml = getText(url, cache=cache)
decodedHtml = None
if rawHtml is not None:
decodedHtml = decode_htmlentities(rawHtml)
except Exception, ex:
printl("Exception (ef): " + str(ex), __name__, "E")
printl("\tURL: " + str(Utf8.utf8ToLatin(url)), __name__, "E")
示例14: _verifyAndDeleteMissingFiles
def _verifyAndDeleteMissingFiles(self, records):
for m in records:
# don't verify series, will remaian with episodes count =0 is needed
if m.isTypeSerie():
continue
path = m.Path + u"/" + m.Filename + u"." + m.Extension
#printl("path: " + path, self)
if os.path.exists(Utf8.utf8ToLatin(path)) is False:
self.dbHandler.markAsMissing(m.Id)
示例15: _setFileInfo
def _setFileInfo(self, m):
if not isinstance(m.Path, unicode):
m.Path = Utf8.stringToUtf8(m.Path)
if not isinstance(m.Filename, unicode):
m.Filename = Utf8.stringToUtf8(m.Filename)
if not isinstance(m.Extension, unicode):
m.Extension = Utf8.stringToUtf8(m.Extension)
path = Utf8.utf8ToLatin(str(m.Path) + u"/" + str(m.Filename) + u"." + str(m.Extension))
if os.path.exists(path):
try:
m.FileCreation = os.stat(path).st_mtime
m.FileSize = os.stat(path).st_size
#m.CRCSize = 100
#m.CRC = self.getCRC32OfMedia(m)
except Exception, ex:
printl("Exception(" + str(type(ex)) + "): " + str(ex), self, "W")
m.FileCreation = 0