Skip to content

Commit

Permalink
Py3k compatibility for snippet execution. (#1860)
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver authored and daspecster committed Jun 16, 2016
1 parent a74ed9e commit 5fc0c01
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions docs/pubsub_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,27 @@ def subscription_check_iam_permissions(client, to_delete):
# [END subscription_check_iam_permissions]


def _line_no(func):
code = getattr(func, '__code__', None) or getattr(func, 'func_code')
return code.co_firstlineno


def _find_examples():
funcs = [obj for obj in globals().values()
if getattr(obj, '_snippet', False)]
for func in sorted(funcs, key=lambda f: f.func_code.co_firstlineno):
for func in sorted(funcs, key=_line_no):
yield func


def _name_and_doc(func):
return func.__name__, func.__doc__


def main():
client = Client()
for example in _find_examples():
to_delete = []
print('%-25s: %s' % (
example.func_name, example.func_doc))
print('%-25s: %s' % _name_and_doc(example))
try:
example(client, to_delete)
except AssertionError as e:
Expand Down

0 comments on commit 5fc0c01

Please sign in to comment.