mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Added extension restrictions
This commit is contained in:
@@ -254,6 +254,9 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns true or false
|
# Returns true or false
|
||||||
def generated_apache_thrift?
|
def generated_apache_thrift?
|
||||||
|
return false unless ['.rb', '.py', '.go', '.js', '.m', '.java', '.h', '.cc', '.cpp'].include?(extname)
|
||||||
|
return false unless lines.count > 1
|
||||||
|
|
||||||
return lines[0].include?("Autogenerated by Thrift Compiler") || lines[1].include?("Autogenerated by Thrift Compiler")
|
return lines[0].include?("Autogenerated by Thrift Compiler") || lines[1].include?("Autogenerated by Thrift Compiler")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
83
samples/Python/gen-py-thrift-linguist.py
Normal file
83
samples/Python/gen-py-thrift-linguist.py
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#
|
||||||
|
# Autogenerated by Thrift Compiler (1.0.0-dev)
|
||||||
|
#
|
||||||
|
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||||
|
#
|
||||||
|
# options string: py
|
||||||
|
#
|
||||||
|
|
||||||
|
from thrift.Thrift import TType, TMessageType, TException, TApplicationException
|
||||||
|
|
||||||
|
from thrift.transport import TTransport
|
||||||
|
from thrift.protocol import TBinaryProtocol, TProtocol
|
||||||
|
try:
|
||||||
|
from thrift.protocol import fastbinary
|
||||||
|
except:
|
||||||
|
fastbinary = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PullRequest:
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
- title
|
||||||
|
"""
|
||||||
|
|
||||||
|
thrift_spec = (
|
||||||
|
None, # 0
|
||||||
|
(1, TType.STRING, 'title', None, None, ), # 1
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, title=None,):
|
||||||
|
self.title = title
|
||||||
|
|
||||||
|
def read(self, iprot):
|
||||||
|
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
|
||||||
|
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
|
||||||
|
return
|
||||||
|
iprot.readStructBegin()
|
||||||
|
while True:
|
||||||
|
(fname, ftype, fid) = iprot.readFieldBegin()
|
||||||
|
if ftype == TType.STOP:
|
||||||
|
break
|
||||||
|
if fid == 1:
|
||||||
|
if ftype == TType.STRING:
|
||||||
|
self.title = iprot.readString()
|
||||||
|
else:
|
||||||
|
iprot.skip(ftype)
|
||||||
|
else:
|
||||||
|
iprot.skip(ftype)
|
||||||
|
iprot.readFieldEnd()
|
||||||
|
iprot.readStructEnd()
|
||||||
|
|
||||||
|
def write(self, oprot):
|
||||||
|
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
|
||||||
|
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
|
||||||
|
return
|
||||||
|
oprot.writeStructBegin('PullRequest')
|
||||||
|
if self.title is not None:
|
||||||
|
oprot.writeFieldBegin('title', TType.STRING, 1)
|
||||||
|
oprot.writeString(self.title)
|
||||||
|
oprot.writeFieldEnd()
|
||||||
|
oprot.writeFieldStop()
|
||||||
|
oprot.writeStructEnd()
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
value = 17
|
||||||
|
value = (value * 31) ^ hash(self.title)
|
||||||
|
return value
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
L = ['%s=%r' % (key, value)
|
||||||
|
for key, value in self.__dict__.iteritems()]
|
||||||
|
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not (self == other)
|
||||||
@@ -219,6 +219,7 @@ class TestBlob < Minitest::Test
|
|||||||
assert sample_blob("Go/api.pb.go").generated?
|
assert sample_blob("Go/api.pb.go").generated?
|
||||||
|
|
||||||
# Apache Thrift generated code
|
# Apache Thrift generated code
|
||||||
|
assert sample_blob("Python/gen-py-linguist-thrift.py").generated?
|
||||||
assert sample_blob("Go/gen-go-linguist-thrift.go").generated?
|
assert sample_blob("Go/gen-go-linguist-thrift.go").generated?
|
||||||
assert sample_blob("Java/gen-java-linguist-thrift.java").generated?
|
assert sample_blob("Java/gen-java-linguist-thrift.java").generated?
|
||||||
assert sample_blob("JavaScript/gen-js-linguist-thrift.js").generated?
|
assert sample_blob("JavaScript/gen-js-linguist-thrift.js").generated?
|
||||||
|
|||||||
Reference in New Issue
Block a user