Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Add support for thrift_file path in http protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
azurefang committed Aug 8, 2016
1 parent e9c087f commit d6efbbd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions thriftpy/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 '
Expand Down

0 comments on commit d6efbbd

Please sign in to comment.