Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py3k compatibility for snippet execution. #1860

Merged
merged 1 commit into from
Jun 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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