partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | cached.argshash | Hash mutable arguments' containers with immutable keys and values. | dwave/cloud/utils.py | def argshash(self, args, kwargs):
"Hash mutable arguments' containers with immutable keys and values."
a = repr(args)
b = repr(sorted((repr(k), repr(v)) for k, v in kwargs.items()))
return a + b | def argshash(self, args, kwargs):
"Hash mutable arguments' containers with immutable keys and values."
a = repr(args)
b = repr(sorted((repr(k), repr(v)) for k, v in kwargs.items()))
return a + b | [
"Hash",
"mutable",
"arguments",
"containers",
"with",
"immutable",
"keys",
"and",
"values",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/utils.py#L316-L320 | [
"def",
"argshash",
"(",
"self",
",",
"args",
",",
"kwargs",
")",
":",
"a",
"=",
"repr",
"(",
"args",
")",
"b",
"=",
"repr",
"(",
"sorted",
"(",
"(",
"repr",
"(",
"k",
")",
",",
"repr",
"(",
"v",
")",
")",
"for",
"k",
",",
"v",
"in",
"kwargs... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | UserMediaImageViewMixin.get_context_data | Adds `next` to the context.
This makes sure that the `next` parameter doesn't get lost if the
form was submitted invalid. | user_media/views.py | def get_context_data(self, **kwargs):
"""
Adds `next` to the context.
This makes sure that the `next` parameter doesn't get lost if the
form was submitted invalid.
"""
ctx = super(UserMediaImageViewMixin, self).get_context_data(**kwargs)
ctx.update({
... | def get_context_data(self, **kwargs):
"""
Adds `next` to the context.
This makes sure that the `next` parameter doesn't get lost if the
form was submitted invalid.
"""
ctx = super(UserMediaImageViewMixin, self).get_context_data(**kwargs)
ctx.update({
... | [
"Adds",
"next",
"to",
"the",
"context",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/views.py#L34-L47 | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"ctx",
"=",
"super",
"(",
"UserMediaImageViewMixin",
",",
"self",
")",
".",
"get_context_data",
"(",
"*",
"*",
"kwargs",
")",
"ctx",
".",
"update",
"(",
"{",
"'action'",
":",
"s... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | UserMediaImageViewMixin.get_success_url | Returns the success URL.
This is either the given `next` URL parameter or the content object's
`get_absolute_url` method's return value. | user_media/views.py | def get_success_url(self):
"""
Returns the success URL.
This is either the given `next` URL parameter or the content object's
`get_absolute_url` method's return value.
"""
if self.next:
return self.next
if self.object and self.object.content_object:
... | def get_success_url(self):
"""
Returns the success URL.
This is either the given `next` URL parameter or the content object's
`get_absolute_url` method's return value.
"""
if self.next:
return self.next
if self.object and self.object.content_object:
... | [
"Returns",
"the",
"success",
"URL",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/views.py#L49-L63 | [
"def",
"get_success_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"next",
":",
"return",
"self",
".",
"next",
"if",
"self",
".",
"object",
"and",
"self",
".",
"object",
".",
"content_object",
":",
"return",
"self",
".",
"object",
".",
"content_object",... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | CreateImageView.dispatch | Adds useful objects to the class and performs security checks. | user_media/views.py | def dispatch(self, request, *args, **kwargs):
"""Adds useful objects to the class and performs security checks."""
self._add_next_and_user(request)
self.content_object = None
self.content_type = None
self.object_id = kwargs.get('object_id', None)
if kwargs.get('content_t... | def dispatch(self, request, *args, **kwargs):
"""Adds useful objects to the class and performs security checks."""
self._add_next_and_user(request)
self.content_object = None
self.content_type = None
self.object_id = kwargs.get('object_id', None)
if kwargs.get('content_t... | [
"Adds",
"useful",
"objects",
"to",
"the",
"class",
"and",
"performs",
"security",
"checks",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/views.py#L72-L104 | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_add_next_and_user",
"(",
"request",
")",
"self",
".",
"content_object",
"=",
"None",
"self",
".",
"content_type",
"=",
"None",
"self",
"... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | DeleteImageView.dispatch | Adds useful objects to the class. | user_media/views.py | def dispatch(self, request, *args, **kwargs):
"""Adds useful objects to the class."""
self._add_next_and_user(request)
return super(DeleteImageView, self).dispatch(request, *args, **kwargs) | def dispatch(self, request, *args, **kwargs):
"""Adds useful objects to the class."""
self._add_next_and_user(request)
return super(DeleteImageView, self).dispatch(request, *args, **kwargs) | [
"Adds",
"useful",
"objects",
"to",
"the",
"class",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/views.py#L131-L134 | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_add_next_and_user",
"(",
"request",
")",
"return",
"super",
"(",
"DeleteImageView",
",",
"self",
")",
".",
"dispatch",
"(",
"request",
"... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | DeleteImageView.get_queryset | Making sure that a user can only delete his own images.
Even when he forges the request URL. | user_media/views.py | def get_queryset(self):
"""
Making sure that a user can only delete his own images.
Even when he forges the request URL.
"""
queryset = super(DeleteImageView, self).get_queryset()
queryset = queryset.filter(user=self.user)
return queryset | def get_queryset(self):
"""
Making sure that a user can only delete his own images.
Even when he forges the request URL.
"""
queryset = super(DeleteImageView, self).get_queryset()
queryset = queryset.filter(user=self.user)
return queryset | [
"Making",
"sure",
"that",
"a",
"user",
"can",
"only",
"delete",
"his",
"own",
"images",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/views.py#L143-L152 | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"queryset",
"=",
"super",
"(",
"DeleteImageView",
",",
"self",
")",
".",
"get_queryset",
"(",
")",
"queryset",
"=",
"queryset",
".",
"filter",
"(",
"user",
"=",
"self",
".",
"user",
")",
"return",
"queryset"
... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | UpdateImageView.dispatch | Adds useful objects to the class. | user_media/views.py | def dispatch(self, request, *args, **kwargs):
"""Adds useful objects to the class."""
self._add_next_and_user(request)
return super(UpdateImageView, self).dispatch(request, *args, **kwargs) | def dispatch(self, request, *args, **kwargs):
"""Adds useful objects to the class."""
self._add_next_and_user(request)
return super(UpdateImageView, self).dispatch(request, *args, **kwargs) | [
"Adds",
"useful",
"objects",
"to",
"the",
"class",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/views.py#L163-L166 | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_add_next_and_user",
"(",
"request",
")",
"return",
"super",
"(",
"UpdateImageView",
",",
"self",
")",
".",
"dispatch",
"(",
"request",
"... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | UpdateImageView.get_queryset | Making sure that a user can only edit his own images.
Even when he forges the request URL. | user_media/views.py | def get_queryset(self):
"""
Making sure that a user can only edit his own images.
Even when he forges the request URL.
"""
queryset = super(UpdateImageView, self).get_queryset()
queryset = queryset.filter(user=self.user)
return queryset | def get_queryset(self):
"""
Making sure that a user can only edit his own images.
Even when he forges the request URL.
"""
queryset = super(UpdateImageView, self).get_queryset()
queryset = queryset.filter(user=self.user)
return queryset | [
"Making",
"sure",
"that",
"a",
"user",
"can",
"only",
"edit",
"his",
"own",
"images",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/views.py#L186-L195 | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"queryset",
"=",
"super",
"(",
"UpdateImageView",
",",
"self",
")",
".",
"get_queryset",
"(",
")",
"queryset",
"=",
"queryset",
".",
"filter",
"(",
"user",
"=",
"self",
".",
"user",
")",
"return",
"queryset"
... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | UserMediaImageFormMixin._delete_images | Deletes all user media images of the given instance. | user_media/forms.py | def _delete_images(self, instance):
"""Deletes all user media images of the given instance."""
UserMediaImage.objects.filter(
content_type=ContentType.objects.get_for_model(instance),
object_id=instance.pk,
user=instance.user,
).delete() | def _delete_images(self, instance):
"""Deletes all user media images of the given instance."""
UserMediaImage.objects.filter(
content_type=ContentType.objects.get_for_model(instance),
object_id=instance.pk,
user=instance.user,
).delete() | [
"Deletes",
"all",
"user",
"media",
"images",
"of",
"the",
"given",
"instance",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/forms.py#L51-L57 | [
"def",
"_delete_images",
"(",
"self",
",",
"instance",
")",
":",
"UserMediaImage",
".",
"objects",
".",
"filter",
"(",
"content_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"instance",
")",
",",
"object_id",
"=",
"instance",
".",
"pk... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | UserMediaImageForm.clean_image | It seems like in Django 1.5 something has changed.
When Django tries to validate the form, it checks if the generated
filename fit into the max_length. But at this point, self.instance.user
is not yet set so our filename generation function cannot create
the new file path because it nee... | user_media/forms.py | def clean_image(self):
"""
It seems like in Django 1.5 something has changed.
When Django tries to validate the form, it checks if the generated
filename fit into the max_length. But at this point, self.instance.user
is not yet set so our filename generation function cannot crea... | def clean_image(self):
"""
It seems like in Django 1.5 something has changed.
When Django tries to validate the form, it checks if the generated
filename fit into the max_length. But at this point, self.instance.user
is not yet set so our filename generation function cannot crea... | [
"It",
"seems",
"like",
"in",
"Django",
"1",
".",
"5",
"something",
"has",
"changed",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/forms.py#L90-L103 | [
"def",
"clean_image",
"(",
"self",
")",
":",
"self",
".",
"instance",
".",
"user",
"=",
"self",
".",
"user",
"data",
"=",
"self",
".",
"cleaned_data",
".",
"get",
"(",
"'image'",
")",
"return",
"data"
] | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | get_image_file_path | Returns a unique filename for images. | user_media/models.py | def get_image_file_path(instance, filename):
"""Returns a unique filename for images."""
ext = filename.split('.')[-1]
filename = '%s.%s' % (uuid.uuid4(), ext)
return os.path.join(
'user_media', str(instance.user.pk), 'images', filename) | def get_image_file_path(instance, filename):
"""Returns a unique filename for images."""
ext = filename.split('.')[-1]
filename = '%s.%s' % (uuid.uuid4(), ext)
return os.path.join(
'user_media', str(instance.user.pk), 'images', filename) | [
"Returns",
"a",
"unique",
"filename",
"for",
"images",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/models.py#L15-L20 | [
"def",
"get_image_file_path",
"(",
"instance",
",",
"filename",
")",
":",
"ext",
"=",
"filename",
".",
"split",
"(",
"'.'",
")",
"[",
"-",
"1",
"]",
"filename",
"=",
"'%s.%s'",
"%",
"(",
"uuid",
".",
"uuid4",
"(",
")",
",",
"ext",
")",
"return",
"o... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | image_post_delete_handler | Makes sure that a an image is also deleted from the media directory.
This should prevent a load of "dead" image files on disc. | user_media/models.py | def image_post_delete_handler(sender, instance, **kwargs):
"""
Makes sure that a an image is also deleted from the media directory.
This should prevent a load of "dead" image files on disc.
"""
for f in glob.glob('{}/{}*'.format(instance.image.storage.location,
... | def image_post_delete_handler(sender, instance, **kwargs):
"""
Makes sure that a an image is also deleted from the media directory.
This should prevent a load of "dead" image files on disc.
"""
for f in glob.glob('{}/{}*'.format(instance.image.storage.location,
... | [
"Makes",
"sure",
"that",
"a",
"an",
"image",
"is",
"also",
"deleted",
"from",
"the",
"media",
"directory",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/models.py#L138-L148 | [
"def",
"image_post_delete_handler",
"(",
"sender",
",",
"instance",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"f",
"in",
"glob",
".",
"glob",
"(",
"'{}/{}*'",
".",
"format",
"(",
"instance",
".",
"image",
".",
"storage",
".",
"location",
",",
"instance",... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | UserMediaImage.box_coordinates | Returns a thumbnail's coordinates. | user_media/models.py | def box_coordinates(self):
"""Returns a thumbnail's coordinates."""
if (
self.thumb_x is not None and
self.thumb_y is not None and
self.thumb_x2 is not None and
self.thumb_y2 is not None
):
return (
int(self.thumb_x),
... | def box_coordinates(self):
"""Returns a thumbnail's coordinates."""
if (
self.thumb_x is not None and
self.thumb_y is not None and
self.thumb_x2 is not None and
self.thumb_y2 is not None
):
return (
int(self.thumb_x),
... | [
"Returns",
"a",
"thumbnail",
"s",
"coordinates",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/models.py#L106-L120 | [
"def",
"box_coordinates",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"thumb_x",
"is",
"not",
"None",
"and",
"self",
".",
"thumb_y",
"is",
"not",
"None",
"and",
"self",
".",
"thumb_x2",
"is",
"not",
"None",
"and",
"self",
".",
"thumb_y2",
"is",
"n... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | UserMediaImage.large_size | Returns a thumbnail's large size. | user_media/models.py | def large_size(self, as_string=True):
"""Returns a thumbnail's large size."""
size = getattr(settings, 'USER_MEDIA_THUMB_SIZE_LARGE', (150, 150))
if as_string:
return u'{}x{}'.format(size[0], size[1])
return size | def large_size(self, as_string=True):
"""Returns a thumbnail's large size."""
size = getattr(settings, 'USER_MEDIA_THUMB_SIZE_LARGE', (150, 150))
if as_string:
return u'{}x{}'.format(size[0], size[1])
return size | [
"Returns",
"a",
"thumbnail",
"s",
"large",
"size",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/models.py#L122-L127 | [
"def",
"large_size",
"(",
"self",
",",
"as_string",
"=",
"True",
")",
":",
"size",
"=",
"getattr",
"(",
"settings",
",",
"'USER_MEDIA_THUMB_SIZE_LARGE'",
",",
"(",
"150",
",",
"150",
")",
")",
"if",
"as_string",
":",
"return",
"u'{}x{}'",
".",
"format",
... | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | crop_box | Uses box coordinates to crop an image without resizing it first. | user_media/processors.py | def crop_box(im, box=False, **kwargs):
"""Uses box coordinates to crop an image without resizing it first."""
if box:
im = im.crop(box)
return im | def crop_box(im, box=False, **kwargs):
"""Uses box coordinates to crop an image without resizing it first."""
if box:
im = im.crop(box)
return im | [
"Uses",
"box",
"coordinates",
"to",
"crop",
"an",
"image",
"without",
"resizing",
"it",
"first",
"."
] | bitlabstudio/django-user-media | python | https://github.com/bitlabstudio/django-user-media/blob/63905aeb57640f116320ab8d7116e0ec35fde377/user_media/processors.py#L4-L8 | [
"def",
"crop_box",
"(",
"im",
",",
"box",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"box",
":",
"im",
"=",
"im",
".",
"crop",
"(",
"box",
")",
"return",
"im"
] | 63905aeb57640f116320ab8d7116e0ec35fde377 |
train | load_germanet | Loads a GermaNet instance connected to the given MongoDB instance.
Arguments:
- `host`: the hostname of the MongoDB instance
- `port`: the port number of the MongoDB instance
- `database_name`: the name of the GermaNet database on the
MongoDB instance | pygermanet/germanet.py | def load_germanet(host = None, port = None, database_name = 'germanet'):
'''
Loads a GermaNet instance connected to the given MongoDB instance.
Arguments:
- `host`: the hostname of the MongoDB instance
- `port`: the port number of the MongoDB instance
- `database_name`: the name of the GermaNet... | def load_germanet(host = None, port = None, database_name = 'germanet'):
'''
Loads a GermaNet instance connected to the given MongoDB instance.
Arguments:
- `host`: the hostname of the MongoDB instance
- `port`: the port number of the MongoDB instance
- `database_name`: the name of the GermaNet... | [
"Loads",
"a",
"GermaNet",
"instance",
"connected",
"to",
"the",
"given",
"MongoDB",
"instance",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L664-L676 | [
"def",
"load_germanet",
"(",
"host",
"=",
"None",
",",
"port",
"=",
"None",
",",
"database_name",
"=",
"'germanet'",
")",
":",
"client",
"=",
"MongoClient",
"(",
"host",
",",
"port",
")",
"germanet_db",
"=",
"client",
"[",
"database_name",
"]",
"return",
... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.cache_size | Set the cache size used to reduce the number of database
access operations. | pygermanet/germanet.py | def cache_size(self, new_value):
'''
Set the cache size used to reduce the number of database
access operations.
'''
if type(new_value) == int and 0 < new_value:
if self._lemma_cache is not None:
self._lemma_cache = repoze.lru.LRUCache(new_value)
... | def cache_size(self, new_value):
'''
Set the cache size used to reduce the number of database
access operations.
'''
if type(new_value) == int and 0 < new_value:
if self._lemma_cache is not None:
self._lemma_cache = repoze.lru.LRUCache(new_value)
... | [
"Set",
"the",
"cache",
"size",
"used",
"to",
"reduce",
"the",
"number",
"of",
"database",
"access",
"operations",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L75-L83 | [
"def",
"cache_size",
"(",
"self",
",",
"new_value",
")",
":",
"if",
"type",
"(",
"new_value",
")",
"==",
"int",
"and",
"0",
"<",
"new_value",
":",
"if",
"self",
".",
"_lemma_cache",
"is",
"not",
"None",
":",
"self",
".",
"_lemma_cache",
"=",
"repoze",
... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.all_lemmas | A generator over all the lemmas in the GermaNet database. | pygermanet/germanet.py | def all_lemmas(self):
'''
A generator over all the lemmas in the GermaNet database.
'''
for lemma_dict in self._mongo_db.lexunits.find():
yield Lemma(self, lemma_dict) | def all_lemmas(self):
'''
A generator over all the lemmas in the GermaNet database.
'''
for lemma_dict in self._mongo_db.lexunits.find():
yield Lemma(self, lemma_dict) | [
"A",
"generator",
"over",
"all",
"the",
"lemmas",
"in",
"the",
"GermaNet",
"database",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L85-L90 | [
"def",
"all_lemmas",
"(",
"self",
")",
":",
"for",
"lemma_dict",
"in",
"self",
".",
"_mongo_db",
".",
"lexunits",
".",
"find",
"(",
")",
":",
"yield",
"Lemma",
"(",
"self",
",",
"lemma_dict",
")"
] | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.lemmas | Looks up lemmas in the GermaNet database.
Arguments:
- `lemma`:
- `pos`: | pygermanet/germanet.py | def lemmas(self, lemma, pos = None):
'''
Looks up lemmas in the GermaNet database.
Arguments:
- `lemma`:
- `pos`:
'''
if pos is not None:
if pos not in SHORT_POS_TO_LONG:
return None
pos = SHORT_POS_TO_LONG[pos]
... | def lemmas(self, lemma, pos = None):
'''
Looks up lemmas in the GermaNet database.
Arguments:
- `lemma`:
- `pos`:
'''
if pos is not None:
if pos not in SHORT_POS_TO_LONG:
return None
pos = SHORT_POS_TO_LONG[pos]
... | [
"Looks",
"up",
"lemmas",
"in",
"the",
"GermaNet",
"database",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L92-L108 | [
"def",
"lemmas",
"(",
"self",
",",
"lemma",
",",
"pos",
"=",
"None",
")",
":",
"if",
"pos",
"is",
"not",
"None",
":",
"if",
"pos",
"not",
"in",
"SHORT_POS_TO_LONG",
":",
"return",
"None",
"pos",
"=",
"SHORT_POS_TO_LONG",
"[",
"pos",
"]",
"lemma_dicts",... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.all_synsets | A generator over all the synsets in the GermaNet database. | pygermanet/germanet.py | def all_synsets(self):
'''
A generator over all the synsets in the GermaNet database.
'''
for synset_dict in self._mongo_db.synsets.find():
yield Synset(self, synset_dict) | def all_synsets(self):
'''
A generator over all the synsets in the GermaNet database.
'''
for synset_dict in self._mongo_db.synsets.find():
yield Synset(self, synset_dict) | [
"A",
"generator",
"over",
"all",
"the",
"synsets",
"in",
"the",
"GermaNet",
"database",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L110-L115 | [
"def",
"all_synsets",
"(",
"self",
")",
":",
"for",
"synset_dict",
"in",
"self",
".",
"_mongo_db",
".",
"synsets",
".",
"find",
"(",
")",
":",
"yield",
"Synset",
"(",
"self",
",",
"synset_dict",
")"
] | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.synsets | Looks up synsets in the GermaNet database.
Arguments:
- `lemma`:
- `pos`: | pygermanet/germanet.py | def synsets(self, lemma, pos = None):
'''
Looks up synsets in the GermaNet database.
Arguments:
- `lemma`:
- `pos`:
'''
return sorted(set(lemma_obj.synset
for lemma_obj in self.lemmas(lemma, pos))) | def synsets(self, lemma, pos = None):
'''
Looks up synsets in the GermaNet database.
Arguments:
- `lemma`:
- `pos`:
'''
return sorted(set(lemma_obj.synset
for lemma_obj in self.lemmas(lemma, pos))) | [
"Looks",
"up",
"synsets",
"in",
"the",
"GermaNet",
"database",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L117-L126 | [
"def",
"synsets",
"(",
"self",
",",
"lemma",
",",
"pos",
"=",
"None",
")",
":",
"return",
"sorted",
"(",
"set",
"(",
"lemma_obj",
".",
"synset",
"for",
"lemma_obj",
"in",
"self",
".",
"lemmas",
"(",
"lemma",
",",
"pos",
")",
")",
")"
] | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.synset | Looks up a synset in GermaNet using its string representation.
Arguments:
- `synset_repr`: a unicode string containing the lemma, part
of speech, and sense number of the first lemma of the synset
>>> gn.synset(u'funktionieren.v.2')
Synset(funktionieren.v.2) | pygermanet/germanet.py | def synset(self, synset_repr):
'''
Looks up a synset in GermaNet using its string representation.
Arguments:
- `synset_repr`: a unicode string containing the lemma, part
of speech, and sense number of the first lemma of the synset
>>> gn.synset(u'funktionieren.v.2')
... | def synset(self, synset_repr):
'''
Looks up a synset in GermaNet using its string representation.
Arguments:
- `synset_repr`: a unicode string containing the lemma, part
of speech, and sense number of the first lemma of the synset
>>> gn.synset(u'funktionieren.v.2')
... | [
"Looks",
"up",
"a",
"synset",
"in",
"GermaNet",
"using",
"its",
"string",
"representation",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L128-L151 | [
"def",
"synset",
"(",
"self",
",",
"synset_repr",
")",
":",
"parts",
"=",
"synset_repr",
".",
"split",
"(",
"'.'",
")",
"if",
"len",
"(",
"parts",
")",
"!=",
"3",
":",
"return",
"None",
"lemma",
",",
"pos",
",",
"sensenum",
"=",
"parts",
"if",
"not... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.get_synset_by_id | Builds a Synset object from the database entry with the given
ObjectId.
Arguments:
- `mongo_id`: a bson.objectid.ObjectId object | pygermanet/germanet.py | def get_synset_by_id(self, mongo_id):
'''
Builds a Synset object from the database entry with the given
ObjectId.
Arguments:
- `mongo_id`: a bson.objectid.ObjectId object
'''
cache_hit = None
if self._synset_cache is not None:
cache_hit = self... | def get_synset_by_id(self, mongo_id):
'''
Builds a Synset object from the database entry with the given
ObjectId.
Arguments:
- `mongo_id`: a bson.objectid.ObjectId object
'''
cache_hit = None
if self._synset_cache is not None:
cache_hit = self... | [
"Builds",
"a",
"Synset",
"object",
"from",
"the",
"database",
"entry",
"with",
"the",
"given",
"ObjectId",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L153-L171 | [
"def",
"get_synset_by_id",
"(",
"self",
",",
"mongo_id",
")",
":",
"cache_hit",
"=",
"None",
"if",
"self",
".",
"_synset_cache",
"is",
"not",
"None",
":",
"cache_hit",
"=",
"self",
".",
"_synset_cache",
".",
"get",
"(",
"mongo_id",
")",
"if",
"cache_hit",
... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.get_lemma_by_id | Builds a Lemma object from the database entry with the given
ObjectId.
Arguments:
- `mongo_id`: a bson.objectid.ObjectId object | pygermanet/germanet.py | def get_lemma_by_id(self, mongo_id):
'''
Builds a Lemma object from the database entry with the given
ObjectId.
Arguments:
- `mongo_id`: a bson.objectid.ObjectId object
'''
cache_hit = None
if self._lemma_cache is not None:
cache_hit = self._l... | def get_lemma_by_id(self, mongo_id):
'''
Builds a Lemma object from the database entry with the given
ObjectId.
Arguments:
- `mongo_id`: a bson.objectid.ObjectId object
'''
cache_hit = None
if self._lemma_cache is not None:
cache_hit = self._l... | [
"Builds",
"a",
"Lemma",
"object",
"from",
"the",
"database",
"entry",
"with",
"the",
"given",
"ObjectId",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L173-L191 | [
"def",
"get_lemma_by_id",
"(",
"self",
",",
"mongo_id",
")",
":",
"cache_hit",
"=",
"None",
"if",
"self",
".",
"_lemma_cache",
"is",
"not",
"None",
":",
"cache_hit",
"=",
"self",
".",
"_lemma_cache",
".",
"get",
"(",
"mongo_id",
")",
"if",
"cache_hit",
"... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | GermaNet.lemmatise | Tries to find the base form (lemma) of the given word, using
the data provided by the Projekt deutscher Wortschatz. This
method returns a list of potential lemmas.
>>> gn.lemmatise(u'Männer')
[u'Mann']
>>> gn.lemmatise(u'XYZ123')
[u'XYZ123'] | pygermanet/germanet.py | def lemmatise(self, word):
'''
Tries to find the base form (lemma) of the given word, using
the data provided by the Projekt deutscher Wortschatz. This
method returns a list of potential lemmas.
>>> gn.lemmatise(u'Männer')
[u'Mann']
>>> gn.lemmatise(u'XYZ123')
... | def lemmatise(self, word):
'''
Tries to find the base form (lemma) of the given word, using
the data provided by the Projekt deutscher Wortschatz. This
method returns a list of potential lemmas.
>>> gn.lemmatise(u'Männer')
[u'Mann']
>>> gn.lemmatise(u'XYZ123')
... | [
"Tries",
"to",
"find",
"the",
"base",
"form",
"(",
"lemma",
")",
"of",
"the",
"given",
"word",
"using",
"the",
"data",
"provided",
"by",
"the",
"Projekt",
"deutscher",
"Wortschatz",
".",
"This",
"method",
"returns",
"a",
"list",
"of",
"potential",
"lemmas"... | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/germanet.py#L193-L208 | [
"def",
"lemmatise",
"(",
"self",
",",
"word",
")",
":",
"lemmas",
"=",
"list",
"(",
"self",
".",
"_mongo_db",
".",
"lemmatiser",
".",
"find",
"(",
"{",
"'word'",
":",
"word",
"}",
")",
")",
"if",
"lemmas",
":",
"return",
"[",
"lemma",
"[",
"'lemma'... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | find_germanet_xml_files | Globs the XML files contained in the given directory and sorts
them into sections for import into the MongoDB database.
Arguments:
- `xml_path`: the path to the directory containing the GermaNet
XML files | pygermanet/mongo_import.py | def find_germanet_xml_files(xml_path):
'''
Globs the XML files contained in the given directory and sorts
them into sections for import into the MongoDB database.
Arguments:
- `xml_path`: the path to the directory containing the GermaNet
XML files
'''
xml_files = sorted(glob.glob(os.p... | def find_germanet_xml_files(xml_path):
'''
Globs the XML files contained in the given directory and sorts
them into sections for import into the MongoDB database.
Arguments:
- `xml_path`: the path to the directory containing the GermaNet
XML files
'''
xml_files = sorted(glob.glob(os.p... | [
"Globs",
"the",
"XML",
"files",
"contained",
"in",
"the",
"given",
"directory",
"and",
"sorts",
"them",
"into",
"sections",
"for",
"import",
"into",
"the",
"MongoDB",
"database",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L30-L85 | [
"def",
"find_germanet_xml_files",
"(",
"xml_path",
")",
":",
"xml_files",
"=",
"sorted",
"(",
"glob",
".",
"glob",
"(",
"os",
".",
"path",
".",
"join",
"(",
"xml_path",
",",
"'*.xml'",
")",
")",
")",
"# sort out the lexical files",
"lex_files",
"=",
"[",
"... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | warn_attribs | Error checking of XML input: check that the given node has certain
required attributes, and does not have any unrecognised
attributes.
Arguments:
- `loc`: a string with some information about the location of the
error in the XML file
- `node`: the node to check
- `recognised_attribs`: a s... | pygermanet/mongo_import.py | def warn_attribs(loc,
node,
recognised_attribs,
reqd_attribs=None):
'''
Error checking of XML input: check that the given node has certain
required attributes, and does not have any unrecognised
attributes.
Arguments:
- `loc`: a string with som... | def warn_attribs(loc,
node,
recognised_attribs,
reqd_attribs=None):
'''
Error checking of XML input: check that the given node has certain
required attributes, and does not have any unrecognised
attributes.
Arguments:
- `loc`: a string with som... | [
"Error",
"checking",
"of",
"XML",
"input",
":",
"check",
"that",
"the",
"given",
"node",
"has",
"certain",
"required",
"attributes",
"and",
"does",
"not",
"have",
"any",
"unrecognised",
"attributes",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L92-L119 | [
"def",
"warn_attribs",
"(",
"loc",
",",
"node",
",",
"recognised_attribs",
",",
"reqd_attribs",
"=",
"None",
")",
":",
"if",
"reqd_attribs",
"is",
"None",
":",
"reqd_attribs",
"=",
"recognised_attribs",
"found_attribs",
"=",
"set",
"(",
"node",
".",
"keys",
... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | read_lexical_file | Reads in a GermaNet lexical information file and returns its
contents as a list of dictionary structures.
Arguments:
- `filename`: the name of the XML file to read | pygermanet/mongo_import.py | def read_lexical_file(filename):
'''
Reads in a GermaNet lexical information file and returns its
contents as a list of dictionary structures.
Arguments:
- `filename`: the name of the XML file to read
'''
with open(filename, 'rb') as input_file:
doc = etree.parse(input_file)
sy... | def read_lexical_file(filename):
'''
Reads in a GermaNet lexical information file and returns its
contents as a list of dictionary structures.
Arguments:
- `filename`: the name of the XML file to read
'''
with open(filename, 'rb') as input_file:
doc = etree.parse(input_file)
sy... | [
"Reads",
"in",
"a",
"GermaNet",
"lexical",
"information",
"file",
"and",
"returns",
"its",
"contents",
"as",
"a",
"list",
"of",
"dictionary",
"structures",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L132-L275 | [
"def",
"read_lexical_file",
"(",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"input_file",
":",
"doc",
"=",
"etree",
".",
"parse",
"(",
"input_file",
")",
"synsets",
"=",
"[",
"]",
"assert",
"doc",
".",
"getroot",
"("... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | read_relation_file | Reads the GermaNet relation file ``gn_relations.xml`` which lists
all the relations holding between lexical units and synsets.
Arguments:
- `filename`: | pygermanet/mongo_import.py | def read_relation_file(filename):
'''
Reads the GermaNet relation file ``gn_relations.xml`` which lists
all the relations holding between lexical units and synsets.
Arguments:
- `filename`:
'''
with open(filename, 'rb') as input_file:
doc = etree.parse(input_file)
lex_rels = []... | def read_relation_file(filename):
'''
Reads the GermaNet relation file ``gn_relations.xml`` which lists
all the relations holding between lexical units and synsets.
Arguments:
- `filename`:
'''
with open(filename, 'rb') as input_file:
doc = etree.parse(input_file)
lex_rels = []... | [
"Reads",
"the",
"GermaNet",
"relation",
"file",
"gn_relations",
".",
"xml",
"which",
"lists",
"all",
"the",
"relations",
"holding",
"between",
"lexical",
"units",
"and",
"synsets",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L288-L329 | [
"def",
"read_relation_file",
"(",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"input_file",
":",
"doc",
"=",
"etree",
".",
"parse",
"(",
"input_file",
")",
"lex_rels",
"=",
"[",
"]",
"con_rels",
"=",
"[",
"]",
"assert... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | read_paraphrase_file | Reads in a GermaNet wiktionary paraphrase file and returns its
contents as a list of dictionary structures.
Arguments:
- `filename`: | pygermanet/mongo_import.py | def read_paraphrase_file(filename):
'''
Reads in a GermaNet wiktionary paraphrase file and returns its
contents as a list of dictionary structures.
Arguments:
- `filename`:
'''
with open(filename, 'rb') as input_file:
doc = etree.parse(input_file)
assert doc.getroot().tag == 'w... | def read_paraphrase_file(filename):
'''
Reads in a GermaNet wiktionary paraphrase file and returns its
contents as a list of dictionary structures.
Arguments:
- `filename`:
'''
with open(filename, 'rb') as input_file:
doc = etree.parse(input_file)
assert doc.getroot().tag == 'w... | [
"Reads",
"in",
"a",
"GermaNet",
"wiktionary",
"paraphrase",
"file",
"and",
"returns",
"its",
"contents",
"as",
"a",
"list",
"of",
"dictionary",
"structures",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L339-L376 | [
"def",
"read_paraphrase_file",
"(",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"input_file",
":",
"doc",
"=",
"etree",
".",
"parse",
"(",
"input_file",
")",
"assert",
"doc",
".",
"getroot",
"(",
")",
".",
"tag",
"=="... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | insert_lexical_information | Reads in the given lexical information files and inserts their
contents into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `lex_files`: a list of paths to XML files containing lexial
information | pygermanet/mongo_import.py | def insert_lexical_information(germanet_db, lex_files):
'''
Reads in the given lexical information files and inserts their
contents into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `lex_files`: a list of paths to XML files containing lexial
... | def insert_lexical_information(germanet_db, lex_files):
'''
Reads in the given lexical information files and inserts their
contents into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `lex_files`: a list of paths to XML files containing lexial
... | [
"Reads",
"in",
"the",
"given",
"lexical",
"information",
"files",
"and",
"inserts",
"their",
"contents",
"into",
"the",
"given",
"MongoDB",
"database",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L389-L427 | [
"def",
"insert_lexical_information",
"(",
"germanet_db",
",",
"lex_files",
")",
":",
"# drop the database collections if they already exist",
"germanet_db",
".",
"lexunits",
".",
"drop",
"(",
")",
"germanet_db",
".",
"synsets",
".",
"drop",
"(",
")",
"# inject data from... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | insert_relation_information | Reads in the given GermaNet relation file and inserts its contents
into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `gn_rels_file`: | pygermanet/mongo_import.py | def insert_relation_information(germanet_db, gn_rels_file):
'''
Reads in the given GermaNet relation file and inserts its contents
into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `gn_rels_file`:
'''
lex_rels, con_rels = read_relation_fil... | def insert_relation_information(germanet_db, gn_rels_file):
'''
Reads in the given GermaNet relation file and inserts its contents
into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `gn_rels_file`:
'''
lex_rels, con_rels = read_relation_fil... | [
"Reads",
"in",
"the",
"given",
"GermaNet",
"relation",
"file",
"and",
"inserts",
"its",
"contents",
"into",
"the",
"given",
"MongoDB",
"database",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L429-L487 | [
"def",
"insert_relation_information",
"(",
"germanet_db",
",",
"gn_rels_file",
")",
":",
"lex_rels",
",",
"con_rels",
"=",
"read_relation_file",
"(",
"gn_rels_file",
")",
"# cache the lexunits while we work on them",
"lexunits",
"=",
"{",
"}",
"for",
"lex_rel",
"in",
... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | insert_paraphrase_information | Reads in the given GermaNet relation file and inserts its contents
into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `wiktionary_files`: | pygermanet/mongo_import.py | def insert_paraphrase_information(germanet_db, wiktionary_files):
'''
Reads in the given GermaNet relation file and inserts its contents
into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `wiktionary_files`:
'''
num_paraphrases = 0
# ca... | def insert_paraphrase_information(germanet_db, wiktionary_files):
'''
Reads in the given GermaNet relation file and inserts its contents
into the given MongoDB database.
Arguments:
- `germanet_db`: a pymongo.database.Database object
- `wiktionary_files`:
'''
num_paraphrases = 0
# ca... | [
"Reads",
"in",
"the",
"given",
"GermaNet",
"relation",
"file",
"and",
"inserts",
"its",
"contents",
"into",
"the",
"given",
"MongoDB",
"database",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L489-L516 | [
"def",
"insert_paraphrase_information",
"(",
"germanet_db",
",",
"wiktionary_files",
")",
":",
"num_paraphrases",
"=",
"0",
"# cache the lexunits while we work on them",
"lexunits",
"=",
"{",
"}",
"for",
"filename",
"in",
"wiktionary_files",
":",
"paraphrases",
"=",
"re... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | insert_lemmatisation_data | Creates the lemmatiser collection in the given MongoDB instance
using the data derived from the Projekt deutscher Wortschatz.
Arguments:
- `germanet_db`: a pymongo.database.Database object | pygermanet/mongo_import.py | def insert_lemmatisation_data(germanet_db):
'''
Creates the lemmatiser collection in the given MongoDB instance
using the data derived from the Projekt deutscher Wortschatz.
Arguments:
- `germanet_db`: a pymongo.database.Database object
'''
# drop the database collection if it already exist... | def insert_lemmatisation_data(germanet_db):
'''
Creates the lemmatiser collection in the given MongoDB instance
using the data derived from the Projekt deutscher Wortschatz.
Arguments:
- `germanet_db`: a pymongo.database.Database object
'''
# drop the database collection if it already exist... | [
"Creates",
"the",
"lemmatiser",
"collection",
"in",
"the",
"given",
"MongoDB",
"instance",
"using",
"the",
"data",
"derived",
"from",
"the",
"Projekt",
"deutscher",
"Wortschatz",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L520-L542 | [
"def",
"insert_lemmatisation_data",
"(",
"germanet_db",
")",
":",
"# drop the database collection if it already exists",
"germanet_db",
".",
"lemmatiser",
".",
"drop",
"(",
")",
"num_lemmas",
"=",
"0",
"input_file",
"=",
"gzip",
".",
"open",
"(",
"os",
".",
"path",
... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | insert_infocontent_data | For every synset in GermaNet, inserts count information derived
from SDEWAC.
Arguments:
- `germanet_db`: a pymongo.database.Database object | pygermanet/mongo_import.py | def insert_infocontent_data(germanet_db):
'''
For every synset in GermaNet, inserts count information derived
from SDEWAC.
Arguments:
- `germanet_db`: a pymongo.database.Database object
'''
gnet = germanet.GermaNet(germanet_db)
# use add one smoothing
gn_counts = defa... | def insert_infocontent_data(germanet_db):
'''
For every synset in GermaNet, inserts count information derived
from SDEWAC.
Arguments:
- `germanet_db`: a pymongo.database.Database object
'''
gnet = germanet.GermaNet(germanet_db)
# use add one smoothing
gn_counts = defa... | [
"For",
"every",
"synset",
"in",
"GermaNet",
"inserts",
"count",
"information",
"derived",
"from",
"SDEWAC",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L551-L600 | [
"def",
"insert_infocontent_data",
"(",
"germanet_db",
")",
":",
"gnet",
"=",
"germanet",
".",
"GermaNet",
"(",
"germanet_db",
")",
"# use add one smoothing",
"gn_counts",
"=",
"defaultdict",
"(",
"lambda",
":",
"1.",
")",
"total_count",
"=",
"1",
"input_file",
"... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | compute_max_min_depth | For every part of speech in GermaNet, computes the maximum
min_depth in that hierarchy.
Arguments:
- `germanet_db`: a pymongo.database.Database object | pygermanet/mongo_import.py | def compute_max_min_depth(germanet_db):
'''
For every part of speech in GermaNet, computes the maximum
min_depth in that hierarchy.
Arguments:
- `germanet_db`: a pymongo.database.Database object
'''
gnet = germanet.GermaNet(germanet_db)
max_min_depths = defaultdict(lambda: -1)... | def compute_max_min_depth(germanet_db):
'''
For every part of speech in GermaNet, computes the maximum
min_depth in that hierarchy.
Arguments:
- `germanet_db`: a pymongo.database.Database object
'''
gnet = germanet.GermaNet(germanet_db)
max_min_depths = defaultdict(lambda: -1)... | [
"For",
"every",
"part",
"of",
"speech",
"in",
"GermaNet",
"computes",
"the",
"maximum",
"min_depth",
"in",
"that",
"hierarchy",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L602-L625 | [
"def",
"compute_max_min_depth",
"(",
"germanet_db",
")",
":",
"gnet",
"=",
"germanet",
".",
"GermaNet",
"(",
"germanet_db",
")",
"max_min_depths",
"=",
"defaultdict",
"(",
"lambda",
":",
"-",
"1",
")",
"for",
"synset",
"in",
"gnet",
".",
"all_synsets",
"(",
... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | main | Main function. | pygermanet/mongo_import.py | def main():
'''Main function.'''
usage = ('\n\n %prog [options] XML_PATH\n\nArguments:\n\n '
'XML_PATH the directory containing the '
'GermaNet .xml files')
parser = optparse.OptionParser(usage=usage)
parser.add_option('--host', default=None,
... | def main():
'''Main function.'''
usage = ('\n\n %prog [options] XML_PATH\n\nArguments:\n\n '
'XML_PATH the directory containing the '
'GermaNet .xml files')
parser = optparse.OptionParser(usage=usage)
parser.add_option('--host', default=None,
... | [
"Main",
"function",
"."
] | wroberts/pygermanet | python | https://github.com/wroberts/pygermanet/blob/1818c20a7e8c431c4cfb5a570ed0d850bb6dd515/pygermanet/mongo_import.py#L632-L669 | [
"def",
"main",
"(",
")",
":",
"usage",
"=",
"(",
"'\\n\\n %prog [options] XML_PATH\\n\\nArguments:\\n\\n '",
"'XML_PATH the directory containing the '",
"'GermaNet .xml files'",
")",
"parser",
"=",
"optparse",
".",
"OptionParser",
"(",
"usage",
"=",
"usage",
... | 1818c20a7e8c431c4cfb5a570ed0d850bb6dd515 |
train | Operator.handle_In | in | pql/matching.py | def handle_In(self, node):
'''in'''
try:
elts = node.elts
except AttributeError:
raise ParseError('Invalid value type for `in` operator: {0}'.format(node.__class__.__name__),
col_offset=node.col_offset)
return {'$in': list(map(self.fie... | def handle_In(self, node):
'''in'''
try:
elts = node.elts
except AttributeError:
raise ParseError('Invalid value type for `in` operator: {0}'.format(node.__class__.__name__),
col_offset=node.col_offset)
return {'$in': list(map(self.fie... | [
"in"
] | alonho/pql | python | https://github.com/alonho/pql/blob/fd8fefcb720b4325d27ab71f15a882fe5f9f77e2/pql/matching.py#L302-L309 | [
"def",
"handle_In",
"(",
"self",
",",
"node",
")",
":",
"try",
":",
"elts",
"=",
"node",
".",
"elts",
"except",
"AttributeError",
":",
"raise",
"ParseError",
"(",
"'Invalid value type for `in` operator: {0}'",
".",
"format",
"(",
"node",
".",
"__class__",
".",... | fd8fefcb720b4325d27ab71f15a882fe5f9f77e2 |
train | TextFSMValue.AssignVar | Assign a value to this Value. | jtextfsm.py | def AssignVar(self, value):
"""Assign a value to this Value."""
self.value = value
# Call OnAssignVar on options.
[option.OnAssignVar() for option in self.options] | def AssignVar(self, value):
"""Assign a value to this Value."""
self.value = value
# Call OnAssignVar on options.
[option.OnAssignVar() for option in self.options] | [
"Assign",
"a",
"value",
"to",
"this",
"Value",
"."
] | jonathanslenders/textfsm | python | https://github.com/jonathanslenders/textfsm/blob/cca5084512d14bc367205aceb34c938ac1c65daf/jtextfsm.py#L223-L227 | [
"def",
"AssignVar",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"value",
"=",
"value",
"# Call OnAssignVar on options.",
"[",
"option",
".",
"OnAssignVar",
"(",
")",
"for",
"option",
"in",
"self",
".",
"options",
"]"
] | cca5084512d14bc367205aceb34c938ac1c65daf |
train | TextFSMValue.Parse | Parse a 'Value' declaration.
Args:
value: String line from a template file, must begin with 'Value '.
Raises:
TextFSMTemplateError: Value declaration contains an error. | jtextfsm.py | def Parse(self, value):
"""Parse a 'Value' declaration.
Args:
value: String line from a template file, must begin with 'Value '.
Raises:
TextFSMTemplateError: Value declaration contains an error.
"""
value_line = value.split(' ')
if len(value_line) < 3:
raise TextFSMTemplat... | def Parse(self, value):
"""Parse a 'Value' declaration.
Args:
value: String line from a template file, must begin with 'Value '.
Raises:
TextFSMTemplateError: Value declaration contains an error.
"""
value_line = value.split(' ')
if len(value_line) < 3:
raise TextFSMTemplat... | [
"Parse",
"a",
"Value",
"declaration",
"."
] | jonathanslenders/textfsm | python | https://github.com/jonathanslenders/textfsm/blob/cca5084512d14bc367205aceb34c938ac1c65daf/jtextfsm.py#L251-L291 | [
"def",
"Parse",
"(",
"self",
",",
"value",
")",
":",
"value_line",
"=",
"value",
".",
"split",
"(",
"' '",
")",
"if",
"len",
"(",
"value_line",
")",
"<",
"3",
":",
"raise",
"TextFSMTemplateError",
"(",
"'Expect at least 3 tokens on line.'",
")",
"if",
"not... | cca5084512d14bc367205aceb34c938ac1c65daf |
train | TextFSM._CheckLine | Passes the line through each rule until a match is made.
Args:
line: A string, the current input line. | jtextfsm.py | def _CheckLine(self, line):
"""Passes the line through each rule until a match is made.
Args:
line: A string, the current input line.
"""
for rule in self._cur_state:
matched = self._CheckRule(rule, line)
if matched:
for value in matched.groupdict():
self._AssignVar(... | def _CheckLine(self, line):
"""Passes the line through each rule until a match is made.
Args:
line: A string, the current input line.
"""
for rule in self._cur_state:
matched = self._CheckRule(rule, line)
if matched:
for value in matched.groupdict():
self._AssignVar(... | [
"Passes",
"the",
"line",
"through",
"each",
"rule",
"until",
"a",
"match",
"is",
"made",
"."
] | jonathanslenders/textfsm | python | https://github.com/jonathanslenders/textfsm/blob/cca5084512d14bc367205aceb34c938ac1c65daf/jtextfsm.py#L866-L884 | [
"def",
"_CheckLine",
"(",
"self",
",",
"line",
")",
":",
"for",
"rule",
"in",
"self",
".",
"_cur_state",
":",
"matched",
"=",
"self",
".",
"_CheckRule",
"(",
"rule",
",",
"line",
")",
"if",
"matched",
":",
"for",
"value",
"in",
"matched",
".",
"group... | cca5084512d14bc367205aceb34c938ac1c65daf |
train | _make_graphite_api_points_list | Make graphite-api data points dictionary from Influxdb ResultSet data | graphite_influxdb.py | def _make_graphite_api_points_list(influxdb_data):
"""Make graphite-api data points dictionary from Influxdb ResultSet data"""
_data = {}
for key in influxdb_data.keys():
_data[key[0]] = [(datetime.datetime.fromtimestamp(float(d['time'])),
d['value']) for d in influxdb_data... | def _make_graphite_api_points_list(influxdb_data):
"""Make graphite-api data points dictionary from Influxdb ResultSet data"""
_data = {}
for key in influxdb_data.keys():
_data[key[0]] = [(datetime.datetime.fromtimestamp(float(d['time'])),
d['value']) for d in influxdb_data... | [
"Make",
"graphite",
"-",
"api",
"data",
"points",
"dictionary",
"from",
"Influxdb",
"ResultSet",
"data"
] | vimeo/graphite-influxdb | python | https://github.com/vimeo/graphite-influxdb/blob/56e4aeec57f39c90f14f3fbec57641b90d06c08b/graphite_influxdb.py#L90-L96 | [
"def",
"_make_graphite_api_points_list",
"(",
"influxdb_data",
")",
":",
"_data",
"=",
"{",
"}",
"for",
"key",
"in",
"influxdb_data",
".",
"keys",
"(",
")",
":",
"_data",
"[",
"key",
"[",
"0",
"]",
"]",
"=",
"[",
"(",
"datetime",
".",
"datetime",
".",
... | 56e4aeec57f39c90f14f3fbec57641b90d06c08b |
train | InfluxdbFinder._setup_logger | Setup log level and log file if set | graphite_influxdb.py | def _setup_logger(self, level, log_file):
"""Setup log level and log file if set"""
if logger.handlers:
return
level = getattr(logging, level.upper())
logger.setLevel(level)
formatter = logging.Formatter(
'[%(levelname)s] %(asctime)s - %(module)s.%(funcNam... | def _setup_logger(self, level, log_file):
"""Setup log level and log file if set"""
if logger.handlers:
return
level = getattr(logging, level.upper())
logger.setLevel(level)
formatter = logging.Formatter(
'[%(levelname)s] %(asctime)s - %(module)s.%(funcNam... | [
"Setup",
"log",
"level",
"and",
"log",
"file",
"if",
"set"
] | vimeo/graphite-influxdb | python | https://github.com/vimeo/graphite-influxdb/blob/56e4aeec57f39c90f14f3fbec57641b90d06c08b/graphite_influxdb.py#L166-L186 | [
"def",
"_setup_logger",
"(",
"self",
",",
"level",
",",
"log_file",
")",
":",
"if",
"logger",
".",
"handlers",
":",
"return",
"level",
"=",
"getattr",
"(",
"logging",
",",
"level",
".",
"upper",
"(",
")",
")",
"logger",
".",
"setLevel",
"(",
"level",
... | 56e4aeec57f39c90f14f3fbec57641b90d06c08b |
train | InfluxdbFinder.compile_regex | Turn glob (graphite) queries into compiled regex
* becomes .*
. becomes \.
fmt argument is so that caller can control anchoring (must contain exactly 1 {0} ! | graphite_influxdb.py | def compile_regex(self, fmt, query):
"""Turn glob (graphite) queries into compiled regex
* becomes .*
. becomes \.
fmt argument is so that caller can control anchoring (must contain exactly 1 {0} !"""
return re.compile(fmt.format(
query.pattern.replace('.', '\.').repl... | def compile_regex(self, fmt, query):
"""Turn glob (graphite) queries into compiled regex
* becomes .*
. becomes \.
fmt argument is so that caller can control anchoring (must contain exactly 1 {0} !"""
return re.compile(fmt.format(
query.pattern.replace('.', '\.').repl... | [
"Turn",
"glob",
"(",
"graphite",
")",
"queries",
"into",
"compiled",
"regex",
"*",
"becomes",
".",
"*",
".",
"becomes",
"\\",
".",
"fmt",
"argument",
"is",
"so",
"that",
"caller",
"can",
"control",
"anchoring",
"(",
"must",
"contain",
"exactly",
"1",
"{"... | vimeo/graphite-influxdb | python | https://github.com/vimeo/graphite-influxdb/blob/56e4aeec57f39c90f14f3fbec57641b90d06c08b/graphite_influxdb.py#L230-L238 | [
"def",
"compile_regex",
"(",
"self",
",",
"fmt",
",",
"query",
")",
":",
"return",
"re",
".",
"compile",
"(",
"fmt",
".",
"format",
"(",
"query",
".",
"pattern",
".",
"replace",
"(",
"'.'",
",",
"'\\.'",
")",
".",
"replace",
"(",
"'*'",
",",
"'[^\\... | 56e4aeec57f39c90f14f3fbec57641b90d06c08b |
train | find | Gets an <expression> and optional <schema>.
<expression> should be a string of python code.
<schema> should be a dictionary mapping field names to types. | pql/__init__.py | def find(expression, schema=None):
'''
Gets an <expression> and optional <schema>.
<expression> should be a string of python code.
<schema> should be a dictionary mapping field names to types.
'''
parser = SchemaFreeParser() if schema is None else SchemaAwareParser(schema)
return parser.pars... | def find(expression, schema=None):
'''
Gets an <expression> and optional <schema>.
<expression> should be a string of python code.
<schema> should be a dictionary mapping field names to types.
'''
parser = SchemaFreeParser() if schema is None else SchemaAwareParser(schema)
return parser.pars... | [
"Gets",
"an",
"<expression",
">",
"and",
"optional",
"<schema",
">",
".",
"<expression",
">",
"should",
"be",
"a",
"string",
"of",
"python",
"code",
".",
"<schema",
">",
"should",
"be",
"a",
"dictionary",
"mapping",
"field",
"names",
"to",
"types",
"."
] | alonho/pql | python | https://github.com/alonho/pql/blob/fd8fefcb720b4325d27ab71f15a882fe5f9f77e2/pql/__init__.py#L7-L14 | [
"def",
"find",
"(",
"expression",
",",
"schema",
"=",
"None",
")",
":",
"parser",
"=",
"SchemaFreeParser",
"(",
")",
"if",
"schema",
"is",
"None",
"else",
"SchemaAwareParser",
"(",
"schema",
")",
"return",
"parser",
".",
"parse",
"(",
"expression",
")"
] | fd8fefcb720b4325d27ab71f15a882fe5f9f77e2 |
train | sort | Gets a list of <fields> to sort by.
Also supports getting a single string for sorting by one field.
Reverse sort is supported by appending '-' to the field name.
Example: sort(['age', '-height']) will sort by ascending age and descending height. | pql/__init__.py | def sort(fields):
'''
Gets a list of <fields> to sort by.
Also supports getting a single string for sorting by one field.
Reverse sort is supported by appending '-' to the field name.
Example: sort(['age', '-height']) will sort by ascending age and descending height.
'''
from pymongo import ... | def sort(fields):
'''
Gets a list of <fields> to sort by.
Also supports getting a single string for sorting by one field.
Reverse sort is supported by appending '-' to the field name.
Example: sort(['age', '-height']) will sort by ascending age and descending height.
'''
from pymongo import ... | [
"Gets",
"a",
"list",
"of",
"<fields",
">",
"to",
"sort",
"by",
".",
"Also",
"supports",
"getting",
"a",
"single",
"string",
"for",
"sorting",
"by",
"one",
"field",
".",
"Reverse",
"sort",
"is",
"supported",
"by",
"appending",
"-",
"to",
"the",
"field",
... | alonho/pql | python | https://github.com/alonho/pql/blob/fd8fefcb720b4325d27ab71f15a882fe5f9f77e2/pql/__init__.py#L73-L97 | [
"def",
"sort",
"(",
"fields",
")",
":",
"from",
"pymongo",
"import",
"ASCENDING",
",",
"DESCENDING",
"from",
"bson",
"import",
"SON",
"if",
"isinstance",
"(",
"fields",
",",
"str",
")",
":",
"fields",
"=",
"[",
"fields",
"]",
"if",
"not",
"hasattr",
"(... | fd8fefcb720b4325d27ab71f15a882fe5f9f77e2 |
train | ordered | Return sorted version of nested dicts/lists for comparing.
Modified from:
http://stackoverflow.com/a/25851972 | bloop/util.py | def ordered(obj):
"""
Return sorted version of nested dicts/lists for comparing.
Modified from:
http://stackoverflow.com/a/25851972
"""
if isinstance(obj, collections.abc.Mapping):
return sorted((k, ordered(v)) for k, v in obj.items())
# Special case str since it's a collections.abc... | def ordered(obj):
"""
Return sorted version of nested dicts/lists for comparing.
Modified from:
http://stackoverflow.com/a/25851972
"""
if isinstance(obj, collections.abc.Mapping):
return sorted((k, ordered(v)) for k, v in obj.items())
# Special case str since it's a collections.abc... | [
"Return",
"sorted",
"version",
"of",
"nested",
"dicts",
"/",
"lists",
"for",
"comparing",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/util.py#L65-L80 | [
"def",
"ordered",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"collections",
".",
"abc",
".",
"Mapping",
")",
":",
"return",
"sorted",
"(",
"(",
"k",
",",
"ordered",
"(",
"v",
")",
")",
"for",
"k",
",",
"v",
"in",
"obj",
".",
"it... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | walk_subclasses | Does not yield the input class | bloop/util.py | def walk_subclasses(root):
"""Does not yield the input class"""
classes = [root]
visited = set()
while classes:
cls = classes.pop()
if cls is type or cls in visited:
continue
classes.extend(cls.__subclasses__())
visited.add(cls)
if cls is not root:
... | def walk_subclasses(root):
"""Does not yield the input class"""
classes = [root]
visited = set()
while classes:
cls = classes.pop()
if cls is type or cls in visited:
continue
classes.extend(cls.__subclasses__())
visited.add(cls)
if cls is not root:
... | [
"Does",
"not",
"yield",
"the",
"input",
"class"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/util.py#L83-L94 | [
"def",
"walk_subclasses",
"(",
"root",
")",
":",
"classes",
"=",
"[",
"root",
"]",
"visited",
"=",
"set",
"(",
")",
"while",
"classes",
":",
"cls",
"=",
"classes",
".",
"pop",
"(",
")",
"if",
"cls",
"is",
"type",
"or",
"cls",
"in",
"visited",
":",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | dump_key | dump the hash (and range, if there is one) key(s) of an object into
a dynamo-friendly format.
returns {dynamo_name: {type: value} for dynamo_name in hash/range keys} | bloop/util.py | def dump_key(engine, obj):
"""dump the hash (and range, if there is one) key(s) of an object into
a dynamo-friendly format.
returns {dynamo_name: {type: value} for dynamo_name in hash/range keys}
"""
key = {}
for key_column in obj.Meta.keys:
key_value = getattr(obj, key_column.name, mis... | def dump_key(engine, obj):
"""dump the hash (and range, if there is one) key(s) of an object into
a dynamo-friendly format.
returns {dynamo_name: {type: value} for dynamo_name in hash/range keys}
"""
key = {}
for key_column in obj.Meta.keys:
key_value = getattr(obj, key_column.name, mis... | [
"dump",
"the",
"hash",
"(",
"and",
"range",
"if",
"there",
"is",
"one",
")",
"key",
"(",
"s",
")",
"of",
"an",
"object",
"into",
"a",
"dynamo",
"-",
"friendly",
"format",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/util.py#L125-L142 | [
"def",
"dump_key",
"(",
"engine",
",",
"obj",
")",
":",
"key",
"=",
"{",
"}",
"for",
"key_column",
"in",
"obj",
".",
"Meta",
".",
"keys",
":",
"key_value",
"=",
"getattr",
"(",
"obj",
",",
"key_column",
".",
"name",
",",
"missing",
")",
"if",
"key_... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | new_expiry | Return an expiration `days` in the future | examples/mixins.py | def new_expiry(days=DEFAULT_PASTE_LIFETIME_DAYS):
"""Return an expiration `days` in the future"""
now = delorean.Delorean()
return now + datetime.timedelta(days=days) | def new_expiry(days=DEFAULT_PASTE_LIFETIME_DAYS):
"""Return an expiration `days` in the future"""
now = delorean.Delorean()
return now + datetime.timedelta(days=days) | [
"Return",
"an",
"expiration",
"days",
"in",
"the",
"future"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/examples/mixins.py#L14-L17 | [
"def",
"new_expiry",
"(",
"days",
"=",
"DEFAULT_PASTE_LIFETIME_DAYS",
")",
":",
"now",
"=",
"delorean",
".",
"Delorean",
"(",
")",
"return",
"now",
"+",
"datetime",
".",
"timedelta",
"(",
"days",
"=",
"days",
")"
] | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | sync | Mark the object as having been persisted at least once.
Store the latest snapshot of all marked values. | bloop/conditions.py | def sync(obj, engine):
"""Mark the object as having been persisted at least once.
Store the latest snapshot of all marked values."""
snapshot = Condition()
# Only expect values (or lack of a value) for columns that have been explicitly set
for column in sorted(_obj_tracking[obj]["marked"], key=lamb... | def sync(obj, engine):
"""Mark the object as having been persisted at least once.
Store the latest snapshot of all marked values."""
snapshot = Condition()
# Only expect values (or lack of a value) for columns that have been explicitly set
for column in sorted(_obj_tracking[obj]["marked"], key=lamb... | [
"Mark",
"the",
"object",
"as",
"having",
"been",
"persisted",
"at",
"least",
"once",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L63-L78 | [
"def",
"sync",
"(",
"obj",
",",
"engine",
")",
":",
"snapshot",
"=",
"Condition",
"(",
")",
"# Only expect values (or lack of a value) for columns that have been explicitly set",
"for",
"column",
"in",
"sorted",
"(",
"_obj_tracking",
"[",
"obj",
"]",
"[",
"\"marked\""... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | printable_name | Provided for debug output when rendering conditions.
User.name[3]["foo"][0]["bar"] -> name[3].foo[0].bar | bloop/conditions.py | def printable_name(column, path=None):
"""Provided for debug output when rendering conditions.
User.name[3]["foo"][0]["bar"] -> name[3].foo[0].bar
"""
pieces = [column.name]
path = path or path_of(column)
for segment in path:
if isinstance(segment, str):
pieces.append(segmen... | def printable_name(column, path=None):
"""Provided for debug output when rendering conditions.
User.name[3]["foo"][0]["bar"] -> name[3].foo[0].bar
"""
pieces = [column.name]
path = path or path_of(column)
for segment in path:
if isinstance(segment, str):
pieces.append(segmen... | [
"Provided",
"for",
"debug",
"output",
"when",
"rendering",
"conditions",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L887-L899 | [
"def",
"printable_name",
"(",
"column",
",",
"path",
"=",
"None",
")",
":",
"pieces",
"=",
"[",
"column",
".",
"name",
"]",
"path",
"=",
"path",
"or",
"path_of",
"(",
"column",
")",
"for",
"segment",
"in",
"path",
":",
"if",
"isinstance",
"(",
"segme... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | iter_conditions | Yield all conditions within the given condition.
If the root condition is and/or/not, it is not yielded (unless a cyclic reference to it is found). | bloop/conditions.py | def iter_conditions(condition):
"""Yield all conditions within the given condition.
If the root condition is and/or/not, it is not yielded (unless a cyclic reference to it is found)."""
conditions = list()
visited = set()
# Has to be split out, since we don't want to visit the root (for cyclic cond... | def iter_conditions(condition):
"""Yield all conditions within the given condition.
If the root condition is and/or/not, it is not yielded (unless a cyclic reference to it is found)."""
conditions = list()
visited = set()
# Has to be split out, since we don't want to visit the root (for cyclic cond... | [
"Yield",
"all",
"conditions",
"within",
"the",
"given",
"condition",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L914-L935 | [
"def",
"iter_conditions",
"(",
"condition",
")",
":",
"conditions",
"=",
"list",
"(",
")",
"visited",
"=",
"set",
"(",
")",
"# Has to be split out, since we don't want to visit the root (for cyclic conditions)",
"# but we don't want to yield it (if it's non-cyclic) because this onl... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | iter_columns | Yield all columns in the condition or its inner conditions.
Unwraps proxies when the condition's column (or any of its values) include paths. | bloop/conditions.py | def iter_columns(condition):
"""
Yield all columns in the condition or its inner conditions.
Unwraps proxies when the condition's column (or any of its values) include paths.
"""
# Like iter_conditions, this can't live in each condition without going possibly infinite on the
# recursion, or pas... | def iter_columns(condition):
"""
Yield all columns in the condition or its inner conditions.
Unwraps proxies when the condition's column (or any of its values) include paths.
"""
# Like iter_conditions, this can't live in each condition without going possibly infinite on the
# recursion, or pas... | [
"Yield",
"all",
"columns",
"in",
"the",
"condition",
"or",
"its",
"inner",
"conditions",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L938-L970 | [
"def",
"iter_columns",
"(",
"condition",
")",
":",
"# Like iter_conditions, this can't live in each condition without going possibly infinite on the",
"# recursion, or passing the visited set through every call. That makes the signature ugly, so we",
"# take care of it here. Luckily, it's pretty e... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | ReferenceTracker._value_ref | inner=True uses column.typedef.inner_type instead of column.typedef | bloop/conditions.py | def _value_ref(self, column, value, *, dumped=False, inner=False):
"""inner=True uses column.typedef.inner_type instead of column.typedef"""
ref = ":v{}".format(self.next_index)
# Need to dump this value
if not dumped:
typedef = column.typedef
for segment in path... | def _value_ref(self, column, value, *, dumped=False, inner=False):
"""inner=True uses column.typedef.inner_type instead of column.typedef"""
ref = ":v{}".format(self.next_index)
# Need to dump this value
if not dumped:
typedef = column.typedef
for segment in path... | [
"inner",
"=",
"True",
"uses",
"column",
".",
"typedef",
".",
"inner_type",
"instead",
"of",
"column",
".",
"typedef"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L166-L181 | [
"def",
"_value_ref",
"(",
"self",
",",
"column",
",",
"value",
",",
"*",
",",
"dumped",
"=",
"False",
",",
"inner",
"=",
"False",
")",
":",
"ref",
"=",
"\":v{}\"",
".",
"format",
"(",
"self",
".",
"next_index",
")",
"# Need to dump this value",
"if",
"... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | ReferenceTracker.any_ref | Returns a NamedTuple of (name, type, value) for any type of reference.
.. code-block:: python
# Name ref
>>> tracker.any_ref(column=User.email)
Reference(name='email', type='name', value=None)
# Value ref
>>> tracker.any_ref(column=User.email, value... | bloop/conditions.py | def any_ref(self, *, column, value=missing, dumped=False, inner=False):
"""Returns a NamedTuple of (name, type, value) for any type of reference.
.. code-block:: python
# Name ref
>>> tracker.any_ref(column=User.email)
Reference(name='email', type='name', value=None... | def any_ref(self, *, column, value=missing, dumped=False, inner=False):
"""Returns a NamedTuple of (name, type, value) for any type of reference.
.. code-block:: python
# Name ref
>>> tracker.any_ref(column=User.email)
Reference(name='email', type='name', value=None... | [
"Returns",
"a",
"NamedTuple",
"of",
"(",
"name",
"type",
"value",
")",
"for",
"any",
"type",
"of",
"reference",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L183-L227 | [
"def",
"any_ref",
"(",
"self",
",",
"*",
",",
"column",
",",
"value",
"=",
"missing",
",",
"dumped",
"=",
"False",
",",
"inner",
"=",
"False",
")",
":",
"# Can't use None since it's a legal value for comparisons (attribute_not_exists)",
"if",
"value",
"is",
"missi... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | ReferenceTracker.pop_refs | Decrement the usage of each ref by 1.
If this was the last use of a ref, remove it from attr_names or attr_values. | bloop/conditions.py | def pop_refs(self, *refs):
"""Decrement the usage of each ref by 1.
If this was the last use of a ref, remove it from attr_names or attr_values.
"""
for ref in refs:
name = ref.name
count = self.counts[name]
# Not tracking this ref
if coun... | def pop_refs(self, *refs):
"""Decrement the usage of each ref by 1.
If this was the last use of a ref, remove it from attr_names or attr_values.
"""
for ref in refs:
name = ref.name
count = self.counts[name]
# Not tracking this ref
if coun... | [
"Decrement",
"the",
"usage",
"of",
"each",
"ref",
"by",
"1",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L229-L253 | [
"def",
"pop_refs",
"(",
"self",
",",
"*",
"refs",
")",
":",
"for",
"ref",
"in",
"refs",
":",
"name",
"=",
"ref",
".",
"name",
"count",
"=",
"self",
".",
"counts",
"[",
"name",
"]",
"# Not tracking this ref",
"if",
"count",
"<",
"1",
":",
"continue",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | ConditionRenderer.render | Main entry point for rendering multiple expressions. All parameters are optional, except obj when
atomic or update are True.
:param obj: *(Optional)* An object to render an atomic condition or update expression for. Required if
update or atomic are true. Default is False.
:param ... | bloop/conditions.py | def render(self, obj=None, condition=None, atomic=False, update=False, filter=None, projection=None, key=None):
"""Main entry point for rendering multiple expressions. All parameters are optional, except obj when
atomic or update are True.
:param obj: *(Optional)* An object to render an atomic... | def render(self, obj=None, condition=None, atomic=False, update=False, filter=None, projection=None, key=None):
"""Main entry point for rendering multiple expressions. All parameters are optional, except obj when
atomic or update are True.
:param obj: *(Optional)* An object to render an atomic... | [
"Main",
"entry",
"point",
"for",
"rendering",
"multiple",
"expressions",
".",
"All",
"parameters",
"are",
"optional",
"except",
"obj",
"when",
"atomic",
"or",
"update",
"are",
"True",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L299-L339 | [
"def",
"render",
"(",
"self",
",",
"obj",
"=",
"None",
",",
"condition",
"=",
"None",
",",
"atomic",
"=",
"False",
",",
"update",
"=",
"False",
",",
"filter",
"=",
"None",
",",
"projection",
"=",
"None",
",",
"key",
"=",
"None",
")",
":",
"if",
"... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | ConditionRenderer.rendered | The rendered wire format for all conditions that have been rendered. Rendered conditions are never
cleared. A new :class:`~bloop.conditions.ConditionRenderer` should be used for each operation. | bloop/conditions.py | def rendered(self):
"""The rendered wire format for all conditions that have been rendered. Rendered conditions are never
cleared. A new :class:`~bloop.conditions.ConditionRenderer` should be used for each operation."""
expressions = {k: v for (k, v) in self.expressions.items() if v is not Non... | def rendered(self):
"""The rendered wire format for all conditions that have been rendered. Rendered conditions are never
cleared. A new :class:`~bloop.conditions.ConditionRenderer` should be used for each operation."""
expressions = {k: v for (k, v) in self.expressions.items() if v is not Non... | [
"The",
"rendered",
"wire",
"format",
"for",
"all",
"conditions",
"that",
"have",
"been",
"rendered",
".",
"Rendered",
"conditions",
"are",
"never",
"cleared",
".",
"A",
"new",
":",
"class",
":",
"~bloop",
".",
"conditions",
".",
"ConditionRenderer",
"should",
... | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/conditions.py#L388-L396 | [
"def",
"rendered",
"(",
"self",
")",
":",
"expressions",
"=",
"{",
"k",
":",
"v",
"for",
"(",
"k",
",",
"v",
")",
"in",
"self",
".",
"expressions",
".",
"items",
"(",
")",
"if",
"v",
"is",
"not",
"None",
"}",
"if",
"self",
".",
"refs",
".",
"... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Stream._unpack | Replaces the attr dict at the given key with an instance of a Model | bloop/stream/stream.py | def _unpack(self, record, key, expected):
"""Replaces the attr dict at the given key with an instance of a Model"""
attrs = record.get(key)
if attrs is None:
return
obj = unpack_from_dynamodb(
attrs=attrs,
expected=expected,
model=self.mode... | def _unpack(self, record, key, expected):
"""Replaces the attr dict at the given key with an instance of a Model"""
attrs = record.get(key)
if attrs is None:
return
obj = unpack_from_dynamodb(
attrs=attrs,
expected=expected,
model=self.mode... | [
"Replaces",
"the",
"attr",
"dict",
"at",
"the",
"given",
"key",
"with",
"an",
"instance",
"of",
"a",
"Model"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/stream.py#L79-L91 | [
"def",
"_unpack",
"(",
"self",
",",
"record",
",",
"key",
",",
"expected",
")",
":",
"attrs",
"=",
"record",
".",
"get",
"(",
"key",
")",
"if",
"attrs",
"is",
"None",
":",
"return",
"obj",
"=",
"unpack_from_dynamodb",
"(",
"attrs",
"=",
"attrs",
",",... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | reformat_record | Repack a record into a cleaner structure for consumption. | bloop/stream/shard.py | def reformat_record(record):
"""Repack a record into a cleaner structure for consumption."""
return {
"key": record["dynamodb"].get("Keys", None),
"new": record["dynamodb"].get("NewImage", None),
"old": record["dynamodb"].get("OldImage", None),
"meta": {
"created_at"... | def reformat_record(record):
"""Repack a record into a cleaner structure for consumption."""
return {
"key": record["dynamodb"].get("Keys", None),
"new": record["dynamodb"].get("NewImage", None),
"old": record["dynamodb"].get("OldImage", None),
"meta": {
"created_at"... | [
"Repack",
"a",
"record",
"into",
"a",
"cleaner",
"structure",
"for",
"consumption",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/shard.py#L287-L303 | [
"def",
"reformat_record",
"(",
"record",
")",
":",
"return",
"{",
"\"key\"",
":",
"record",
"[",
"\"dynamodb\"",
"]",
".",
"get",
"(",
"\"Keys\"",
",",
"None",
")",
",",
"\"new\"",
":",
"record",
"[",
"\"dynamodb\"",
"]",
".",
"get",
"(",
"\"NewImage\"",... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | unpack_shards | List[Dict] -> Dict[shard_id, Shard].
Each Shards' parent/children are hooked up with the other Shards in the list. | bloop/stream/shard.py | def unpack_shards(shards, stream_arn, session):
"""List[Dict] -> Dict[shard_id, Shard].
Each Shards' parent/children are hooked up with the other Shards in the list.
"""
if not shards:
return {}
# When unpacking tokens, shard id key is "shard_id"
# When unpacking DescribeStream respons... | def unpack_shards(shards, stream_arn, session):
"""List[Dict] -> Dict[shard_id, Shard].
Each Shards' parent/children are hooked up with the other Shards in the list.
"""
if not shards:
return {}
# When unpacking tokens, shard id key is "shard_id"
# When unpacking DescribeStream respons... | [
"List",
"[",
"Dict",
"]",
"-",
">",
"Dict",
"[",
"shard_id",
"Shard",
"]",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/shard.py#L306-L329 | [
"def",
"unpack_shards",
"(",
"shards",
",",
"stream_arn",
",",
"session",
")",
":",
"if",
"not",
"shards",
":",
"return",
"{",
"}",
"# When unpacking tokens, shard id key is \"shard_id\"",
"# When unpacking DescribeStream responses, shard id key is \"ShardId\"",
"if",
"\"Shar... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Shard.token | JSON-serializable representation of the current Shard state.
The token is enough to rebuild the Shard as part of rebuilding a Stream.
:returns: Shard state as a json-friendly dict
:rtype: dict | bloop/stream/shard.py | def token(self):
"""JSON-serializable representation of the current Shard state.
The token is enough to rebuild the Shard as part of rebuilding a Stream.
:returns: Shard state as a json-friendly dict
:rtype: dict
"""
if self.iterator_type in RELATIVE_ITERATORS:
... | def token(self):
"""JSON-serializable representation of the current Shard state.
The token is enough to rebuild the Shard as part of rebuilding a Stream.
:returns: Shard state as a json-friendly dict
:rtype: dict
"""
if self.iterator_type in RELATIVE_ITERATORS:
... | [
"JSON",
"-",
"serializable",
"representation",
"of",
"the",
"current",
"Shard",
"state",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/shard.py#L127-L149 | [
"def",
"token",
"(",
"self",
")",
":",
"if",
"self",
".",
"iterator_type",
"in",
"RELATIVE_ITERATORS",
":",
"logger",
".",
"warning",
"(",
"\"creating shard token at non-exact location \\\"{}\\\"\"",
".",
"format",
"(",
"self",
".",
"iterator_type",
")",
")",
"tok... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Shard.walk_tree | Generator that yields each :class:`~bloop.stream.shard.Shard` by walking the shard's children in order. | bloop/stream/shard.py | def walk_tree(self):
"""Generator that yields each :class:`~bloop.stream.shard.Shard` by walking the shard's children in order."""
shards = collections.deque([self])
while shards:
shard = shards.popleft()
yield shard
shards.extend(shard.children) | def walk_tree(self):
"""Generator that yields each :class:`~bloop.stream.shard.Shard` by walking the shard's children in order."""
shards = collections.deque([self])
while shards:
shard = shards.popleft()
yield shard
shards.extend(shard.children) | [
"Generator",
"that",
"yields",
"each",
":",
"class",
":",
"~bloop",
".",
"stream",
".",
"shard",
".",
"Shard",
"by",
"walking",
"the",
"shard",
"s",
"children",
"in",
"order",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/shard.py#L151-L157 | [
"def",
"walk_tree",
"(",
"self",
")",
":",
"shards",
"=",
"collections",
".",
"deque",
"(",
"[",
"self",
"]",
")",
"while",
"shards",
":",
"shard",
"=",
"shards",
".",
"popleft",
"(",
")",
"yield",
"shard",
"shards",
".",
"extend",
"(",
"shard",
".",... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Shard.jump_to | Move to a new position in the shard using the standard parameters to GetShardIterator.
:param str iterator_type: "trim_horizon", "at_sequence", "after_sequence", "latest"
:param str sequence_number: *(Optional)* Sequence number to use with at/after sequence. Default is None. | bloop/stream/shard.py | def jump_to(self, *, iterator_type, sequence_number=None):
"""Move to a new position in the shard using the standard parameters to GetShardIterator.
:param str iterator_type: "trim_horizon", "at_sequence", "after_sequence", "latest"
:param str sequence_number: *(Optional)* Sequence number to us... | def jump_to(self, *, iterator_type, sequence_number=None):
"""Move to a new position in the shard using the standard parameters to GetShardIterator.
:param str iterator_type: "trim_horizon", "at_sequence", "after_sequence", "latest"
:param str sequence_number: *(Optional)* Sequence number to us... | [
"Move",
"to",
"a",
"new",
"position",
"in",
"the",
"shard",
"using",
"the",
"standard",
"parameters",
"to",
"GetShardIterator",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/shard.py#L159-L173 | [
"def",
"jump_to",
"(",
"self",
",",
"*",
",",
"iterator_type",
",",
"sequence_number",
"=",
"None",
")",
":",
"# Just a simple wrapper; let the caller handle RecordsExpired",
"self",
".",
"iterator_id",
"=",
"self",
".",
"session",
".",
"get_shard_iterator",
"(",
"s... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Shard.seek_to | Move the Shard's iterator to the earliest record after the :class:`~datetime.datetime` time.
Returns the first records at or past ``position``. If the list is empty,
the seek failed to find records, either because the Shard is exhausted or it
reached the HEAD of an open Shard.
:param ... | bloop/stream/shard.py | def seek_to(self, position):
"""Move the Shard's iterator to the earliest record after the :class:`~datetime.datetime` time.
Returns the first records at or past ``position``. If the list is empty,
the seek failed to find records, either because the Shard is exhausted or it
reached the... | def seek_to(self, position):
"""Move the Shard's iterator to the earliest record after the :class:`~datetime.datetime` time.
Returns the first records at or past ``position``. If the list is empty,
the seek failed to find records, either because the Shard is exhausted or it
reached the... | [
"Move",
"the",
"Shard",
"s",
"iterator",
"to",
"the",
"earliest",
"record",
"after",
"the",
":",
"class",
":",
"~datetime",
".",
"datetime",
"time",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/shard.py#L175-L204 | [
"def",
"seek_to",
"(",
"self",
",",
"position",
")",
":",
"# 0) We have no way to associate the date with a position,",
"# so we have to scan the shard from the beginning.",
"self",
".",
"jump_to",
"(",
"iterator_type",
"=",
"\"trim_horizon\"",
")",
"position",
"=",
"int",... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Shard.load_children | If the Shard doesn't have any children, tries to find some from DescribeStream.
If the Shard is open this won't find any children, so an empty response doesn't
mean the Shard will **never** have children. | bloop/stream/shard.py | def load_children(self):
"""If the Shard doesn't have any children, tries to find some from DescribeStream.
If the Shard is open this won't find any children, so an empty response doesn't
mean the Shard will **never** have children.
"""
# Child count is fixed the first time any ... | def load_children(self):
"""If the Shard doesn't have any children, tries to find some from DescribeStream.
If the Shard is open this won't find any children, so an empty response doesn't
mean the Shard will **never** have children.
"""
# Child count is fixed the first time any ... | [
"If",
"the",
"Shard",
"doesn",
"t",
"have",
"any",
"children",
"tries",
"to",
"find",
"some",
"from",
"DescribeStream",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/shard.py#L206-L250 | [
"def",
"load_children",
"(",
"self",
")",
":",
"# Child count is fixed the first time any of the following happen:",
"# 0 :: stream closed or throughput decreased",
"# 1 :: shard was open for ~4 hours",
"# 2 :: throughput increased",
"if",
"self",
".",
"children",
":",
"return",
"sel... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Shard.get_records | Get the next set of records in this shard. An empty list doesn't guarantee the shard is exhausted.
:returns: A list of reformatted records. May be empty. | bloop/stream/shard.py | def get_records(self):
"""Get the next set of records in this shard. An empty list doesn't guarantee the shard is exhausted.
:returns: A list of reformatted records. May be empty.
"""
# Won't be able to find new records.
if self.exhausted:
return []
# Alre... | def get_records(self):
"""Get the next set of records in this shard. An empty list doesn't guarantee the shard is exhausted.
:returns: A list of reformatted records. May be empty.
"""
# Won't be able to find new records.
if self.exhausted:
return []
# Alre... | [
"Get",
"the",
"next",
"set",
"of",
"records",
"in",
"this",
"shard",
".",
"An",
"empty",
"list",
"doesn",
"t",
"guarantee",
"the",
"shard",
"is",
"exhausted",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/shard.py#L252-L271 | [
"def",
"get_records",
"(",
"self",
")",
":",
"# Won't be able to find new records.",
"if",
"self",
".",
"exhausted",
":",
"return",
"[",
"]",
"# Already caught up, just the one call please.",
"if",
"self",
".",
"empty_responses",
">=",
"CALLS_TO_REACH_HEAD",
":",
"retur... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Engine.bind | Create backing tables for a model and its non-abstract subclasses.
:param model: Base model to bind. Can be abstract.
:param skip_table_setup: Don't create or verify the table in DynamoDB. Default is False.
:raises bloop.exceptions.InvalidModel: if ``model`` is not a subclass of :class:`~bloo... | bloop/engine.py | def bind(self, model, *, skip_table_setup=False):
"""Create backing tables for a model and its non-abstract subclasses.
:param model: Base model to bind. Can be abstract.
:param skip_table_setup: Don't create or verify the table in DynamoDB. Default is False.
:raises bloop.exceptions.... | def bind(self, model, *, skip_table_setup=False):
"""Create backing tables for a model and its non-abstract subclasses.
:param model: Base model to bind. Can be abstract.
:param skip_table_setup: Don't create or verify the table in DynamoDB. Default is False.
:raises bloop.exceptions.... | [
"Create",
"backing",
"tables",
"for",
"a",
"model",
"and",
"its",
"non",
"-",
"abstract",
"subclasses",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/engine.py#L115-L165 | [
"def",
"bind",
"(",
"self",
",",
"model",
",",
"*",
",",
"skip_table_setup",
"=",
"False",
")",
":",
"# Make sure we're looking at models",
"validate_is_model",
"(",
"model",
")",
"concrete",
"=",
"set",
"(",
"filter",
"(",
"lambda",
"m",
":",
"not",
"m",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Engine.delete | Delete one or more objects.
:param objs: objects to delete.
:param condition: only perform each delete if this condition holds.
:param bool atomic: only perform each delete if the local and DynamoDB versions of the object match.
:raises bloop.exceptions.ConstraintViolation: if the condi... | bloop/engine.py | def delete(self, *objs, condition=None, atomic=False):
"""Delete one or more objects.
:param objs: objects to delete.
:param condition: only perform each delete if this condition holds.
:param bool atomic: only perform each delete if the local and DynamoDB versions of the object match.
... | def delete(self, *objs, condition=None, atomic=False):
"""Delete one or more objects.
:param objs: objects to delete.
:param condition: only perform each delete if this condition holds.
:param bool atomic: only perform each delete if the local and DynamoDB versions of the object match.
... | [
"Delete",
"one",
"or",
"more",
"objects",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/engine.py#L167-L184 | [
"def",
"delete",
"(",
"self",
",",
"*",
"objs",
",",
"condition",
"=",
"None",
",",
"atomic",
"=",
"False",
")",
":",
"objs",
"=",
"set",
"(",
"objs",
")",
"validate_not_abstract",
"(",
"*",
"objs",
")",
"for",
"obj",
"in",
"objs",
":",
"self",
"."... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Engine.load | Populate objects from DynamoDB.
:param objs: objects to delete.
:param bool consistent: Use `strongly consistent reads`__ if True. Default is False.
:raises bloop.exceptions.MissingKey: if any object doesn't provide a value for a key column.
:raises bloop.exceptions.MissingObjects: if ... | bloop/engine.py | def load(self, *objs, consistent=False):
"""Populate objects from DynamoDB.
:param objs: objects to delete.
:param bool consistent: Use `strongly consistent reads`__ if True. Default is False.
:raises bloop.exceptions.MissingKey: if any object doesn't provide a value for a key column.
... | def load(self, *objs, consistent=False):
"""Populate objects from DynamoDB.
:param objs: objects to delete.
:param bool consistent: Use `strongly consistent reads`__ if True. Default is False.
:raises bloop.exceptions.MissingKey: if any object doesn't provide a value for a key column.
... | [
"Populate",
"objects",
"from",
"DynamoDB",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/engine.py#L186-L239 | [
"def",
"load",
"(",
"self",
",",
"*",
"objs",
",",
"consistent",
"=",
"False",
")",
":",
"get_table_name",
"=",
"self",
".",
"_compute_table_name",
"objs",
"=",
"set",
"(",
"objs",
")",
"validate_not_abstract",
"(",
"*",
"objs",
")",
"table_index",
",",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Engine.query | Create a reusable :class:`~bloop.search.QueryIterator`.
:param model_or_index: A model or index to query. For example, ``User`` or ``User.by_email``.
:param key:
Key condition. This must include an equality against the hash key, and optionally one
of a restricted set of condit... | bloop/engine.py | def query(self, model_or_index, key, filter=None, projection="all", consistent=False, forward=True):
"""Create a reusable :class:`~bloop.search.QueryIterator`.
:param model_or_index: A model or index to query. For example, ``User`` or ``User.by_email``.
:param key:
Key condition. ... | def query(self, model_or_index, key, filter=None, projection="all", consistent=False, forward=True):
"""Create a reusable :class:`~bloop.search.QueryIterator`.
:param model_or_index: A model or index to query. For example, ``User`` or ``User.by_email``.
:param key:
Key condition. ... | [
"Create",
"a",
"reusable",
":",
"class",
":",
"~bloop",
".",
"search",
".",
"QueryIterator",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/engine.py#L241-L268 | [
"def",
"query",
"(",
"self",
",",
"model_or_index",
",",
"key",
",",
"filter",
"=",
"None",
",",
"projection",
"=",
"\"all\"",
",",
"consistent",
"=",
"False",
",",
"forward",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"model_or_index",
",",
"Index"... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Engine.save | Save one or more objects.
:param objs: objects to save.
:param condition: only perform each save if this condition holds.
:param bool atomic: only perform each save if the local and DynamoDB versions of the object match.
:raises bloop.exceptions.ConstraintViolation: if the condition (or... | bloop/engine.py | def save(self, *objs, condition=None, atomic=False):
"""Save one or more objects.
:param objs: objects to save.
:param condition: only perform each save if this condition holds.
:param bool atomic: only perform each save if the local and DynamoDB versions of the object match.
:r... | def save(self, *objs, condition=None, atomic=False):
"""Save one or more objects.
:param objs: objects to save.
:param condition: only perform each save if this condition holds.
:param bool atomic: only perform each save if the local and DynamoDB versions of the object match.
:r... | [
"Save",
"one",
"or",
"more",
"objects",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/engine.py#L270-L287 | [
"def",
"save",
"(",
"self",
",",
"*",
"objs",
",",
"condition",
"=",
"None",
",",
"atomic",
"=",
"False",
")",
":",
"objs",
"=",
"set",
"(",
"objs",
")",
"validate_not_abstract",
"(",
"*",
"objs",
")",
"for",
"obj",
"in",
"objs",
":",
"self",
".",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Engine.scan | Create a reusable :class:`~bloop.search.ScanIterator`.
:param model_or_index: A model or index to scan. For example, ``User`` or ``User.by_email``.
:param filter: Filter condition. Only matching objects will be included in the results.
:param projection:
"all", "count", a list of ... | bloop/engine.py | def scan(self, model_or_index, filter=None, projection="all", consistent=False, parallel=None):
"""Create a reusable :class:`~bloop.search.ScanIterator`.
:param model_or_index: A model or index to scan. For example, ``User`` or ``User.by_email``.
:param filter: Filter condition. Only matching... | def scan(self, model_or_index, filter=None, projection="all", consistent=False, parallel=None):
"""Create a reusable :class:`~bloop.search.ScanIterator`.
:param model_or_index: A model or index to scan. For example, ``User`` or ``User.by_email``.
:param filter: Filter condition. Only matching... | [
"Create",
"a",
"reusable",
":",
"class",
":",
"~bloop",
".",
"search",
".",
"ScanIterator",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/engine.py#L289-L314 | [
"def",
"scan",
"(",
"self",
",",
"model_or_index",
",",
"filter",
"=",
"None",
",",
"projection",
"=",
"\"all\"",
",",
"consistent",
"=",
"False",
",",
"parallel",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"model_or_index",
",",
"Index",
")",
":",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Engine.stream | Create a :class:`~bloop.stream.Stream` that provides approximate chronological ordering.
.. code-block:: pycon
# Create a user so we have a record
>>> engine = Engine()
>>> user = User(id=3, email="user@domain.com")
>>> engine.save(user)
>>> user.ema... | bloop/engine.py | def stream(self, model, position):
"""Create a :class:`~bloop.stream.Stream` that provides approximate chronological ordering.
.. code-block:: pycon
# Create a user so we have a record
>>> engine = Engine()
>>> user = User(id=3, email="user@domain.com")
... | def stream(self, model, position):
"""Create a :class:`~bloop.stream.Stream` that provides approximate chronological ordering.
.. code-block:: pycon
# Create a user so we have a record
>>> engine = Engine()
>>> user = User(id=3, email="user@domain.com")
... | [
"Create",
"a",
":",
"class",
":",
"~bloop",
".",
"stream",
".",
"Stream",
"that",
"provides",
"approximate",
"chronological",
"ordering",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/engine.py#L316-L355 | [
"def",
"stream",
"(",
"self",
",",
"model",
",",
"position",
")",
":",
"validate_not_abstract",
"(",
"model",
")",
"if",
"not",
"model",
".",
"Meta",
".",
"stream",
"or",
"not",
"model",
".",
"Meta",
".",
"stream",
".",
"get",
"(",
"\"arn\"",
")",
":... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Engine.transaction | Create a new :class:`~bloop.transactions.ReadTransaction` or :class:`~bloop.transactions.WriteTransaction`.
As a context manager, calling commit when the block exits:
.. code-block:: pycon
>>> engine = Engine()
>>> user = User(id=3, email="user@domain.com")
>>> twe... | bloop/engine.py | def transaction(self, mode="w"):
"""
Create a new :class:`~bloop.transactions.ReadTransaction` or :class:`~bloop.transactions.WriteTransaction`.
As a context manager, calling commit when the block exits:
.. code-block:: pycon
>>> engine = Engine()
>>> user = Us... | def transaction(self, mode="w"):
"""
Create a new :class:`~bloop.transactions.ReadTransaction` or :class:`~bloop.transactions.WriteTransaction`.
As a context manager, calling commit when the block exits:
.. code-block:: pycon
>>> engine = Engine()
>>> user = Us... | [
"Create",
"a",
"new",
":",
"class",
":",
"~bloop",
".",
"transactions",
".",
"ReadTransaction",
"or",
":",
"class",
":",
"~bloop",
".",
"transactions",
".",
"WriteTransaction",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/engine.py#L357-L394 | [
"def",
"transaction",
"(",
"self",
",",
"mode",
"=",
"\"w\"",
")",
":",
"if",
"mode",
"==",
"\"r\"",
":",
"cls",
"=",
"ReadTransaction",
"elif",
"mode",
"==",
"\"w\"",
":",
"cls",
"=",
"WriteTransaction",
"else",
":",
"raise",
"ValueError",
"(",
"f\"unkn... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Type._dump | Entry point for serializing values. Most custom types should use :func:`~bloop.types.Type.dynamo_dump`.
This wraps the return value of :func:`~bloop.types.Type.dynamo_dump` in DynamoDB's wire format.
For example, serializing a string enum to an int:
.. code-block:: python
value =... | bloop/types.py | def _dump(self, value, **kwargs):
"""Entry point for serializing values. Most custom types should use :func:`~bloop.types.Type.dynamo_dump`.
This wraps the return value of :func:`~bloop.types.Type.dynamo_dump` in DynamoDB's wire format.
For example, serializing a string enum to an int:
... | def _dump(self, value, **kwargs):
"""Entry point for serializing values. Most custom types should use :func:`~bloop.types.Type.dynamo_dump`.
This wraps the return value of :func:`~bloop.types.Type.dynamo_dump` in DynamoDB's wire format.
For example, serializing a string enum to an int:
... | [
"Entry",
"point",
"for",
"serializing",
"values",
".",
"Most",
"custom",
"types",
"should",
"use",
":",
"func",
":",
"~bloop",
".",
"types",
".",
"Type",
".",
"dynamo_dump",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/types.py#L101-L120 | [
"def",
"_dump",
"(",
"self",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"value",
"=",
"self",
".",
"dynamo_dump",
"(",
"value",
",",
"*",
"*",
"kwargs",
")",
"if",
"value",
"is",
"None",
":",
"return",
"value",
"return",
"{",
"self",
".",
"... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Type._load | Entry point for deserializing values. Most custom types should use :func:`~bloop.types.Type.dynamo_load`.
This unpacks DynamoDB's wire format and calls :func:`~bloop.types.Type.dynamo_load` on the inner value.
For example, deserializing an int to a string enum:
.. code-block:: python
... | bloop/types.py | def _load(self, value, **kwargs):
"""Entry point for deserializing values. Most custom types should use :func:`~bloop.types.Type.dynamo_load`.
This unpacks DynamoDB's wire format and calls :func:`~bloop.types.Type.dynamo_load` on the inner value.
For example, deserializing an int to a string e... | def _load(self, value, **kwargs):
"""Entry point for deserializing values. Most custom types should use :func:`~bloop.types.Type.dynamo_load`.
This unpacks DynamoDB's wire format and calls :func:`~bloop.types.Type.dynamo_load` on the inner value.
For example, deserializing an int to a string e... | [
"Entry",
"point",
"for",
"deserializing",
"values",
".",
"Most",
"custom",
"types",
"should",
"use",
":",
"func",
":",
"~bloop",
".",
"types",
".",
"Type",
".",
"dynamo_load",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/types.py#L122-L139 | [
"def",
"_load",
"(",
"self",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"value",
"=",
"next",
"(",
"iter",
"(",
"value",
".",
"values",
"(",
")",
")",
")",
"return",
"self",
".",
"dynamo_load",
"(",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | DynamicType.backing_type_for | Returns the DynamoDB backing type for a given python value's type
::
4 -> 'N'
['x', 3] -> 'L'
{2, 4} -> 'SS' | bloop/types.py | def backing_type_for(value):
"""Returns the DynamoDB backing type for a given python value's type
::
4 -> 'N'
['x', 3] -> 'L'
{2, 4} -> 'SS'
"""
if isinstance(value, str):
vtype = "S"
elif isinstance(value, bytes):
vty... | def backing_type_for(value):
"""Returns the DynamoDB backing type for a given python value's type
::
4 -> 'N'
['x', 3] -> 'L'
{2, 4} -> 'SS'
"""
if isinstance(value, str):
vtype = "S"
elif isinstance(value, bytes):
vty... | [
"Returns",
"the",
"DynamoDB",
"backing",
"type",
"for",
"a",
"given",
"python",
"value",
"s",
"type"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/types.py#L637-L674 | [
"def",
"backing_type_for",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"vtype",
"=",
"\"S\"",
"elif",
"isinstance",
"(",
"value",
",",
"bytes",
")",
":",
"vtype",
"=",
"\"B\"",
"# NOTE: numbers.Number check must come **AFTER... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | stream_replicate | Monitor changes in approximately real-time and replicate them | examples/replication.py | def stream_replicate():
"""Monitor changes in approximately real-time and replicate them"""
stream = primary.stream(SomeDataBlob, "trim_horizon")
next_heartbeat = pendulum.now()
while True:
now = pendulum.now()
if now >= next_heartbeat:
stream.heartbeat()
next_hea... | def stream_replicate():
"""Monitor changes in approximately real-time and replicate them"""
stream = primary.stream(SomeDataBlob, "trim_horizon")
next_heartbeat = pendulum.now()
while True:
now = pendulum.now()
if now >= next_heartbeat:
stream.heartbeat()
next_hea... | [
"Monitor",
"changes",
"in",
"approximately",
"real",
"-",
"time",
"and",
"replicate",
"them"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/examples/replication.py#L42-L58 | [
"def",
"stream_replicate",
"(",
")",
":",
"stream",
"=",
"primary",
".",
"stream",
"(",
"SomeDataBlob",
",",
"\"trim_horizon\"",
")",
"next_heartbeat",
"=",
"pendulum",
".",
"now",
"(",
")",
"while",
"True",
":",
"now",
"=",
"pendulum",
".",
"now",
"(",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | _move_stream_endpoint | Move to the "trim_horizon" or "latest" of the entire stream. | bloop/stream/coordinator.py | def _move_stream_endpoint(coordinator, position):
"""Move to the "trim_horizon" or "latest" of the entire stream."""
# 0) Everything will be rebuilt from DescribeStream.
stream_arn = coordinator.stream_arn
coordinator.roots.clear()
coordinator.active.clear()
coordinator.buffer.clear()
# 1) ... | def _move_stream_endpoint(coordinator, position):
"""Move to the "trim_horizon" or "latest" of the entire stream."""
# 0) Everything will be rebuilt from DescribeStream.
stream_arn = coordinator.stream_arn
coordinator.roots.clear()
coordinator.active.clear()
coordinator.buffer.clear()
# 1) ... | [
"Move",
"to",
"the",
"trim_horizon",
"or",
"latest",
"of",
"the",
"entire",
"stream",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/coordinator.py#L214-L240 | [
"def",
"_move_stream_endpoint",
"(",
"coordinator",
",",
"position",
")",
":",
"# 0) Everything will be rebuilt from DescribeStream.",
"stream_arn",
"=",
"coordinator",
".",
"stream_arn",
"coordinator",
".",
"roots",
".",
"clear",
"(",
")",
"coordinator",
".",
"active",... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | _move_stream_time | Scan through the *entire* Stream for the first record after ``time``.
This is an extremely expensive, naive algorithm that starts at trim_horizon and simply
dumps records into the void until the first hit. General improvements in performance are
tough; we can use the fact that Shards have a max life of 24... | bloop/stream/coordinator.py | def _move_stream_time(coordinator, time):
"""Scan through the *entire* Stream for the first record after ``time``.
This is an extremely expensive, naive algorithm that starts at trim_horizon and simply
dumps records into the void until the first hit. General improvements in performance are
tough; we c... | def _move_stream_time(coordinator, time):
"""Scan through the *entire* Stream for the first record after ``time``.
This is an extremely expensive, naive algorithm that starts at trim_horizon and simply
dumps records into the void until the first hit. General improvements in performance are
tough; we c... | [
"Scan",
"through",
"the",
"*",
"entire",
"*",
"Stream",
"for",
"the",
"first",
"record",
"after",
"time",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/coordinator.py#L243-L271 | [
"def",
"_move_stream_time",
"(",
"coordinator",
",",
"time",
")",
":",
"if",
"time",
">",
"datetime",
".",
"datetime",
".",
"now",
"(",
"datetime",
".",
"timezone",
".",
"utc",
")",
":",
"_move_stream_endpoint",
"(",
"coordinator",
",",
"\"latest\"",
")",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | _move_stream_token | Move to the Stream position described by the token.
The following rules are applied when interpolation is required:
- If a shard does not exist (past the trim_horizon) it is ignored. If that
shard had children, its children are also checked against the existing shards.
- If none of the shards in the... | bloop/stream/coordinator.py | def _move_stream_token(coordinator, token):
"""Move to the Stream position described by the token.
The following rules are applied when interpolation is required:
- If a shard does not exist (past the trim_horizon) it is ignored. If that
shard had children, its children are also checked against the ... | def _move_stream_token(coordinator, token):
"""Move to the Stream position described by the token.
The following rules are applied when interpolation is required:
- If a shard does not exist (past the trim_horizon) it is ignored. If that
shard had children, its children are also checked against the ... | [
"Move",
"to",
"the",
"Stream",
"position",
"described",
"by",
"the",
"token",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/coordinator.py#L274-L328 | [
"def",
"_move_stream_token",
"(",
"coordinator",
",",
"token",
")",
":",
"stream_arn",
"=",
"coordinator",
".",
"stream_arn",
"=",
"token",
"[",
"\"stream_arn\"",
"]",
"# 0) Everything will be rebuilt from the DescribeStream masked by the token.",
"coordinator",
".",
"roots... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Coordinator.advance_shards | Poll active shards for records and insert them into the buffer. Rotate exhausted shards.
Returns immediately if the buffer isn't empty. | bloop/stream/coordinator.py | def advance_shards(self):
"""Poll active shards for records and insert them into the buffer. Rotate exhausted shards.
Returns immediately if the buffer isn't empty.
"""
# Don't poll shards when there are pending records.
if self.buffer:
return
# 0) Collect ... | def advance_shards(self):
"""Poll active shards for records and insert them into the buffer. Rotate exhausted shards.
Returns immediately if the buffer isn't empty.
"""
# Don't poll shards when there are pending records.
if self.buffer:
return
# 0) Collect ... | [
"Poll",
"active",
"shards",
"for",
"records",
"and",
"insert",
"them",
"into",
"the",
"buffer",
".",
"Rotate",
"exhausted",
"shards",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/coordinator.py#L77-L94 | [
"def",
"advance_shards",
"(",
"self",
")",
":",
"# Don't poll shards when there are pending records.",
"if",
"self",
".",
"buffer",
":",
"return",
"# 0) Collect new records from all active shards.",
"record_shard_pairs",
"=",
"[",
"]",
"for",
"shard",
"in",
"self",
".",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Coordinator.heartbeat | Keep active shards with "trim_horizon", "latest" iterators alive by advancing their iterators. | bloop/stream/coordinator.py | def heartbeat(self):
"""Keep active shards with "trim_horizon", "latest" iterators alive by advancing their iterators."""
for shard in self.active:
if shard.sequence_number is None:
records = next(shard)
# Success! This shard now has an ``at_sequence`` iterat... | def heartbeat(self):
"""Keep active shards with "trim_horizon", "latest" iterators alive by advancing their iterators."""
for shard in self.active:
if shard.sequence_number is None:
records = next(shard)
# Success! This shard now has an ``at_sequence`` iterat... | [
"Keep",
"active",
"shards",
"with",
"trim_horizon",
"latest",
"iterators",
"alive",
"by",
"advancing",
"their",
"iterators",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/coordinator.py#L96-L104 | [
"def",
"heartbeat",
"(",
"self",
")",
":",
"for",
"shard",
"in",
"self",
".",
"active",
":",
"if",
"shard",
".",
"sequence_number",
"is",
"None",
":",
"records",
"=",
"next",
"(",
"shard",
")",
"# Success! This shard now has an ``at_sequence`` iterator",
"if",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Coordinator.token | JSON-serializable representation of the current Stream state.
Use :func:`Engine.stream(YourModel, token) <bloop.engine.Engine.stream>` to create an identical stream,
or :func:`stream.move_to(token) <bloop.stream.Stream.move_to>` to move an existing stream to this position.
:returns: Stream sta... | bloop/stream/coordinator.py | def token(self):
"""JSON-serializable representation of the current Stream state.
Use :func:`Engine.stream(YourModel, token) <bloop.engine.Engine.stream>` to create an identical stream,
or :func:`stream.move_to(token) <bloop.stream.Stream.move_to>` to move an existing stream to this position.
... | def token(self):
"""JSON-serializable representation of the current Stream state.
Use :func:`Engine.stream(YourModel, token) <bloop.engine.Engine.stream>` to create an identical stream,
or :func:`stream.move_to(token) <bloop.stream.Stream.move_to>` to move an existing stream to this position.
... | [
"JSON",
"-",
"serializable",
"representation",
"of",
"the",
"current",
"Stream",
"state",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/coordinator.py#L131-L160 | [
"def",
"token",
"(",
"self",
")",
":",
"# 0) Trace roots and active shards",
"active_ids",
"=",
"[",
"]",
"shard_tokens",
"=",
"[",
"]",
"for",
"root",
"in",
"self",
".",
"roots",
":",
"for",
"shard",
"in",
"root",
".",
"walk_tree",
"(",
")",
":",
"shard... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Coordinator.remove_shard | Remove a Shard from the Coordinator. Drops all buffered records from the Shard.
If the Shard is active or a root, it is removed and any children promoted to those roles.
:param shard: The shard to remove
:type shard: :class:`~bloop.stream.shard.Shard`
:param bool drop_buffered_record... | bloop/stream/coordinator.py | def remove_shard(self, shard, drop_buffered_records=False):
"""Remove a Shard from the Coordinator. Drops all buffered records from the Shard.
If the Shard is active or a root, it is removed and any children promoted to those roles.
:param shard: The shard to remove
:type shard: :cla... | def remove_shard(self, shard, drop_buffered_records=False):
"""Remove a Shard from the Coordinator. Drops all buffered records from the Shard.
If the Shard is active or a root, it is removed and any children promoted to those roles.
:param shard: The shard to remove
:type shard: :cla... | [
"Remove",
"a",
"Shard",
"from",
"the",
"Coordinator",
".",
"Drops",
"all",
"buffered",
"records",
"from",
"the",
"Shard",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/coordinator.py#L162-L195 | [
"def",
"remove_shard",
"(",
"self",
",",
"shard",
",",
"drop_buffered_records",
"=",
"False",
")",
":",
"try",
":",
"self",
".",
"roots",
".",
"remove",
"(",
"shard",
")",
"except",
"ValueError",
":",
"# Wasn't a root Shard",
"pass",
"else",
":",
"self",
"... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | Coordinator.move_to | Set the Coordinator to a specific endpoint or time, or load state from a token.
:param position: "trim_horizon", "latest", :class:`~datetime.datetime`, or a
:attr:`Coordinator.token <bloop.stream.coordinator.Coordinator.token>` | bloop/stream/coordinator.py | def move_to(self, position):
"""Set the Coordinator to a specific endpoint or time, or load state from a token.
:param position: "trim_horizon", "latest", :class:`~datetime.datetime`, or a
:attr:`Coordinator.token <bloop.stream.coordinator.Coordinator.token>`
"""
if isinstan... | def move_to(self, position):
"""Set the Coordinator to a specific endpoint or time, or load state from a token.
:param position: "trim_horizon", "latest", :class:`~datetime.datetime`, or a
:attr:`Coordinator.token <bloop.stream.coordinator.Coordinator.token>`
"""
if isinstan... | [
"Set",
"the",
"Coordinator",
"to",
"a",
"specific",
"endpoint",
"or",
"time",
"or",
"load",
"state",
"from",
"a",
"token",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/coordinator.py#L197-L211 | [
"def",
"move_to",
"(",
"self",
",",
"position",
")",
":",
"if",
"isinstance",
"(",
"position",
",",
"collections",
".",
"abc",
".",
"Mapping",
")",
":",
"move",
"=",
"_move_stream_token",
"elif",
"hasattr",
"(",
"position",
",",
"\"timestamp\"",
")",
"and"... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | heap_item | Create a tuple of (ordering, (record, shard)) for use in a RecordBuffer. | bloop/stream/buffer.py | def heap_item(clock, record, shard):
"""Create a tuple of (ordering, (record, shard)) for use in a RecordBuffer."""
# Primary ordering is by event creation time.
# However, creation time is *approximate* and has whole-second resolution.
# This means two events in the same shard within one second can't b... | def heap_item(clock, record, shard):
"""Create a tuple of (ordering, (record, shard)) for use in a RecordBuffer."""
# Primary ordering is by event creation time.
# However, creation time is *approximate* and has whole-second resolution.
# This means two events in the same shard within one second can't b... | [
"Create",
"a",
"tuple",
"of",
"(",
"ordering",
"(",
"record",
"shard",
"))",
"for",
"use",
"in",
"a",
"RecordBuffer",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/buffer.py#L4-L18 | [
"def",
"heap_item",
"(",
"clock",
",",
"record",
",",
"shard",
")",
":",
"# Primary ordering is by event creation time.",
"# However, creation time is *approximate* and has whole-second resolution.",
"# This means two events in the same shard within one second can't be ordered.",
"ordering... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | RecordBuffer.push | Push a new record into the buffer
:param dict record: new record
:param shard: Shard the record came from
:type shard: :class:`~bloop.stream.shard.Shard` | bloop/stream/buffer.py | def push(self, record, shard):
"""Push a new record into the buffer
:param dict record: new record
:param shard: Shard the record came from
:type shard: :class:`~bloop.stream.shard.Shard`
"""
heapq.heappush(self.heap, heap_item(self.clock, record, shard)) | def push(self, record, shard):
"""Push a new record into the buffer
:param dict record: new record
:param shard: Shard the record came from
:type shard: :class:`~bloop.stream.shard.Shard`
"""
heapq.heappush(self.heap, heap_item(self.clock, record, shard)) | [
"Push",
"a",
"new",
"record",
"into",
"the",
"buffer"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/buffer.py#L39-L46 | [
"def",
"push",
"(",
"self",
",",
"record",
",",
"shard",
")",
":",
"heapq",
".",
"heappush",
"(",
"self",
".",
"heap",
",",
"heap_item",
"(",
"self",
".",
"clock",
",",
"record",
",",
"shard",
")",
")"
] | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | RecordBuffer.push_all | Push multiple (record, shard) pairs at once, with only one :meth:`heapq.heapify` call to maintain order.
:param record_shard_pairs: list of ``(record, shard)`` tuples
(see :func:`~bloop.stream.buffer.RecordBuffer.push`). | bloop/stream/buffer.py | def push_all(self, record_shard_pairs):
"""Push multiple (record, shard) pairs at once, with only one :meth:`heapq.heapify` call to maintain order.
:param record_shard_pairs: list of ``(record, shard)`` tuples
(see :func:`~bloop.stream.buffer.RecordBuffer.push`).
"""
# Faste... | def push_all(self, record_shard_pairs):
"""Push multiple (record, shard) pairs at once, with only one :meth:`heapq.heapify` call to maintain order.
:param record_shard_pairs: list of ``(record, shard)`` tuples
(see :func:`~bloop.stream.buffer.RecordBuffer.push`).
"""
# Faste... | [
"Push",
"multiple",
"(",
"record",
"shard",
")",
"pairs",
"at",
"once",
"with",
"only",
"one",
":",
"meth",
":",
"heapq",
".",
"heapify",
"call",
"to",
"maintain",
"order",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/stream/buffer.py#L48-L58 | [
"def",
"push_all",
"(",
"self",
",",
"record_shard_pairs",
")",
":",
"# Faster than inserting one at a time; the heap is sorted once after all inserts.",
"for",
"record",
",",
"shard",
"in",
"record_shard_pairs",
":",
"item",
"=",
"heap_item",
"(",
"self",
".",
"clock",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | loaded_columns | Yields each (name, value) tuple for all columns in an object that aren't missing | bloop/models.py | def loaded_columns(obj: BaseModel):
"""Yields each (name, value) tuple for all columns in an object that aren't missing"""
for column in sorted(obj.Meta.columns, key=lambda c: c.name):
value = getattr(obj, column.name, missing)
if value is not missing:
yield column.name, value | def loaded_columns(obj: BaseModel):
"""Yields each (name, value) tuple for all columns in an object that aren't missing"""
for column in sorted(obj.Meta.columns, key=lambda c: c.name):
value = getattr(obj, column.name, missing)
if value is not missing:
yield column.name, value | [
"Yields",
"each",
"(",
"name",
"value",
")",
"tuple",
"for",
"all",
"columns",
"in",
"an",
"object",
"that",
"aren",
"t",
"missing"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L583-L588 | [
"def",
"loaded_columns",
"(",
"obj",
":",
"BaseModel",
")",
":",
"for",
"column",
"in",
"sorted",
"(",
"obj",
".",
"Meta",
".",
"columns",
",",
"key",
"=",
"lambda",
"c",
":",
"c",
".",
"name",
")",
":",
"value",
"=",
"getattr",
"(",
"obj",
",",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | unpack_from_dynamodb | Push values by dynamo_name into an object | bloop/models.py | def unpack_from_dynamodb(*, attrs, expected, model=None, obj=None, engine=None, context=None, **kwargs):
"""Push values by dynamo_name into an object"""
context = context or {"engine": engine}
engine = engine or context.get("engine", None)
if not engine:
raise ValueError("You must provide engine... | def unpack_from_dynamodb(*, attrs, expected, model=None, obj=None, engine=None, context=None, **kwargs):
"""Push values by dynamo_name into an object"""
context = context or {"engine": engine}
engine = engine or context.get("engine", None)
if not engine:
raise ValueError("You must provide engine... | [
"Push",
"values",
"by",
"dynamo_name",
"into",
"an",
"object"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L591-L608 | [
"def",
"unpack_from_dynamodb",
"(",
"*",
",",
"attrs",
",",
"expected",
",",
"model",
"=",
"None",
",",
"obj",
"=",
"None",
",",
"engine",
"=",
"None",
",",
"context",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"context",
"=",
"context",
"or",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | setdefault | Set an object's field to default if it doesn't have a value | bloop/models.py | def setdefault(obj, field, default):
"""Set an object's field to default if it doesn't have a value"""
setattr(obj, field, getattr(obj, field, default)) | def setdefault(obj, field, default):
"""Set an object's field to default if it doesn't have a value"""
setattr(obj, field, getattr(obj, field, default)) | [
"Set",
"an",
"object",
"s",
"field",
"to",
"default",
"if",
"it",
"doesn",
"t",
"have",
"a",
"value"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L751-L753 | [
"def",
"setdefault",
"(",
"obj",
",",
"field",
",",
"default",
")",
":",
"setattr",
"(",
"obj",
",",
"field",
",",
"getattr",
"(",
"obj",
",",
"field",
",",
"default",
")",
")"
] | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | bind_column | Bind a column to the model with the given name.
This method is primarily used during BaseModel.__init_subclass__, although it can be used to easily
attach a new column to an existing model:
.. code-block:: python
import bloop.models
class User(BaseModel):
id = Column(String, ... | bloop/models.py | def bind_column(model, name, column, force=False, recursive=False, copy=False) -> Column:
"""Bind a column to the model with the given name.
This method is primarily used during BaseModel.__init_subclass__, although it can be used to easily
attach a new column to an existing model:
.. code-block:: pyt... | def bind_column(model, name, column, force=False, recursive=False, copy=False) -> Column:
"""Bind a column to the model with the given name.
This method is primarily used during BaseModel.__init_subclass__, although it can be used to easily
attach a new column to an existing model:
.. code-block:: pyt... | [
"Bind",
"a",
"column",
"to",
"the",
"model",
"with",
"the",
"given",
"name",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L820-L940 | [
"def",
"bind_column",
"(",
"model",
",",
"name",
",",
"column",
",",
"force",
"=",
"False",
",",
"recursive",
"=",
"False",
",",
"copy",
"=",
"False",
")",
"->",
"Column",
":",
"if",
"not",
"subclassof",
"(",
"model",
",",
"BaseModel",
")",
":",
"rai... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | bind_index | Bind an index to the model with the given name.
This method is primarily used during BaseModel.__init_subclass__, although it can be used to easily
attach a new index to an existing model:
.. code-block:: python
import bloop.models
class User(BaseModel):
... | bloop/models.py | def bind_index(model, name, index, force=False, recursive=True, copy=False) -> Index:
"""Bind an index to the model with the given name.
This method is primarily used during BaseModel.__init_subclass__, although it can be used to easily
attach a new index to an existing model:
.. code-bloc... | def bind_index(model, name, index, force=False, recursive=True, copy=False) -> Index:
"""Bind an index to the model with the given name.
This method is primarily used during BaseModel.__init_subclass__, although it can be used to easily
attach a new index to an existing model:
.. code-bloc... | [
"Bind",
"an",
"index",
"to",
"the",
"model",
"with",
"the",
"given",
"name",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L943-L1047 | [
"def",
"bind_index",
"(",
"model",
",",
"name",
",",
"index",
",",
"force",
"=",
"False",
",",
"recursive",
"=",
"True",
",",
"copy",
"=",
"False",
")",
"->",
"Index",
":",
"if",
"not",
"subclassof",
"(",
"model",
",",
"BaseModel",
")",
":",
"raise",... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | refresh_index | Recalculate the projection, hash_key, and range_key for the given index.
:param meta: model.Meta to find columns by name
:param index: The index to refresh | bloop/models.py | def refresh_index(meta, index) -> None:
"""Recalculate the projection, hash_key, and range_key for the given index.
:param meta: model.Meta to find columns by name
:param index: The index to refresh
"""
# All projections include model + index keys
projection_keys = set.union(meta.keys, index.ke... | def refresh_index(meta, index) -> None:
"""Recalculate the projection, hash_key, and range_key for the given index.
:param meta: model.Meta to find columns by name
:param index: The index to refresh
"""
# All projections include model + index keys
projection_keys = set.union(meta.keys, index.ke... | [
"Recalculate",
"the",
"projection",
"hash_key",
"and",
"range_key",
"for",
"the",
"given",
"index",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L1050-L1076 | [
"def",
"refresh_index",
"(",
"meta",
",",
"index",
")",
"->",
"None",
":",
"# All projections include model + index keys",
"projection_keys",
"=",
"set",
".",
"union",
"(",
"meta",
".",
"keys",
",",
"index",
".",
"keys",
")",
"proj",
"=",
"index",
".",
"proj... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | unbind | Unconditionally remove any columns or indexes bound to the given name or dynamo_name.
.. code-block:: python
import bloop.models
class User(BaseModel):
id = Column(String, hash_key=True)
email = Column(String, dynamo_name="e")
by_email = GlobalSecondaryIndex(p... | bloop/models.py | def unbind(meta, name=None, dynamo_name=None) -> None:
"""Unconditionally remove any columns or indexes bound to the given name or dynamo_name.
.. code-block:: python
import bloop.models
class User(BaseModel):
id = Column(String, hash_key=True)
email = Column(String, ... | def unbind(meta, name=None, dynamo_name=None) -> None:
"""Unconditionally remove any columns or indexes bound to the given name or dynamo_name.
.. code-block:: python
import bloop.models
class User(BaseModel):
id = Column(String, hash_key=True)
email = Column(String, ... | [
"Unconditionally",
"remove",
"any",
"columns",
"or",
"indexes",
"bound",
"to",
"the",
"given",
"name",
"or",
"dynamo_name",
"."
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L1079-L1151 | [
"def",
"unbind",
"(",
"meta",
",",
"name",
"=",
"None",
",",
"dynamo_name",
"=",
"None",
")",
"->",
"None",
":",
"if",
"name",
"is",
"not",
"None",
":",
"columns",
"=",
"{",
"x",
"for",
"x",
"in",
"meta",
".",
"columns",
"if",
"x",
".",
"name",
... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | BaseModel._load | dict (dynamo name) -> obj | bloop/models.py | def _load(cls, attrs, *, context, **kwargs):
""" dict (dynamo name) -> obj """
return unpack_from_dynamodb(
model=cls,
attrs=attrs or {},
expected=cls.Meta.columns,
context=context, **kwargs) | def _load(cls, attrs, *, context, **kwargs):
""" dict (dynamo name) -> obj """
return unpack_from_dynamodb(
model=cls,
attrs=attrs or {},
expected=cls.Meta.columns,
context=context, **kwargs) | [
"dict",
"(",
"dynamo",
"name",
")",
"-",
">",
"obj"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L207-L213 | [
"def",
"_load",
"(",
"cls",
",",
"attrs",
",",
"*",
",",
"context",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"unpack_from_dynamodb",
"(",
"model",
"=",
"cls",
",",
"attrs",
"=",
"attrs",
"or",
"{",
"}",
",",
"expected",
"=",
"cls",
".",
"Meta",... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
train | BaseModel._dump | obj -> dict | bloop/models.py | def _dump(cls, obj, *, context, **kwargs):
""" obj -> dict """
if obj is None:
return None
dump = context["engine"]._dump
filtered = filter(
lambda item: item[1] is not None,
((
column.dynamo_name,
dump(column.typedef, g... | def _dump(cls, obj, *, context, **kwargs):
""" obj -> dict """
if obj is None:
return None
dump = context["engine"]._dump
filtered = filter(
lambda item: item[1] is not None,
((
column.dynamo_name,
dump(column.typedef, g... | [
"obj",
"-",
">",
"dict"
] | numberoverzero/bloop | python | https://github.com/numberoverzero/bloop/blob/4c95f5a0ff0802443a1c258bfaccecd1758363e7/bloop/models.py#L216-L227 | [
"def",
"_dump",
"(",
"cls",
",",
"obj",
",",
"*",
",",
"context",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"obj",
"is",
"None",
":",
"return",
"None",
"dump",
"=",
"context",
"[",
"\"engine\"",
"]",
".",
"_dump",
"filtered",
"=",
"filter",
"(",
"... | 4c95f5a0ff0802443a1c258bfaccecd1758363e7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.