本文整理汇总了Python中sickrage.helper.encoding.ss函数的典型用法代码示例。如果您正苦于以下问题:Python ss函数的具体用法?Python ss怎么用?Python ss使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ss函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ex
def ex(e):
"""
:param e: The exception to convert into a unicode string
:return: A unicode string from the exception text if it exists
"""
message = u''
if not e or not e.args:
return message
for arg in e.args:
if arg is not None:
if isinstance(arg, (str, unicode)):
fixed_arg = ss(arg)
else:
try:
fixed_arg = u'error %s' % ss(str(arg))
except Exception:
fixed_arg = None
if fixed_arg:
if not message:
message = fixed_arg
else:
message = '%s : %s' % (message, fixed_arg)
return message
开发者ID:BreizhCat,项目名称:SickRage,代码行数:28,代码来源:exceptions.py
示例2: ex
def ex(e):
"""
:param e: The exception to convert into a unicode string
:return: A unicode string from the exception text if it exists
"""
message = u''
if not e or not e.args:
return message
for arg in e.args:
if arg is not None:
if isinstance(arg, (str, text_type)):
fixed_arg = ss(arg)
else:
try:
fixed_arg = u'error %s' % ss(str(arg))
except Exception:
fixed_arg = None
if fixed_arg:
if not message:
message = fixed_arg
else:
try:
message = u'{} : {}'.format(message, fixed_arg)
except UnicodeError:
message = u'{} : {}'.format(
text_type(message, errors='replace'),
text_type(fixed_arg, errors='replace'))
return message
开发者ID:Eiber,项目名称:SickRage-Medusa,代码行数:33,代码来源:exceptions.py
示例3: processEpisode
def processEpisode(self, proc_dir=None, nzbName=None, jobName=None, quiet=None, process_method=None, force=None,
is_priority=None, delete_on='0', failed='0', type='auto', *args, **kwargs):
nzb_name = nzbName
def argToBool(argument):
if isinstance(argument, basestring):
_arg = argument.strip().lower()
else:
_arg = argument
if _arg in ['1', 'on', 'true', True]:
return True
elif _arg in ['0', 'off', 'false', False]:
return False
return argument
if not proc_dir:
return self.redirect('/home/postprocess/')
else:
nzb_name = ss(nzb_name) if nzb_name else nzb_name
result = processTV.processDir(
ss(proc_dir), nzb_name, process_method=process_method, force=argToBool(force),
is_priority=argToBool(is_priority), delete_on=argToBool(delete_on), failed=argToBool(failed), proc_type=type
)
if quiet is not None and int(quiet) == 1:
return result
result = result.replace('\n', '<br>\n')
return self._genericMessage('Postprocessing results', result)
开发者ID:bitzorro,项目名称:SickRage,代码行数:32,代码来源:post_process.py
示例4: ex
def ex(e):
"""
:param e: The exception to convert into a six.text_type string
:return: A six.text_type string from the exception text if it exists
"""
message = ''
if not e or not e.args:
return message
for arg in e.args:
if arg is not None:
if isinstance(arg, six.string_types):
fixed_arg = ss(arg)
else:
try:
fixed_arg = 'error {0}'.format(ss(str(arg)))
except Exception:
fixed_arg = None
if fixed_arg:
if not message:
message = fixed_arg
else:
try:
message = '{0} : {1}'.format(message, fixed_arg)
except UnicodeError:
message = '{0} : {1}'.format(
six.text_type(message, errors='replace'),
six.text_type(fixed_arg, errors='replace'))
return message
开发者ID:shtrom,项目名称:SickRage,代码行数:33,代码来源:exceptions.py
示例5: ex
def ex(e):
"""
Returns a unicode string from the exception text if it exists.
"""
e_message = u""
if not e or not e.args:
return e_message
for arg in e.args:
if arg is not None:
if isinstance(arg, (str, unicode)):
fixed_arg = ss(arg)
else:
try:
fixed_arg = u"error " + ss(str(arg))
except:
fixed_arg = None
if fixed_arg:
if not e_message:
e_message = fixed_arg
else:
e_message = e_message + " : " + fixed_arg
return e_message
开发者ID:xNovax,项目名称:SickRage,代码行数:28,代码来源:exceptions.py
示例6: _send_to_kodi
def _send_to_kodi(self, command, host=None, username=None, password=None):
"""Handles communication to KODI servers via HTTP API
Args:
command: Dictionary of field/data pairs, encoded via urllib and passed to the KODI API via HTTP
host: KODI webserver host:port
username: KODI webserver username
password: KODI webserver password
Returns:
Returns response.result for successful commands or False if there was an error
"""
# fill in omitted parameters
if not username:
username = sickbeard.KODI_USERNAME
if not password:
password = sickbeard.KODI_PASSWORD
if not host:
logger.log(u'No KODI host passed, aborting update', logger.WARNING)
return False
for key in command:
if isinstance(command[key], unicode):
command[key] = command[key].encode('utf-8')
enc_command = urllib.urlencode(command)
logger.log(u"KODI encoded API command: " + enc_command, logger.DEBUG)
url = 'http://%s/kodiCmds/kodiHttp/?%s' % (host, enc_command)
try:
req = urllib2.Request(url)
# if we have a password, use authentication
if password:
base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
authheader = "Basic %s" % base64string
req.add_header("Authorization", authheader)
logger.log(u"Contacting KODI (with auth header) via url: " + ss(url), logger.DEBUG)
else:
logger.log(u"Contacting KODI via url: " + ss(url), logger.DEBUG)
try:
response = urllib2.urlopen(req)
except (httplib.BadStatusLine, urllib2.URLError) as e:
logger.log(u"Couldn't contact KODI HTTP at %r : %r" % (url, ex(e)), logger.DEBUG)
return False
result = response.read().decode(sickbeard.SYS_ENCODING)
response.close()
logger.log(u"KODI HTTP response: " + result.replace('\n', ''), logger.DEBUG)
return result
except Exception as e:
logger.log(u"Couldn't contact KODI HTTP at %r : %r" % (url, ex(e)), logger.DEBUG)
return False
开发者ID:mexicanamerican,项目名称:SickRage,代码行数:58,代码来源:kodi.py
示例7: _send_to_kodi_json
def _send_to_kodi_json(self, command, host=None, username=None, password=None):
"""Handles communication to KODI servers via JSONRPC
Args:
command: Dictionary of field/data pairs, encoded via urllib and passed to the KODI JSON-RPC via HTTP
host: KODI webserver host:port
username: KODI webserver username
password: KODI webserver password
Returns:
Returns response.result for successful commands or False if there was an error
"""
# fill in omitted parameters
if not username:
username = sickbeard.KODI_USERNAME
if not password:
password = sickbeard.KODI_PASSWORD
if not host:
logger.log(u'No KODI host passed, aborting update', logger.WARNING)
return False
command = command.encode('utf-8')
logger.log(u"KODI JSON command: " + command, logger.DEBUG)
url = 'http://%s/jsonrpc' % (host)
try:
req = urllib2.Request(url, command)
req.add_header("Content-type", "application/json")
# if we have a password, use authentication
if password:
base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
authheader = "Basic %s" % base64string
req.add_header("Authorization", authheader)
logger.log(u"Contacting KODI (with auth header) via url: " + ss(url), logger.DEBUG)
else:
logger.log(u"Contacting KODI via url: " + ss(url), logger.DEBUG)
try:
response = urllib2.urlopen(req)
except (httplib.BadStatusLine, urllib2.URLError), e:
logger.log(u"Error while trying to retrieve KODI API version for " + host + ": " + ex(e),
logger.WARNING)
return False
# parse the json result
try:
result = json.load(response)
response.close()
logger.log(u"KODI JSON response: " + str(result), logger.DEBUG)
return result # need to return response for parsing
except ValueError, e:
logger.log(u"Unable to decode JSON: " + str(response.read()), logger.WARNING)
return False
开发者ID:mexicanamerican,项目名称:SickRage,代码行数:56,代码来源:kodi.py
示例8: __str__
def __str__(self):
to_return = ""
if self.series_name is not None:
to_return += ss(self.series_name)
if self.season_number is not None:
to_return += 'S' + ss(self.season_number).zfill(2)
if self.episode_numbers and len(self.episode_numbers):
for e in self.episode_numbers:
to_return += 'E' + ss(e).zfill(2)
if self.is_air_by_date:
to_return += ss(self.air_date)
if self.ab_episode_numbers:
to_return += ' [ABS: ' + ss(self.ab_episode_numbers) + ']'
if self.version and self.is_anime is True:
to_return += ' [ANIME VER: ' + ss(self.version) + ']'
if self.release_group:
to_return += ' [GROUP: ' + self.release_group + ']'
to_return += ' [ABD: ' + ss(self.is_air_by_date) + ']'
to_return += ' [ANIME: ' + ss(self.is_anime) + ']'
to_return += ' [whichReg: ' + ss(self.which_regex) + ']'
return to_return
开发者ID:coderbone,项目名称:SickRage,代码行数:25,代码来源:parser.py
示例9: _convert_number
def _convert_number(org_number):
"""
Convert org_number into an integer
org_number: integer or representation of a number: string or unicode
Try force converting to int first, on error try converting from Roman numerals
returns integer or 0
"""
try:
# try forcing to int
if org_number:
number = int(org_number)
else:
number = 0
except Exception:
# on error try converting from Roman numerals
roman_to_int_map = (
('M', 1000), ('CM', 900), ('D', 500), ('CD', 400), ('C', 100),
('XC', 90), ('L', 50), ('XL', 40), ('X', 10),
('IX', 9), ('V', 5), ('IV', 4), ('I', 1)
)
roman_numeral = ss(org_number).upper()
number = 0
index = 0
for numeral, integer in roman_to_int_map:
while roman_numeral[index:index + len(numeral)] == numeral:
number += integer
index += len(numeral)
return number
开发者ID:coderbone,项目名称:SickRage,代码行数:33,代码来源:parser.py
示例10: _write_image
def _write_image(self, image_data, image_path, obj = None):
"""
Saves the data in image_data to the location image_path. Returns True/False
to represent success or failure.
image_data: binary image data to write to file
image_path: file location to save the image to
"""
# don't bother overwriting it
if ek(os.path.isfile, image_path):
logger.log(u"Image already exists, not downloading", logger.DEBUG)
return False
image_dir = ek(os.path.dirname, image_path)
if not image_data:
logger.log(u"Unable to retrieve image to save in %s, skipping" % (ss(image_path)), logger.DEBUG)
return False
try:
if not ek(os.path.isdir, image_dir):
logger.log(u"Metadata dir didn't exist, creating it at " + image_dir, logger.DEBUG)
ek(os.makedirs, image_dir)
helpers.chmodAsParent(image_dir)
outFile = ek(open, image_path, 'wb')
outFile.write(image_data)
outFile.close()
helpers.chmodAsParent(image_path)
except IOError, e:
logger.log(
u"Unable to write image to " + image_path + " - are you sure the show folder is writable? " + ex(e),
logger.ERROR)
return False
开发者ID:logo000,项目名称:SickRage,代码行数:35,代码来源:generic.py
示例11: test_email
def test_email(self):
"""
Test email notifications
"""
email_notifier = EmailNotifier()
# Per-show-email notifications were added early on and utilized a different format than the other notifiers.
# Therefore, to test properly (and ensure backwards compatibility), this routine will test shows that use
# both the old and the new storage methodology
legacy_test_emails = "[email protected],[email protected],[email protected]"
test_emails = "[email protected],[email protected],[email protected]"
for show in self.legacy_shows:
showid = self._get_showid_by_showname(show.name)
self.mydb.action("UPDATE tv_shows SET notify_list = ? WHERE show_id = ?", [legacy_test_emails, showid])
for show in self.shows:
showid = self._get_showid_by_showname(show.name)
Home.saveShowNotifyList(show=showid, emails=test_emails)
# Now, iterate through all shows using the email list generation routines that are used in the notifier proper
shows = self.legacy_shows+self.shows
for show in shows:
for episode in show.episodes:
ep_name = ss(episode._format_pattern('%SN - %Sx%0E - %EN - ')+episode.quality) # pylint: disable=protected-access
show_name = email_notifier._parseEp(ep_name) # pylint: disable=protected-access
recipients = email_notifier._generate_recipients(show_name) # pylint: disable=protected-access
self._debug_spew("- Email Notifications for "+show.name+" (episode: "+episode.name+") will be sent to:")
for email in recipients:
self._debug_spew("-- "+email.strip())
self._debug_spew("\n\r")
return True
开发者ID:feld,项目名称:SickRage,代码行数:33,代码来源:notifier_tests.py
示例12: test_prowl
def test_prowl(self):
"""
Test prowl notifications
"""
prowl_notifier = ProwlNotifier()
# Prowl per-show-notifications only utilize the new methodology for storage; therefore, the list of legacy_shows
# will not be altered (to preserve backwards compatibility testing)
test_prowl_apis = "11111111111111111111,22222222222222222222"
for show in self.shows:
showid = self._get_showid_by_showname(show.name)
Home.saveShowNotifyList(show=showid, prowlAPIs=test_prowl_apis)
# Now, iterate through all shows using the Prowl API generation routines that are used in the notifier proper
for show in self.shows:
for episode in show.episodes:
ep_name = ss(episode._format_pattern('%SN - %Sx%0E - %EN - ')+episode.quality) # pylint: disable=protected-access
show_name = prowl_notifier._parse_episode(ep_name) # pylint: disable=protected-access
recipients = prowl_notifier._generate_recipients(show_name) # pylint: disable=protected-access
self._debug_spew("- Prowl Notifications for "+show.name+" (episode: "+episode.name+") will be sent to:")
for api in recipients:
self._debug_spew("-- "+api.strip())
self._debug_spew("\n\r")
return True
开发者ID:feld,项目名称:SickRage,代码行数:26,代码来源:notifier_tests.py
示例13: _parseEp
def _parseEp(ep_name):
ep_name = ss(ep_name)
sep = ' - '
titles = ep_name.split(sep)
logger.log('TITLES: {0}'.format(titles), logger.DEBUG)
return titles
开发者ID:magicseb,项目名称:SickRage,代码行数:7,代码来源:emailnotify.py
示例14: _send_to_kodi
def _send_to_kodi(command, host=None, username=None, password=None, dest_app="KODI"): # pylint: disable=too-many-arguments
"""Handles communication to KODI servers via HTTP API
Args:
command: Dictionary of field/data pairs, encoded via urllib and passed to the KODI API via HTTP
host: KODI webserver host:port
username: KODI webserver username
password: KODI webserver password
Returns:
Returns response.result for successful commands or False if there was an error
"""
# fill in omitted parameters
if not username:
username = sickbeard.KODI_USERNAME
if not password:
password = sickbeard.KODI_PASSWORD
if not host:
logger.log('No {0} host passed, aborting update'.format(dest_app), logger.WARNING)
return False
for key in command:
if isinstance(command[key], six.text_type):
command[key] = command[key].encode('utf-8')
enc_command = urllib.parse.urlencode(command)
logger.log("{0} encoded API command: {1!r}".format(dest_app, enc_command), logger.DEBUG)
# url = 'http://%s/xbmcCmds/xbmcHttp/?%s' % (host, enc_command) # maybe need for old plex?
url = 'http://{0}/kodiCmds/kodiHttp/?{1}'.format(host, enc_command)
try:
req = urllib.request.Request(url)
# if we have a password, use authentication
if password:
base64string = base64.encodestring('{0}:{1}'.format(username, password))[:-1]
authheader = "Basic {0}".format(base64string)
req.add_header("Authorization", authheader)
logger.log("Contacting {0} (with auth header) via url: {1}".format(dest_app, ss(url)), logger.DEBUG)
else:
logger.log("Contacting {0} via url: {1}".format(dest_app, ss(url)), logger.DEBUG)
try:
response = urllib.request.urlopen(req)
except (http_client.BadStatusLine, urllib.error.URLError) as e:
logger.log("Couldn't contact {0} HTTP at {1!r} : {2!r}".format(dest_app, url, ex(e)), logger.DEBUG)
return False
result = response.read().decode(sickbeard.SYS_ENCODING)
response.close()
logger.log("{0} HTTP response: {1}".format(dest_app, result.replace('\n', '')), logger.DEBUG)
return result
except Exception as e:
logger.log("Couldn't contact {0} HTTP at {1!r} : {2!r}".format(dest_app, url, ex(e)), logger.DEBUG)
return False
开发者ID:magicseb,项目名称:SickRage,代码行数:59,代码来源:kodi.py
示例15: _parseEp
def _parseEp(ep_name):
ep_name = ss(ep_name)
sep = ' - '
titles = ep_name.split(sep)
titles.sort(key=len, reverse=True)
logger.log('TITLES: {}'.format(titles), logger.DEBUG)
return titles
开发者ID:bitzorro,项目名称:SickRage,代码行数:8,代码来源:emailnotify.py
示例16: _parseEp
def _parseEp(self, ep_name):
ep_name = ss(ep_name)
sep = " - "
titles = ep_name.split(sep)
titles.sort(key=len, reverse=True)
logging.debug("TITLES: %s" % titles)
return titles
开发者ID:coderbone,项目名称:SickRage,代码行数:8,代码来源:emailnotify.py
示例17: _parseEp
def _parseEp(self, ep_name):
ep_name = ss(ep_name)
sep = " - "
titles = ep_name.split(sep)
titles.sort(key=len, reverse=True)
logger.log("TITLES: %s" % titles, logger.DEBUG)
return titles
开发者ID:BreizhCat,项目名称:SickRage,代码行数:8,代码来源:emailnotify.py
示例18: _parse_episode
def _parse_episode(ep_name):
ep_name = ss(ep_name)
sep = " - "
titles = ep_name.split(sep)
titles.sort(key=len, reverse=True)
logger.log("TITLES: {0}".format(titles), logger.DEBUG)
return titles
开发者ID:Arcanemagus,项目名称:SickRage,代码行数:8,代码来源:prowl.py
示例19: createNZBString
def createNZBString(fileElements, xmlns):
rootElement = etree.Element("nzb")
if xmlns:
rootElement.set("xmlns", xmlns)
for curFile in fileElements:
rootElement.append(stripNS(curFile, xmlns))
return etree.tostring(ss(rootElement))
开发者ID:Maximilian-Reuter,项目名称:SickRage,代码行数:9,代码来源:nzbSplitter.py
示例20: notify_snatch
def notify_snatch(self, ep_name):
ep_name = ss(ep_name)
if sickbeard.PROWL_NOTIFY_ONSNATCH:
show = self._parse_episode(ep_name)
recipients = self._generate_recipients(show)
if len(recipients) == 0:
logger.log('Skipping prowl notify because there are no configured recipients', logger.DEBUG)
else:
for api in recipients:
self._send_prowl(prowl_api=api, prowl_priority=None, event=common.notifyStrings[common.NOTIFY_SNATCH],
message=ep_name + " :: " + time.strftime(sickbeard.DATE_PRESET + " " + sickbeard.TIME_PRESET))
开发者ID:Hydrog3n,项目名称:SickRage,代码行数:11,代码来源:prowl.py
注:本文中的sickrage.helper.encoding.ss函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论