私はPythonにはかなり慣れていませんが、Pythonが好きになりました。私は最初の Python プロジェクトを開始し、プロトタイピングを行っています。「Python 哲学」は、型付けと例外に関して私を混乱させます。誰かがこの抜粋を撃ってくれませんか? 基本的な Python の方法論を設計しすぎたり、見逃したりしていませんか?
class URIPartError(Exception):
pass
class WCFClient(object):
def __init__(self, host, scheme='http', port=80, path='/', user=None, password=None):
super(WCFClient, self).__init__()
#Store our variables
try:
self.__host = str(host).lower()
self.__scheme = str(scheme).lower()
self.__port = int(port)
self.__path = str(path)
self.__user = str(user) if user else None
self.__password = str(password) if password else None
except (TypeError, ValueError), e:
raise URIPartError('Invalid URI part')
#Are our inputs valid?
if not self.__scheme == 'http' and not self.__scheme == 'https':
raise URIPartError('Invalid URI scheme')
if not path.startswith('/') or not path.endswith('/'):
raise URIPartError('Invalid URI path')
#Generate valid URI for baseurl
if (self.__scheme == 'http' and self.__port == 80) or (self.__scheme == 'https' and self.__port == 443):
self.__baseurl = '{0}://{1}{2}'.format(self.__scheme, self.__host, self.__path)
else:
self.__baseurl = '{0}://{1}:{2}{3}'.format(self.__scheme, self.__host, self.__port, self.__path)
def baseurl(self):
return self.__baseurl
ありがとう!