#!/usr/bin/env python # -*- coding: utf-8 -*- """ :synopsis: Prompts the user to add network paths and username passwords for e.g. smb paths """ from logging import getLogger import re import socket import xbmc from .. import path_ops, utils LOG = getLogger('PLEX.direct_path_sources') SUPPORTED_PROTOCOLS = ('smb', 'nfs', 'http', 'https', 'ftp', 'sftp') PATH = path_ops.translate_path('special://userdata/') def get_etree(topelement): try: xml = utils.etree.parse( path_ops.path.join(PATH, '%s.xml' % topelement)) except IOError: # Document is blank or missing LOG.info('%s.xml is missing or blank, creating it', topelement) root = utils.etree.Element(topelement) except utils.ParseError: LOG.error('Error parsing %s', topelement) # "Kodi cannot parse {0}. PKC will not function correctly. Please visit # {1} and correct your file!" utils.messageDialog(utils.lang(29999), utils.lang(39716).format( '%s.xml' % topelement, 'http://forum.kodi.tv/')) return else: root = xml.getroot() return root def is_valid_hostname(hostname): if len(hostname) > 255: return False if hostname[-1] == ".": # strip exactly one dot from the right, if present hostname = hostname[:-1] allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?