Create new class to handle HTTP requests

Some more clean-up
This commit is contained in:
Tim 2015-07-05 15:59:57 +02:00
parent e1e3659eb3
commit 9b7f529d02
6 changed files with 456 additions and 545 deletions

View file

@ -14,6 +14,7 @@
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
from operator import itemgetter
from xml.dom import minidom
import unicodedata
import plexpy
@ -359,4 +360,36 @@ def get_percent(value1, value2):
else:
percent = 0
return math.trunc(percent)
return math.trunc(percent)
def parse_xml(unparsed=None):
from plexpy import logger
if unparsed:
try:
xml_parse = minidom.parseString(unparsed)
return xml_parse
except Exception, e:
logger.warn("Error parsing XML. %s" % e)
return []
except:
logger.warn("Error parsing XML.")
return []
else:
logger.warn("XML parse request made but no data received.")
return []
"""
Validate xml keys to make sure they exist and return their attribute value, return blank value is none found
"""
def get_xml_attr(xml_key, attribute, return_bool=False, default_return=''):
if xml_key.getAttribute(attribute):
if return_bool:
return True
else:
return xml_key.getAttribute(attribute)
else:
if return_bool:
return False
else:
return default_return