From d6efbbd0d55ad83f9c9c305a625955589a50afd3 Mon Sep 17 00:00:00 2001 From: Fang Tao Date: Mon, 8 Aug 2016 18:20:25 +0800 Subject: [PATCH] Add support for thrift_file path in `http` protocol --- thriftpy/parser/parser.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/thriftpy/parser/parser.py b/thriftpy/parser/parser.py index f93c305..5eac566 100644 --- a/thriftpy/parser/parser.py +++ b/thriftpy/parser/parser.py @@ -11,6 +11,8 @@ import os import sys import types +import urllib2 +from urlparse import urlparse from ply import lex, yacc from .lexer import * # noqa from .exc import ThriftParserError, ThriftGrammerError @@ -484,8 +486,16 @@ def parse(path, module_name=None, include_dirs=None, include_dir=None, if not path.endswith('.thrift'): raise ThriftParserError('Path should end with .thrift') - with open(path) as fh: - data = fh.read() + url_scheme = urlparse(path).scheme + if url_scheme == '': + with open(path) as fh: + data = fh.read() + elif url_scheme in ('http', 'https'): + data = urllib2.urlopen(path).read() + else: + raise ThriftParserError('ThriftPy does not support generating module ' + 'with path in protocol \'{}\''.format( + url_scheme)) if module_name is not None and not module_name.endswith('_thrift'): raise ThriftParserError('ThriftPy can only generate module with '