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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test | _Session._add_object | The flag is a simple integer to force the placement
of the object into position in the object array.
Used for overwriting the placeholder objects. | pypdflite/session.py | def _add_object(self, flag=None):
""" The flag is a simple integer to force the placement
of the object into position in the object array.
Used for overwriting the placeholder objects.
"""
self.offset = len(self.buffer)
if flag is None:
objnum = len(self.objects)
obj = _PDFObject(objnum, self.offset)
self.objects.append(obj)
else:
objnum = flag
obj = _PDFObject(objnum, self.offset)
self.objects[flag] = obj
self._out(str(objnum) + ' 0 obj')
return obj | def _add_object(self, flag=None):
""" The flag is a simple integer to force the placement
of the object into position in the object array.
Used for overwriting the placeholder objects.
"""
self.offset = len(self.buffer)
if flag is None:
objnum = len(self.objects)
obj = _PDFObject(objnum, self.offset)
self.objects.append(obj)
else:
objnum = flag
obj = _PDFObject(objnum, self.offset)
self.objects[flag] = obj
self._out(str(objnum) + ' 0 obj')
return obj | [
"The",
"flag",
"is",
"a",
"simple",
"integer",
"to",
"force",
"the",
"placement",
"of",
"the",
"object",
"into",
"position",
"in",
"the",
"object",
"array",
".",
"Used",
"for",
"overwriting",
"the",
"placeholder",
"objects",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/session.py#L64-L80 | [
"def",
"_add_object",
"(",
"self",
",",
"flag",
"=",
"None",
")",
":",
"self",
".",
"offset",
"=",
"len",
"(",
"self",
".",
"buffer",
")",
"if",
"flag",
"is",
"None",
":",
"objnum",
"=",
"len",
"(",
"self",
".",
"objects",
")",
"obj",
"=",
"_PDFObject",
"(",
"objnum",
",",
"self",
".",
"offset",
")",
"self",
".",
"objects",
".",
"append",
"(",
"obj",
")",
"else",
":",
"objnum",
"=",
"flag",
"obj",
"=",
"_PDFObject",
"(",
"objnum",
",",
"self",
".",
"offset",
")",
"self",
".",
"objects",
"[",
"flag",
"]",
"=",
"obj",
"self",
".",
"_out",
"(",
"str",
"(",
"objnum",
")",
"+",
"' 0 obj'",
")",
"return",
"obj"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | _Session._out | Stores the pdf code in a buffer. If it is page related,
provide the page object. | pypdflite/session.py | def _out(self, stream, page=None):
""" Stores the pdf code in a buffer. If it is page related,
provide the page object.
"""
if page is not None:
page.buffer += str(stream) + "\n"
else:
self.buffer += str(stream) + "\n" | def _out(self, stream, page=None):
""" Stores the pdf code in a buffer. If it is page related,
provide the page object.
"""
if page is not None:
page.buffer += str(stream) + "\n"
else:
self.buffer += str(stream) + "\n" | [
"Stores",
"the",
"pdf",
"code",
"in",
"a",
"buffer",
".",
"If",
"it",
"is",
"page",
"related",
"provide",
"the",
"page",
"object",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/session.py#L89-L97 | [
"def",
"_out",
"(",
"self",
",",
"stream",
",",
"page",
"=",
"None",
")",
":",
"if",
"page",
"is",
"not",
"None",
":",
"page",
".",
"buffer",
"+=",
"str",
"(",
"stream",
")",
"+",
"\"\\n\"",
"else",
":",
"self",
".",
"buffer",
"+=",
"str",
"(",
"stream",
")",
"+",
"\"\\n\""
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | _Session._put_stream | Creates a PDF text stream sandwich. | pypdflite/session.py | def _put_stream(self, stream):
""" Creates a PDF text stream sandwich.
"""
self._out('stream')
self._out(stream)
self._out('endstream') | def _put_stream(self, stream):
""" Creates a PDF text stream sandwich.
"""
self._out('stream')
self._out(stream)
self._out('endstream') | [
"Creates",
"a",
"PDF",
"text",
"stream",
"sandwich",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/session.py#L99-L105 | [
"def",
"_put_stream",
"(",
"self",
",",
"stream",
")",
":",
"self",
".",
"_out",
"(",
"'stream'",
")",
"self",
".",
"_out",
"(",
"stream",
")",
"self",
".",
"_out",
"(",
"'endstream'",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | _Session._add_page | Helper function for PDFText, to have the document
add a page, and retry adding a large block of
text that would otherwise have been to long for the
page. | pypdflite/session.py | def _add_page(self, text):
""" Helper function for PDFText, to have the document
add a page, and retry adding a large block of
text that would otherwise have been to long for the
page.
"""
save_cursor = self.parent.document.page.cursor.copy()
save_cursor.x_reset()
save_cursor.y_reset()
self.parent.document.add_page()
self.parent.document.set_cursor(save_cursor)
self.parent.document.add_text(text) | def _add_page(self, text):
""" Helper function for PDFText, to have the document
add a page, and retry adding a large block of
text that would otherwise have been to long for the
page.
"""
save_cursor = self.parent.document.page.cursor.copy()
save_cursor.x_reset()
save_cursor.y_reset()
self.parent.document.add_page()
self.parent.document.set_cursor(save_cursor)
self.parent.document.add_text(text) | [
"Helper",
"function",
"for",
"PDFText",
"to",
"have",
"the",
"document",
"add",
"a",
"page",
"and",
"retry",
"adding",
"a",
"large",
"block",
"of",
"text",
"that",
"would",
"otherwise",
"have",
"been",
"to",
"long",
"for",
"the",
"page",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/session.py#L107-L119 | [
"def",
"_add_page",
"(",
"self",
",",
"text",
")",
":",
"save_cursor",
"=",
"self",
".",
"parent",
".",
"document",
".",
"page",
".",
"cursor",
".",
"copy",
"(",
")",
"save_cursor",
".",
"x_reset",
"(",
")",
"save_cursor",
".",
"y_reset",
"(",
")",
"self",
".",
"parent",
".",
"document",
".",
"add_page",
"(",
")",
"self",
".",
"parent",
".",
"document",
".",
"set_cursor",
"(",
"save_cursor",
")",
"self",
".",
"parent",
".",
"document",
".",
"add_text",
"(",
"text",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument._set_color_scheme | Default color object is black letters
& black lines. | pypdflite/pdfdocument.py | def _set_color_scheme(self, draw_color=None, fill_color=None, text_color=None):
""" Default color object is black letters
& black lines."""
if draw_color is None:
draw_color = PDFColor()
draw_color._set_type('d')
if fill_color is None:
fill_color = PDFColor()
fill_color._set_type('f')
if text_color is None:
text_color = PDFColor()
text_color._set_type('t')
self.draw_color = draw_color
self.fill_color = fill_color
self.text_color = text_color | def _set_color_scheme(self, draw_color=None, fill_color=None, text_color=None):
""" Default color object is black letters
& black lines."""
if draw_color is None:
draw_color = PDFColor()
draw_color._set_type('d')
if fill_color is None:
fill_color = PDFColor()
fill_color._set_type('f')
if text_color is None:
text_color = PDFColor()
text_color._set_type('t')
self.draw_color = draw_color
self.fill_color = fill_color
self.text_color = text_color | [
"Default",
"color",
"object",
"is",
"black",
"letters",
"&",
"black",
"lines",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L71-L86 | [
"def",
"_set_color_scheme",
"(",
"self",
",",
"draw_color",
"=",
"None",
",",
"fill_color",
"=",
"None",
",",
"text_color",
"=",
"None",
")",
":",
"if",
"draw_color",
"is",
"None",
":",
"draw_color",
"=",
"PDFColor",
"(",
")",
"draw_color",
".",
"_set_type",
"(",
"'d'",
")",
"if",
"fill_color",
"is",
"None",
":",
"fill_color",
"=",
"PDFColor",
"(",
")",
"fill_color",
".",
"_set_type",
"(",
"'f'",
")",
"if",
"text_color",
"is",
"None",
":",
"text_color",
"=",
"PDFColor",
"(",
")",
"text_color",
".",
"_set_type",
"(",
"'t'",
")",
"self",
".",
"draw_color",
"=",
"draw_color",
"self",
".",
"fill_color",
"=",
"fill_color",
"self",
".",
"text_color",
"=",
"text_color"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument._set_default_font | Internal method to set the initial default font. Change
the font using set_font method. | pypdflite/pdfdocument.py | def _set_default_font(self):
""" Internal method to set the initial default font. Change
the font using set_font method."""
self.font = PDFFont(self.session)
self.font._set_index()
self.fonts.append(self.font)
self.fontkeys.append(self.font.font_key) | def _set_default_font(self):
""" Internal method to set the initial default font. Change
the font using set_font method."""
self.font = PDFFont(self.session)
self.font._set_index()
self.fonts.append(self.font)
self.fontkeys.append(self.font.font_key) | [
"Internal",
"method",
"to",
"set",
"the",
"initial",
"default",
"font",
".",
"Change",
"the",
"font",
"using",
"set_font",
"method",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L106-L112 | [
"def",
"_set_default_font",
"(",
"self",
")",
":",
"self",
".",
"font",
"=",
"PDFFont",
"(",
"self",
".",
"session",
")",
"self",
".",
"font",
".",
"_set_index",
"(",
")",
"self",
".",
"fonts",
".",
"append",
"(",
"self",
".",
"font",
")",
"self",
".",
"fontkeys",
".",
"append",
"(",
"self",
".",
"font",
".",
"font_key",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument.add_page | May generate and add a PDFPage separately, or use this to generate
a default page. | pypdflite/pdfdocument.py | def add_page(self, page=None):
""" May generate and add a PDFPage separately, or use this to generate
a default page."""
if page is None:
self.page = PDFPage(self.orientation_default, self.layout_default, self.margins)
else:
self.page = page
self.page._set_index(len(self.pages))
self.pages.append(self.page)
currentfont = self.font
self.set_font(font=currentfont)
self.session._reset_colors() | def add_page(self, page=None):
""" May generate and add a PDFPage separately, or use this to generate
a default page."""
if page is None:
self.page = PDFPage(self.orientation_default, self.layout_default, self.margins)
else:
self.page = page
self.page._set_index(len(self.pages))
self.pages.append(self.page)
currentfont = self.font
self.set_font(font=currentfont)
self.session._reset_colors() | [
"May",
"generate",
"and",
"add",
"a",
"PDFPage",
"separately",
"or",
"use",
"this",
"to",
"generate",
"a",
"default",
"page",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L120-L131 | [
"def",
"add_page",
"(",
"self",
",",
"page",
"=",
"None",
")",
":",
"if",
"page",
"is",
"None",
":",
"self",
".",
"page",
"=",
"PDFPage",
"(",
"self",
".",
"orientation_default",
",",
"self",
".",
"layout_default",
",",
"self",
".",
"margins",
")",
"else",
":",
"self",
".",
"page",
"=",
"page",
"self",
".",
"page",
".",
"_set_index",
"(",
"len",
"(",
"self",
".",
"pages",
")",
")",
"self",
".",
"pages",
".",
"append",
"(",
"self",
".",
"page",
")",
"currentfont",
"=",
"self",
".",
"font",
"self",
".",
"set_font",
"(",
"font",
"=",
"currentfont",
")",
"self",
".",
"session",
".",
"_reset_colors",
"(",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument.set_font | Set the document font object, size given in points. If family, style, and/or size is given, generates
a new Font object, checks to see if it is already in use, and selects it. | pypdflite/pdfdocument.py | def set_font(self, family=None, style='', size=None, font=None):
""" Set the document font object, size given in points. If family, style, and/or size is given, generates
a new Font object, checks to see if it is already in use, and selects it. """
if font:
testfont = font
elif isinstance(family, PDFFont):
testfont = family
else:
# If size is not defined, keep the last size.
if size is None:
size = self.font.font_size
# Create a font from givens to test its key
if family in CORE_FONTS:
testfont = PDFFont(self.session, family, style, size)
else:
testfont = PDFTTFont(self.session, family, style, size)
testkey = testfont.font_key
if testkey in self.fontkeys:
index = self.fontkeys.index(testkey)
self.font = self.fonts[index]
if size != self.font.font_size:
self.font._set_size(size)
if style != self.font.style:
self.font._set_style(style)
else:
self.font = testfont
self._register_new_font(self.font)
self.font.is_set = False
if self.page.index > 0:
self.session._out('BT /F%d %.2f Tf ET' %
(self.font.index, self.font.font_size),
self.page)
self.font.is_set = True
return self.font | def set_font(self, family=None, style='', size=None, font=None):
""" Set the document font object, size given in points. If family, style, and/or size is given, generates
a new Font object, checks to see if it is already in use, and selects it. """
if font:
testfont = font
elif isinstance(family, PDFFont):
testfont = family
else:
# If size is not defined, keep the last size.
if size is None:
size = self.font.font_size
# Create a font from givens to test its key
if family in CORE_FONTS:
testfont = PDFFont(self.session, family, style, size)
else:
testfont = PDFTTFont(self.session, family, style, size)
testkey = testfont.font_key
if testkey in self.fontkeys:
index = self.fontkeys.index(testkey)
self.font = self.fonts[index]
if size != self.font.font_size:
self.font._set_size(size)
if style != self.font.style:
self.font._set_style(style)
else:
self.font = testfont
self._register_new_font(self.font)
self.font.is_set = False
if self.page.index > 0:
self.session._out('BT /F%d %.2f Tf ET' %
(self.font.index, self.font.font_size),
self.page)
self.font.is_set = True
return self.font | [
"Set",
"the",
"document",
"font",
"object",
"size",
"given",
"in",
"points",
".",
"If",
"family",
"style",
"and",
"/",
"or",
"size",
"is",
"given",
"generates",
"a",
"new",
"Font",
"object",
"checks",
"to",
"see",
"if",
"it",
"is",
"already",
"in",
"use",
"and",
"selects",
"it",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L179-L217 | [
"def",
"set_font",
"(",
"self",
",",
"family",
"=",
"None",
",",
"style",
"=",
"''",
",",
"size",
"=",
"None",
",",
"font",
"=",
"None",
")",
":",
"if",
"font",
":",
"testfont",
"=",
"font",
"elif",
"isinstance",
"(",
"family",
",",
"PDFFont",
")",
":",
"testfont",
"=",
"family",
"else",
":",
"# If size is not defined, keep the last size.\r",
"if",
"size",
"is",
"None",
":",
"size",
"=",
"self",
".",
"font",
".",
"font_size",
"# Create a font from givens to test its key\r",
"if",
"family",
"in",
"CORE_FONTS",
":",
"testfont",
"=",
"PDFFont",
"(",
"self",
".",
"session",
",",
"family",
",",
"style",
",",
"size",
")",
"else",
":",
"testfont",
"=",
"PDFTTFont",
"(",
"self",
".",
"session",
",",
"family",
",",
"style",
",",
"size",
")",
"testkey",
"=",
"testfont",
".",
"font_key",
"if",
"testkey",
"in",
"self",
".",
"fontkeys",
":",
"index",
"=",
"self",
".",
"fontkeys",
".",
"index",
"(",
"testkey",
")",
"self",
".",
"font",
"=",
"self",
".",
"fonts",
"[",
"index",
"]",
"if",
"size",
"!=",
"self",
".",
"font",
".",
"font_size",
":",
"self",
".",
"font",
".",
"_set_size",
"(",
"size",
")",
"if",
"style",
"!=",
"self",
".",
"font",
".",
"style",
":",
"self",
".",
"font",
".",
"_set_style",
"(",
"style",
")",
"else",
":",
"self",
".",
"font",
"=",
"testfont",
"self",
".",
"_register_new_font",
"(",
"self",
".",
"font",
")",
"self",
".",
"font",
".",
"is_set",
"=",
"False",
"if",
"self",
".",
"page",
".",
"index",
">",
"0",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'BT /F%d %.2f Tf ET'",
"%",
"(",
"self",
".",
"font",
".",
"index",
",",
"self",
".",
"font",
".",
"font_size",
")",
",",
"self",
".",
"page",
")",
"self",
".",
"font",
".",
"is_set",
"=",
"True",
"return",
"self",
".",
"font"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument.set_font_size | Convenience method for just changing font size. | pypdflite/pdfdocument.py | def set_font_size(self, size):
"""Convenience method for just changing font size."""
if self.font.font_size == size:
pass
else:
self.font._set_size(size) | def set_font_size(self, size):
"""Convenience method for just changing font size."""
if self.font.font_size == size:
pass
else:
self.font._set_size(size) | [
"Convenience",
"method",
"for",
"just",
"changing",
"font",
"size",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L224-L229 | [
"def",
"set_font_size",
"(",
"self",
",",
"size",
")",
":",
"if",
"self",
".",
"font",
".",
"font_size",
"==",
"size",
":",
"pass",
"else",
":",
"self",
".",
"font",
".",
"_set_size",
"(",
"size",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument.add_text | Input text, short or long. Writes in order, within the defined page boundaries. Sequential add_text commands will print without
additional whitespace. | pypdflite/pdfdocument.py | def add_text(self, text, cursor=None, justification=None):
""" Input text, short or long. Writes in order, within the defined page boundaries. Sequential add_text commands will print without
additional whitespace. """
if cursor is None:
cursor = self.page.cursor
text = re.sub("\s\s+" , " ", text)
if justification is None:
justification = self.justification
if '\n' in text:
text_list = text.split('\n')
for text in text_list:
PDFText(self.session, self.page, text, self.font, self.text_color, cursor, justification, self.double_spacing)
self.add_newline()
else:
PDFText(self.session, self.page, text, self.font, self.text_color, cursor, justification, self.double_spacing) | def add_text(self, text, cursor=None, justification=None):
""" Input text, short or long. Writes in order, within the defined page boundaries. Sequential add_text commands will print without
additional whitespace. """
if cursor is None:
cursor = self.page.cursor
text = re.sub("\s\s+" , " ", text)
if justification is None:
justification = self.justification
if '\n' in text:
text_list = text.split('\n')
for text in text_list:
PDFText(self.session, self.page, text, self.font, self.text_color, cursor, justification, self.double_spacing)
self.add_newline()
else:
PDFText(self.session, self.page, text, self.font, self.text_color, cursor, justification, self.double_spacing) | [
"Input",
"text",
"short",
"or",
"long",
".",
"Writes",
"in",
"order",
"within",
"the",
"defined",
"page",
"boundaries",
".",
"Sequential",
"add_text",
"commands",
"will",
"print",
"without",
"additional",
"whitespace",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L238-L255 | [
"def",
"add_text",
"(",
"self",
",",
"text",
",",
"cursor",
"=",
"None",
",",
"justification",
"=",
"None",
")",
":",
"if",
"cursor",
"is",
"None",
":",
"cursor",
"=",
"self",
".",
"page",
".",
"cursor",
"text",
"=",
"re",
".",
"sub",
"(",
"\"\\s\\s+\"",
",",
"\" \"",
",",
"text",
")",
"if",
"justification",
"is",
"None",
":",
"justification",
"=",
"self",
".",
"justification",
"if",
"'\\n'",
"in",
"text",
":",
"text_list",
"=",
"text",
".",
"split",
"(",
"'\\n'",
")",
"for",
"text",
"in",
"text_list",
":",
"PDFText",
"(",
"self",
".",
"session",
",",
"self",
".",
"page",
",",
"text",
",",
"self",
".",
"font",
",",
"self",
".",
"text_color",
",",
"cursor",
",",
"justification",
",",
"self",
".",
"double_spacing",
")",
"self",
".",
"add_newline",
"(",
")",
"else",
":",
"PDFText",
"(",
"self",
".",
"session",
",",
"self",
".",
"page",
",",
"text",
",",
"self",
".",
"font",
",",
"self",
".",
"text_color",
",",
"cursor",
",",
"justification",
",",
"self",
".",
"double_spacing",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument.add_newline | Starts over again at the new line. If number is specified,
it will leave multiple lines. | pypdflite/pdfdocument.py | def add_newline(self, number=1):
""" Starts over again at the new line. If number is specified,
it will leave multiple lines."""
if isinstance(number, int):
try:
self.page._add_newline(self.font, number, self.double_spacing)
except ValueError:
self.add_page()
else:
raise TypeError("Number of newlines must be an integer.") | def add_newline(self, number=1):
""" Starts over again at the new line. If number is specified,
it will leave multiple lines."""
if isinstance(number, int):
try:
self.page._add_newline(self.font, number, self.double_spacing)
except ValueError:
self.add_page()
else:
raise TypeError("Number of newlines must be an integer.") | [
"Starts",
"over",
"again",
"at",
"the",
"new",
"line",
".",
"If",
"number",
"is",
"specified",
"it",
"will",
"leave",
"multiple",
"lines",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L266-L275 | [
"def",
"add_newline",
"(",
"self",
",",
"number",
"=",
"1",
")",
":",
"if",
"isinstance",
"(",
"number",
",",
"int",
")",
":",
"try",
":",
"self",
".",
"page",
".",
"_add_newline",
"(",
"self",
".",
"font",
",",
"number",
",",
"self",
".",
"double_spacing",
")",
"except",
"ValueError",
":",
"self",
".",
"add_page",
"(",
")",
"else",
":",
"raise",
"TypeError",
"(",
"\"Number of newlines must be an integer.\"",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument.add_pie_chart | Data type may be "raw" or "percent" | pypdflite/pdfdocument.py | def add_pie_chart(self, data, cursor, width, height, title=None, data_type="raw", fill_colors=None, labels=False, background=None, legend=None):
""" Data type may be "raw" or "percent" """
save_draw_color = self.draw_color
save_fill_color = self.fill_color
chart = PDFPieChart(self.session, self.page, data, cursor, width, height, title, data_type, fill_colors, labels, background, legend)
self.set_draw_color(save_draw_color)
self.set_fill_color(save_fill_color) | def add_pie_chart(self, data, cursor, width, height, title=None, data_type="raw", fill_colors=None, labels=False, background=None, legend=None):
""" Data type may be "raw" or "percent" """
save_draw_color = self.draw_color
save_fill_color = self.fill_color
chart = PDFPieChart(self.session, self.page, data, cursor, width, height, title, data_type, fill_colors, labels, background, legend)
self.set_draw_color(save_draw_color)
self.set_fill_color(save_fill_color) | [
"Data",
"type",
"may",
"be",
"raw",
"or",
"percent"
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L537-L545 | [
"def",
"add_pie_chart",
"(",
"self",
",",
"data",
",",
"cursor",
",",
"width",
",",
"height",
",",
"title",
"=",
"None",
",",
"data_type",
"=",
"\"raw\"",
",",
"fill_colors",
"=",
"None",
",",
"labels",
"=",
"False",
",",
"background",
"=",
"None",
",",
"legend",
"=",
"None",
")",
":",
"save_draw_color",
"=",
"self",
".",
"draw_color",
"save_fill_color",
"=",
"self",
".",
"fill_color",
"chart",
"=",
"PDFPieChart",
"(",
"self",
".",
"session",
",",
"self",
".",
"page",
",",
"data",
",",
"cursor",
",",
"width",
",",
"height",
",",
"title",
",",
"data_type",
",",
"fill_colors",
",",
"labels",
",",
"background",
",",
"legend",
")",
"self",
".",
"set_draw_color",
"(",
"save_draw_color",
")",
"self",
".",
"set_fill_color",
"(",
"save_fill_color",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument._output_pages | Called by the PDFLite object to prompt creating
the page objects. | pypdflite/pdfdocument.py | def _output_pages(self):
""" Called by the PDFLite object to prompt creating
the page objects."""
if not self.orientation_changes:
self._get_orientation_changes()
# Page
for page in self.pages:
obj = self.session._add_object()
self.session._out('<</Type /Page')
self.session._out('/Parent 1 0 R')
if self.orientation_changes:
self.session._out('/MediaBox [0 0 %.2f %.2f]' % (page.width, page.height))
self.session._out('/Resources 2 0 R')
self.session._out('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>')
self.session._out('/Contents %s 0 R>>' % (obj.id + 1))
self.session._out('endobj')
# Page content
self.session._add_object()
if self.session.compression is True:
textfilter = ' /Filter /FlateDecode '
page._compress()
else:
textfilter = ''
self.session._out('<<%s/Length %s >>' % (textfilter, len(page.buffer)))
self.session._put_stream(page.buffer)
self.session._out('endobj') | def _output_pages(self):
""" Called by the PDFLite object to prompt creating
the page objects."""
if not self.orientation_changes:
self._get_orientation_changes()
# Page
for page in self.pages:
obj = self.session._add_object()
self.session._out('<</Type /Page')
self.session._out('/Parent 1 0 R')
if self.orientation_changes:
self.session._out('/MediaBox [0 0 %.2f %.2f]' % (page.width, page.height))
self.session._out('/Resources 2 0 R')
self.session._out('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>')
self.session._out('/Contents %s 0 R>>' % (obj.id + 1))
self.session._out('endobj')
# Page content
self.session._add_object()
if self.session.compression is True:
textfilter = ' /Filter /FlateDecode '
page._compress()
else:
textfilter = ''
self.session._out('<<%s/Length %s >>' % (textfilter, len(page.buffer)))
self.session._put_stream(page.buffer)
self.session._out('endobj') | [
"Called",
"by",
"the",
"PDFLite",
"object",
"to",
"prompt",
"creating",
"the",
"page",
"objects",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L637-L664 | [
"def",
"_output_pages",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"orientation_changes",
":",
"self",
".",
"_get_orientation_changes",
"(",
")",
"# Page\r",
"for",
"page",
"in",
"self",
".",
"pages",
":",
"obj",
"=",
"self",
".",
"session",
".",
"_add_object",
"(",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'<</Type /Page'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Parent 1 0 R'",
")",
"if",
"self",
".",
"orientation_changes",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/MediaBox [0 0 %.2f %.2f]'",
"%",
"(",
"page",
".",
"width",
",",
"page",
".",
"height",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Resources 2 0 R'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Contents %s 0 R>>'",
"%",
"(",
"obj",
".",
"id",
"+",
"1",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'endobj'",
")",
"# Page content\r",
"self",
".",
"session",
".",
"_add_object",
"(",
")",
"if",
"self",
".",
"session",
".",
"compression",
"is",
"True",
":",
"textfilter",
"=",
"' /Filter /FlateDecode '",
"page",
".",
"_compress",
"(",
")",
"else",
":",
"textfilter",
"=",
"''",
"self",
".",
"session",
".",
"_out",
"(",
"'<<%s/Length %s >>'",
"%",
"(",
"textfilter",
",",
"len",
"(",
"page",
".",
"buffer",
")",
")",
")",
"self",
".",
"session",
".",
"_put_stream",
"(",
"page",
".",
"buffer",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'endobj'",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument._get_orientation_changes | Returns a list of the pages that have
orientation changes. | pypdflite/pdfdocument.py | def _get_orientation_changes(self):
""" Returns a list of the pages that have
orientation changes."""
self.orientation_changes = []
for page in self.pages:
if page.orientation_change is True:
self.orientation_changes.append(page.index)
else:
pass
return self.orientation_changes | def _get_orientation_changes(self):
""" Returns a list of the pages that have
orientation changes."""
self.orientation_changes = []
for page in self.pages:
if page.orientation_change is True:
self.orientation_changes.append(page.index)
else:
pass
return self.orientation_changes | [
"Returns",
"a",
"list",
"of",
"the",
"pages",
"that",
"have",
"orientation",
"changes",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L703-L712 | [
"def",
"_get_orientation_changes",
"(",
"self",
")",
":",
"self",
".",
"orientation_changes",
"=",
"[",
"]",
"for",
"page",
"in",
"self",
".",
"pages",
":",
"if",
"page",
".",
"orientation_change",
"is",
"True",
":",
"self",
".",
"orientation_changes",
".",
"append",
"(",
"page",
".",
"index",
")",
"else",
":",
"pass",
"return",
"self",
".",
"orientation_changes"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument._output_fonts | Called by the PDFLite object to prompt creating
the font objects. | pypdflite/pdfdocument.py | def _output_fonts(self):
""" Called by the PDFLite object to prompt creating
the font objects."""
self.session._save_object_number()
self._output_encoding_diffs()
self._output_font_files()
for font in self.fonts:
obj = self.session._add_object()
font._set_number(obj.id)
font._output() | def _output_fonts(self):
""" Called by the PDFLite object to prompt creating
the font objects."""
self.session._save_object_number()
self._output_encoding_diffs()
self._output_font_files()
for font in self.fonts:
obj = self.session._add_object()
font._set_number(obj.id)
font._output() | [
"Called",
"by",
"the",
"PDFLite",
"object",
"to",
"prompt",
"creating",
"the",
"font",
"objects",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L726-L736 | [
"def",
"_output_fonts",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"_save_object_number",
"(",
")",
"self",
".",
"_output_encoding_diffs",
"(",
")",
"self",
".",
"_output_font_files",
"(",
")",
"for",
"font",
"in",
"self",
".",
"fonts",
":",
"obj",
"=",
"self",
".",
"session",
".",
"_add_object",
"(",
")",
"font",
".",
"_set_number",
"(",
"obj",
".",
"id",
")",
"font",
".",
"_output",
"(",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFDocument._output_images | Creates reference images, that can be
drawn throughout the document. | pypdflite/pdfdocument.py | def _output_images(self):
""" Creates reference images, that can be
drawn throughout the document."""
for image in self.images:
obj = self.session._add_object()
image._set_number(obj.id)
image._output() | def _output_images(self):
""" Creates reference images, that can be
drawn throughout the document."""
for image in self.images:
obj = self.session._add_object()
image._set_number(obj.id)
image._output() | [
"Creates",
"reference",
"images",
"that",
"can",
"be",
"drawn",
"throughout",
"the",
"document",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfdocument.py#L755-L761 | [
"def",
"_output_images",
"(",
"self",
")",
":",
"for",
"image",
"in",
"self",
".",
"images",
":",
"obj",
"=",
"self",
".",
"session",
".",
"_add_object",
"(",
")",
"image",
".",
"_set_number",
"(",
"obj",
".",
"id",
")",
"image",
".",
"_output",
"(",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFImage._output | Prompts the creating of image objects. | pypdflite/pdfobjects/pdfimage.py | def _output(self):
""" Prompts the creating of image objects.
"""
self.session._out('<</Type /XObject')
self.session._out('/Subtype /Image')
self.session._out('/Width %s' % self.width)
self.session._out('/Height %s' % self.height)
if self.colorspace is 'Indexed':
self.session._out('/ColorSpace [/Indexed /DeviceRGB %s %s 0 R' %
(self.pal, self.number + 1))
else:
self.session._out('/ColorSpace /%s' % self.colorspace)
if self.colorspace is 'DeviceCMYK':
self.session._out('/Decode [1 0 1 0 1 0 1 0]')
self.session._out('/BitsPerComponent %s' % self.bits_per_component)
if self.filter:
self.session._out('/Filter /%s' % self.filter)
if self.decode:
self.session._out('/DecodeParms << %s >>' % self.decode)
if self.transparent:
self.session._out('/Mask [%s]' % self.transparent_string)
if self.soft_mask:
self.session._out('/SMask %s 0 R' % (self.number + 1))
self.session._out('/Length %s >>' % self.size)
self.session._put_stream(self.image_data)
self.session._out('endobj')
if self.colorspace is 'Indexed':
self.session._out('<<%s /Length %s >>' % (self.palette_filter, self.palette_length))
self.session._put_stream(self.palette)
self.session._out('endobj')
if isinstance(self.soft_mask, PDFImage):
obj = self.session._add_object()
self.soft_mask._set_number(obj.id)
self.soft_mask._output() | def _output(self):
""" Prompts the creating of image objects.
"""
self.session._out('<</Type /XObject')
self.session._out('/Subtype /Image')
self.session._out('/Width %s' % self.width)
self.session._out('/Height %s' % self.height)
if self.colorspace is 'Indexed':
self.session._out('/ColorSpace [/Indexed /DeviceRGB %s %s 0 R' %
(self.pal, self.number + 1))
else:
self.session._out('/ColorSpace /%s' % self.colorspace)
if self.colorspace is 'DeviceCMYK':
self.session._out('/Decode [1 0 1 0 1 0 1 0]')
self.session._out('/BitsPerComponent %s' % self.bits_per_component)
if self.filter:
self.session._out('/Filter /%s' % self.filter)
if self.decode:
self.session._out('/DecodeParms << %s >>' % self.decode)
if self.transparent:
self.session._out('/Mask [%s]' % self.transparent_string)
if self.soft_mask:
self.session._out('/SMask %s 0 R' % (self.number + 1))
self.session._out('/Length %s >>' % self.size)
self.session._put_stream(self.image_data)
self.session._out('endobj')
if self.colorspace is 'Indexed':
self.session._out('<<%s /Length %s >>' % (self.palette_filter, self.palette_length))
self.session._put_stream(self.palette)
self.session._out('endobj')
if isinstance(self.soft_mask, PDFImage):
obj = self.session._add_object()
self.soft_mask._set_number(obj.id)
self.soft_mask._output() | [
"Prompts",
"the",
"creating",
"of",
"image",
"objects",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfimage.py#L228-L267 | [
"def",
"_output",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'<</Type /XObject'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Subtype /Image'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Width %s'",
"%",
"self",
".",
"width",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Height %s'",
"%",
"self",
".",
"height",
")",
"if",
"self",
".",
"colorspace",
"is",
"'Indexed'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/ColorSpace [/Indexed /DeviceRGB %s %s 0 R'",
"%",
"(",
"self",
".",
"pal",
",",
"self",
".",
"number",
"+",
"1",
")",
")",
"else",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/ColorSpace /%s'",
"%",
"self",
".",
"colorspace",
")",
"if",
"self",
".",
"colorspace",
"is",
"'DeviceCMYK'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/Decode [1 0 1 0 1 0 1 0]'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/BitsPerComponent %s'",
"%",
"self",
".",
"bits_per_component",
")",
"if",
"self",
".",
"filter",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/Filter /%s'",
"%",
"self",
".",
"filter",
")",
"if",
"self",
".",
"decode",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/DecodeParms << %s >>'",
"%",
"self",
".",
"decode",
")",
"if",
"self",
".",
"transparent",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/Mask [%s]'",
"%",
"self",
".",
"transparent_string",
")",
"if",
"self",
".",
"soft_mask",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/SMask %s 0 R'",
"%",
"(",
"self",
".",
"number",
"+",
"1",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Length %s >>'",
"%",
"self",
".",
"size",
")",
"self",
".",
"session",
".",
"_put_stream",
"(",
"self",
".",
"image_data",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'endobj'",
")",
"if",
"self",
".",
"colorspace",
"is",
"'Indexed'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'<<%s /Length %s >>'",
"%",
"(",
"self",
".",
"palette_filter",
",",
"self",
".",
"palette_length",
")",
")",
"self",
".",
"session",
".",
"_put_stream",
"(",
"self",
".",
"palette",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'endobj'",
")",
"if",
"isinstance",
"(",
"self",
".",
"soft_mask",
",",
"PDFImage",
")",
":",
"obj",
"=",
"self",
".",
"session",
".",
"_add_object",
"(",
")",
"self",
".",
"soft_mask",
".",
"_set_number",
"(",
"obj",
".",
"id",
")",
"self",
".",
"soft_mask",
".",
"_output",
"(",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFTransform.transform | Adjust the current transformation state of the current graphics state
matrix. Not recommended for the faint of heart. | pypdflite/pdfobjects/pdftransforms.py | def transform(self, a, b, c, d, e, f):
""" Adjust the current transformation state of the current graphics state
matrix. Not recommended for the faint of heart.
"""
a0, b0, c0, d0, e0, f0 = self._currentMatrix
self._currentMatrix = (a0 * a + c0 * b, b0 * a + d0 * b,
a0 * c + c0 * d, b0 * c + d0 * d,
a0 * e + c0 * f + e0, b0 * e + d0 * f + f0)
a1, b1, c1, d1, e1, f1 = self._currentMatrix
self.session._out('%.2f %.2f %.2f %.2f %.2f %.2f cm' % (a1, b1, c1, d1, e1, f1), self.page) | def transform(self, a, b, c, d, e, f):
""" Adjust the current transformation state of the current graphics state
matrix. Not recommended for the faint of heart.
"""
a0, b0, c0, d0, e0, f0 = self._currentMatrix
self._currentMatrix = (a0 * a + c0 * b, b0 * a + d0 * b,
a0 * c + c0 * d, b0 * c + d0 * d,
a0 * e + c0 * f + e0, b0 * e + d0 * f + f0)
a1, b1, c1, d1, e1, f1 = self._currentMatrix
self.session._out('%.2f %.2f %.2f %.2f %.2f %.2f cm' % (a1, b1, c1, d1, e1, f1), self.page) | [
"Adjust",
"the",
"current",
"transformation",
"state",
"of",
"the",
"current",
"graphics",
"state",
"matrix",
".",
"Not",
"recommended",
"for",
"the",
"faint",
"of",
"heart",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdftransforms.py#L45-L54 | [
"def",
"transform",
"(",
"self",
",",
"a",
",",
"b",
",",
"c",
",",
"d",
",",
"e",
",",
"f",
")",
":",
"a0",
",",
"b0",
",",
"c0",
",",
"d0",
",",
"e0",
",",
"f0",
"=",
"self",
".",
"_currentMatrix",
"self",
".",
"_currentMatrix",
"=",
"(",
"a0",
"*",
"a",
"+",
"c0",
"*",
"b",
",",
"b0",
"*",
"a",
"+",
"d0",
"*",
"b",
",",
"a0",
"*",
"c",
"+",
"c0",
"*",
"d",
",",
"b0",
"*",
"c",
"+",
"d0",
"*",
"d",
",",
"a0",
"*",
"e",
"+",
"c0",
"*",
"f",
"+",
"e0",
",",
"b0",
"*",
"e",
"+",
"d0",
"*",
"f",
"+",
"f0",
")",
"a1",
",",
"b1",
",",
"c1",
",",
"d1",
",",
"e1",
",",
"f1",
"=",
"self",
".",
"_currentMatrix",
"self",
".",
"session",
".",
"_out",
"(",
"'%.2f %.2f %.2f %.2f %.2f %.2f cm'",
"%",
"(",
"a1",
",",
"b1",
",",
"c1",
",",
"d1",
",",
"e1",
",",
"f1",
")",
",",
"self",
".",
"page",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFTransform.absolute_position | return the absolute position of x,y in user space w.r.t. default user space | pypdflite/pdfobjects/pdftransforms.py | def absolute_position(self, x, y):
"""return the absolute position of x,y in user space w.r.t. default user space"""
(a, b, c, d, e, f) = self._currentMatrix
xp = a * x + c * y + e
yp = b * x + d * y + f
return xp, yp | def absolute_position(self, x, y):
"""return the absolute position of x,y in user space w.r.t. default user space"""
(a, b, c, d, e, f) = self._currentMatrix
xp = a * x + c * y + e
yp = b * x + d * y + f
return xp, yp | [
"return",
"the",
"absolute",
"position",
"of",
"x",
"y",
"in",
"user",
"space",
"w",
".",
"r",
".",
"t",
".",
"default",
"user",
"space"
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdftransforms.py#L56-L61 | [
"def",
"absolute_position",
"(",
"self",
",",
"x",
",",
"y",
")",
":",
"(",
"a",
",",
"b",
",",
"c",
",",
"d",
",",
"e",
",",
"f",
")",
"=",
"self",
".",
"_currentMatrix",
"xp",
"=",
"a",
"*",
"x",
"+",
"c",
"*",
"y",
"+",
"e",
"yp",
"=",
"b",
"*",
"x",
"+",
"d",
"*",
"y",
"+",
"f",
"return",
"xp",
",",
"yp"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFTransform.rotate | Rotate current graphic state by the angle theta (in degrees). | pypdflite/pdfobjects/pdftransforms.py | def rotate(self, theta):
"""Rotate current graphic state by the angle theta (in degrees)."""
c = cos(theta * pi / 180)
s = sin(theta * pi / 180)
self.transform(c, s, -s, c, 0, 0) | def rotate(self, theta):
"""Rotate current graphic state by the angle theta (in degrees)."""
c = cos(theta * pi / 180)
s = sin(theta * pi / 180)
self.transform(c, s, -s, c, 0, 0) | [
"Rotate",
"current",
"graphic",
"state",
"by",
"the",
"angle",
"theta",
"(",
"in",
"degrees",
")",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdftransforms.py#L74-L78 | [
"def",
"rotate",
"(",
"self",
",",
"theta",
")",
":",
"c",
"=",
"cos",
"(",
"theta",
"*",
"pi",
"/",
"180",
")",
"s",
"=",
"sin",
"(",
"theta",
"*",
"pi",
"/",
"180",
")",
"self",
".",
"transform",
"(",
"c",
",",
"s",
",",
"-",
"s",
",",
"c",
",",
"0",
",",
"0",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFFont._set_style | Style should be a string, containing the letters 'B' for bold,
'U' for underline, or 'I' for italic, or should be '', for no style.
Symbol will not be underlined. The underline style can further be
modified by specifying the underline thickness and position. | pypdflite/pdfobjects/pdffont.py | def _set_style(self, style=None):
""" Style should be a string, containing the letters 'B' for bold,
'U' for underline, or 'I' for italic, or should be '', for no style.
Symbol will not be underlined. The underline style can further be
modified by specifying the underline thickness and position.
"""
if style is None:
self.style = ''
self.underline = False
# No syling for symbol
elif self.family == ('symbol' or 'zapfdingbats'):
self.style = ''
self.underline = False
self.style = style.upper()
# SetUnderline
if 'U' in self.style or self.style == 'U':
self.underline = True
else:
self.underline = False | def _set_style(self, style=None):
""" Style should be a string, containing the letters 'B' for bold,
'U' for underline, or 'I' for italic, or should be '', for no style.
Symbol will not be underlined. The underline style can further be
modified by specifying the underline thickness and position.
"""
if style is None:
self.style = ''
self.underline = False
# No syling for symbol
elif self.family == ('symbol' or 'zapfdingbats'):
self.style = ''
self.underline = False
self.style = style.upper()
# SetUnderline
if 'U' in self.style or self.style == 'U':
self.underline = True
else:
self.underline = False | [
"Style",
"should",
"be",
"a",
"string",
"containing",
"the",
"letters",
"B",
"for",
"bold",
"U",
"for",
"underline",
"or",
"I",
"for",
"italic",
"or",
"should",
"be",
"for",
"no",
"style",
".",
"Symbol",
"will",
"not",
"be",
"underlined",
".",
"The",
"underline",
"style",
"can",
"further",
"be",
"modified",
"by",
"specifying",
"the",
"underline",
"thickness",
"and",
"position",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdffont.py#L47-L68 | [
"def",
"_set_style",
"(",
"self",
",",
"style",
"=",
"None",
")",
":",
"if",
"style",
"is",
"None",
":",
"self",
".",
"style",
"=",
"''",
"self",
".",
"underline",
"=",
"False",
"# No syling for symbol\r",
"elif",
"self",
".",
"family",
"==",
"(",
"'symbol'",
"or",
"'zapfdingbats'",
")",
":",
"self",
".",
"style",
"=",
"''",
"self",
".",
"underline",
"=",
"False",
"self",
".",
"style",
"=",
"style",
".",
"upper",
"(",
")",
"# SetUnderline\r",
"if",
"'U'",
"in",
"self",
".",
"style",
"or",
"self",
".",
"style",
"==",
"'U'",
":",
"self",
".",
"underline",
"=",
"True",
"else",
":",
"self",
".",
"underline",
"=",
"False"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFFont._set_font | Select a font; size given in points | pypdflite/pdfobjects/pdffont.py | def _set_font(self, family=None, style=None, size=None):
"""Select a font; size given in points"""
self._set_family(family)
self._set_style(style)
self._set_size(size)
self._set_font_key()
self._set_name()
self._set_character_widths() | def _set_font(self, family=None, style=None, size=None):
"""Select a font; size given in points"""
self._set_family(family)
self._set_style(style)
self._set_size(size)
self._set_font_key()
self._set_name()
self._set_character_widths() | [
"Select",
"a",
"font",
";",
"size",
"given",
"in",
"points"
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdffont.py#L105-L112 | [
"def",
"_set_font",
"(",
"self",
",",
"family",
"=",
"None",
",",
"style",
"=",
"None",
",",
"size",
"=",
"None",
")",
":",
"self",
".",
"_set_family",
"(",
"family",
")",
"self",
".",
"_set_style",
"(",
"style",
")",
"self",
".",
"_set_size",
"(",
"size",
")",
"self",
".",
"_set_font_key",
"(",
")",
"self",
".",
"_set_name",
"(",
")",
"self",
".",
"_set_character_widths",
"(",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFFont._string_width | Get width of a string in the current font | pypdflite/pdfobjects/pdffont.py | def _string_width(self, s):
"""Get width of a string in the current font"""
s = str(s)
w = 0
for i in s:
w += self.character_widths[i]
return w * self.font_size / 1000.0 | def _string_width(self, s):
"""Get width of a string in the current font"""
s = str(s)
w = 0
for i in s:
w += self.character_widths[i]
return w * self.font_size / 1000.0 | [
"Get",
"width",
"of",
"a",
"string",
"in",
"the",
"current",
"font"
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdffont.py#L134-L140 | [
"def",
"_string_width",
"(",
"self",
",",
"s",
")",
":",
"s",
"=",
"str",
"(",
"s",
")",
"w",
"=",
"0",
"for",
"i",
"in",
"s",
":",
"w",
"+=",
"self",
".",
"character_widths",
"[",
"i",
"]",
"return",
"w",
"*",
"self",
".",
"font_size",
"/",
"1000.0"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | HASC.getCellVertexes | Edge coordinates of an hexagon centered in (x,y) having a side of d:
[x-d/2, y+sqrt(3)*d/2] [x+d/2, y+sqrt(3)*d/2]
[x-d, y] [x+d, y]
[x-d/2, y-sqrt(3)*d/2] [x+d/2, y-sqrt(3)*d/2] | hex_utils/hasc.py | def getCellVertexes(self, i, j):
"""
Edge coordinates of an hexagon centered in (x,y) having a side of d:
[x-d/2, y+sqrt(3)*d/2] [x+d/2, y+sqrt(3)*d/2]
[x-d, y] [x+d, y]
[x-d/2, y-sqrt(3)*d/2] [x+d/2, y-sqrt(3)*d/2]
"""
# Using unrotated centroid coordinates to avoid an extra computation
x,y = self._getUnrotatedCellCentroidCoords(i, j)
return [
self.rotatePoint(x - self._side, y ),
self.rotatePoint(x - self._side / 2.0, y - self._hexPerp ),
self.rotatePoint(x + self._side / 2.0, y - self._hexPerp ),
self.rotatePoint(x + self._side, y ),
self.rotatePoint(x + self._side / 2.0, y + self._hexPerp ),
self.rotatePoint(x - self._side / 2.0, y + self._hexPerp ),
] | def getCellVertexes(self, i, j):
"""
Edge coordinates of an hexagon centered in (x,y) having a side of d:
[x-d/2, y+sqrt(3)*d/2] [x+d/2, y+sqrt(3)*d/2]
[x-d, y] [x+d, y]
[x-d/2, y-sqrt(3)*d/2] [x+d/2, y-sqrt(3)*d/2]
"""
# Using unrotated centroid coordinates to avoid an extra computation
x,y = self._getUnrotatedCellCentroidCoords(i, j)
return [
self.rotatePoint(x - self._side, y ),
self.rotatePoint(x - self._side / 2.0, y - self._hexPerp ),
self.rotatePoint(x + self._side / 2.0, y - self._hexPerp ),
self.rotatePoint(x + self._side, y ),
self.rotatePoint(x + self._side / 2.0, y + self._hexPerp ),
self.rotatePoint(x - self._side / 2.0, y + self._hexPerp ),
] | [
"Edge",
"coordinates",
"of",
"an",
"hexagon",
"centered",
"in",
"(",
"x",
"y",
")",
"having",
"a",
"side",
"of",
"d",
":",
"[",
"x",
"-",
"d",
"/",
"2",
"y",
"+",
"sqrt",
"(",
"3",
")",
"*",
"d",
"/",
"2",
"]",
"[",
"x",
"+",
"d",
"/",
"2",
"y",
"+",
"sqrt",
"(",
"3",
")",
"*",
"d",
"/",
"2",
"]",
"[",
"x",
"-",
"d",
"y",
"]",
"[",
"x",
"+",
"d",
"y",
"]",
"[",
"x",
"-",
"d",
"/",
"2",
"y",
"-",
"sqrt",
"(",
"3",
")",
"*",
"d",
"/",
"2",
"]",
"[",
"x",
"+",
"d",
"/",
"2",
"y",
"-",
"sqrt",
"(",
"3",
")",
"*",
"d",
"/",
"2",
"]"
] | ldesousa/hex-utils | python | https://github.com/ldesousa/hex-utils/blob/34b47bd9da7c0106defbe1aa5645b52c999c0e1e/hex_utils/hasc.py#L211-L232 | [
"def",
"getCellVertexes",
"(",
"self",
",",
"i",
",",
"j",
")",
":",
"# Using unrotated centroid coordinates to avoid an extra computation",
"x",
",",
"y",
"=",
"self",
".",
"_getUnrotatedCellCentroidCoords",
"(",
"i",
",",
"j",
")",
"return",
"[",
"self",
".",
"rotatePoint",
"(",
"x",
"-",
"self",
".",
"_side",
",",
"y",
")",
",",
"self",
".",
"rotatePoint",
"(",
"x",
"-",
"self",
".",
"_side",
"/",
"2.0",
",",
"y",
"-",
"self",
".",
"_hexPerp",
")",
",",
"self",
".",
"rotatePoint",
"(",
"x",
"+",
"self",
".",
"_side",
"/",
"2.0",
",",
"y",
"-",
"self",
".",
"_hexPerp",
")",
",",
"self",
".",
"rotatePoint",
"(",
"x",
"+",
"self",
".",
"_side",
",",
"y",
")",
",",
"self",
".",
"rotatePoint",
"(",
"x",
"+",
"self",
".",
"_side",
"/",
"2.0",
",",
"y",
"+",
"self",
".",
"_hexPerp",
")",
",",
"self",
".",
"rotatePoint",
"(",
"x",
"-",
"self",
".",
"_side",
"/",
"2.0",
",",
"y",
"+",
"self",
".",
"_hexPerp",
")",
",",
"]"
] | 34b47bd9da7c0106defbe1aa5645b52c999c0e1e |
test | HASC.rotatePoint | Rotates a point relative to the mesh origin by the angle specified in the angle property.
Uses the angle formed between the segment linking the point of interest to the origin and
the parallel intersecting the origin. This angle is called beta in the code. | hex_utils/hasc.py | def rotatePoint(self, pointX, pointY):
"""
Rotates a point relative to the mesh origin by the angle specified in the angle property.
Uses the angle formed between the segment linking the point of interest to the origin and
the parallel intersecting the origin. This angle is called beta in the code.
"""
if(self.angle == 0 or self.angle == None):
return(pointX, pointY)
# 1. Compute the segment length
length = math.sqrt((pointX - self.xll) ** 2 + (pointY - self.yll) ** 2)
# 2. Compute beta
beta = math.acos((pointX - self.xll) / length)
if(pointY < self.yll):
beta = math.pi * 2 - beta
# 3. Compute offsets
offsetX = math.cos(beta) * length - math.cos(self._angle_rd + beta) * length
offsetY = math.sin(self._angle_rd + beta) * length - math.sin(beta) * length
return (pointX - offsetX, pointY + offsetY) | def rotatePoint(self, pointX, pointY):
"""
Rotates a point relative to the mesh origin by the angle specified in the angle property.
Uses the angle formed between the segment linking the point of interest to the origin and
the parallel intersecting the origin. This angle is called beta in the code.
"""
if(self.angle == 0 or self.angle == None):
return(pointX, pointY)
# 1. Compute the segment length
length = math.sqrt((pointX - self.xll) ** 2 + (pointY - self.yll) ** 2)
# 2. Compute beta
beta = math.acos((pointX - self.xll) / length)
if(pointY < self.yll):
beta = math.pi * 2 - beta
# 3. Compute offsets
offsetX = math.cos(beta) * length - math.cos(self._angle_rd + beta) * length
offsetY = math.sin(self._angle_rd + beta) * length - math.sin(beta) * length
return (pointX - offsetX, pointY + offsetY) | [
"Rotates",
"a",
"point",
"relative",
"to",
"the",
"mesh",
"origin",
"by",
"the",
"angle",
"specified",
"in",
"the",
"angle",
"property",
".",
"Uses",
"the",
"angle",
"formed",
"between",
"the",
"segment",
"linking",
"the",
"point",
"of",
"interest",
"to",
"the",
"origin",
"and",
"the",
"parallel",
"intersecting",
"the",
"origin",
".",
"This",
"angle",
"is",
"called",
"beta",
"in",
"the",
"code",
"."
] | ldesousa/hex-utils | python | https://github.com/ldesousa/hex-utils/blob/34b47bd9da7c0106defbe1aa5645b52c999c0e1e/hex_utils/hasc.py#L235-L255 | [
"def",
"rotatePoint",
"(",
"self",
",",
"pointX",
",",
"pointY",
")",
":",
"if",
"(",
"self",
".",
"angle",
"==",
"0",
"or",
"self",
".",
"angle",
"==",
"None",
")",
":",
"return",
"(",
"pointX",
",",
"pointY",
")",
"# 1. Compute the segment length",
"length",
"=",
"math",
".",
"sqrt",
"(",
"(",
"pointX",
"-",
"self",
".",
"xll",
")",
"**",
"2",
"+",
"(",
"pointY",
"-",
"self",
".",
"yll",
")",
"**",
"2",
")",
"# 2. Compute beta",
"beta",
"=",
"math",
".",
"acos",
"(",
"(",
"pointX",
"-",
"self",
".",
"xll",
")",
"/",
"length",
")",
"if",
"(",
"pointY",
"<",
"self",
".",
"yll",
")",
":",
"beta",
"=",
"math",
".",
"pi",
"*",
"2",
"-",
"beta",
"# 3. Compute offsets",
"offsetX",
"=",
"math",
".",
"cos",
"(",
"beta",
")",
"*",
"length",
"-",
"math",
".",
"cos",
"(",
"self",
".",
"_angle_rd",
"+",
"beta",
")",
"*",
"length",
"offsetY",
"=",
"math",
".",
"sin",
"(",
"self",
".",
"_angle_rd",
"+",
"beta",
")",
"*",
"length",
"-",
"math",
".",
"sin",
"(",
"beta",
")",
"*",
"length",
"return",
"(",
"pointX",
"-",
"offsetX",
",",
"pointY",
"+",
"offsetY",
")"
] | 34b47bd9da7c0106defbe1aa5645b52c999c0e1e |
test | PDFLite.set_information | Convenience function to add property info, can set any attribute and leave the others blank, it won't over-write
previously set items. | pypdflite/pdflite.py | def set_information(self, title=None, subject=None, author=None, keywords=None, creator=None):
""" Convenience function to add property info, can set any attribute and leave the others blank, it won't over-write
previously set items. """
info_dict = {"title": title, "subject": subject,
"author": author, "keywords": keywords,
"creator": creator}
for att, value in info_dict.iteritems():
if hasattr(self, att):
if value:
setattr(self, att, value)
else:
setattr(self, att, None) | def set_information(self, title=None, subject=None, author=None, keywords=None, creator=None):
""" Convenience function to add property info, can set any attribute and leave the others blank, it won't over-write
previously set items. """
info_dict = {"title": title, "subject": subject,
"author": author, "keywords": keywords,
"creator": creator}
for att, value in info_dict.iteritems():
if hasattr(self, att):
if value:
setattr(self, att, value)
else:
setattr(self, att, None) | [
"Convenience",
"function",
"to",
"add",
"property",
"info",
"can",
"set",
"any",
"attribute",
"and",
"leave",
"the",
"others",
"blank",
"it",
"won",
"t",
"over",
"-",
"write",
"previously",
"set",
"items",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L61-L73 | [
"def",
"set_information",
"(",
"self",
",",
"title",
"=",
"None",
",",
"subject",
"=",
"None",
",",
"author",
"=",
"None",
",",
"keywords",
"=",
"None",
",",
"creator",
"=",
"None",
")",
":",
"info_dict",
"=",
"{",
"\"title\"",
":",
"title",
",",
"\"subject\"",
":",
"subject",
",",
"\"author\"",
":",
"author",
",",
"\"keywords\"",
":",
"keywords",
",",
"\"creator\"",
":",
"creator",
"}",
"for",
"att",
",",
"value",
"in",
"info_dict",
".",
"iteritems",
"(",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"att",
")",
":",
"if",
"value",
":",
"setattr",
"(",
"self",
",",
"att",
",",
"value",
")",
"else",
":",
"setattr",
"(",
"self",
",",
"att",
",",
"None",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite.set_display_mode | Set the default viewing options. | pypdflite/pdflite.py | def set_display_mode(self, zoom='fullpage', layout='continuous'):
""" Set the default viewing options. """
self.zoom_options = ["fullpage", "fullwidth", "real", "default"]
self.layout_options = ["single", "continuous", "two", "default"]
if zoom in self.zoom_options or (isinstance(zoom, int) and 0 < zoom <= 100):
self.zoom_mode = zoom
else:
raise Exception('Incorrect zoom display mode: ' + zoom)
if layout in self.layout_options:
self.layout_mode = layout
else:
raise Exception('Incorrect layout display mode: ' + layout) | def set_display_mode(self, zoom='fullpage', layout='continuous'):
""" Set the default viewing options. """
self.zoom_options = ["fullpage", "fullwidth", "real", "default"]
self.layout_options = ["single", "continuous", "two", "default"]
if zoom in self.zoom_options or (isinstance(zoom, int) and 0 < zoom <= 100):
self.zoom_mode = zoom
else:
raise Exception('Incorrect zoom display mode: ' + zoom)
if layout in self.layout_options:
self.layout_mode = layout
else:
raise Exception('Incorrect layout display mode: ' + layout) | [
"Set",
"the",
"default",
"viewing",
"options",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L75-L88 | [
"def",
"set_display_mode",
"(",
"self",
",",
"zoom",
"=",
"'fullpage'",
",",
"layout",
"=",
"'continuous'",
")",
":",
"self",
".",
"zoom_options",
"=",
"[",
"\"fullpage\"",
",",
"\"fullwidth\"",
",",
"\"real\"",
",",
"\"default\"",
"]",
"self",
".",
"layout_options",
"=",
"[",
"\"single\"",
",",
"\"continuous\"",
",",
"\"two\"",
",",
"\"default\"",
"]",
"if",
"zoom",
"in",
"self",
".",
"zoom_options",
"or",
"(",
"isinstance",
"(",
"zoom",
",",
"int",
")",
"and",
"0",
"<",
"zoom",
"<=",
"100",
")",
":",
"self",
".",
"zoom_mode",
"=",
"zoom",
"else",
":",
"raise",
"Exception",
"(",
"'Incorrect zoom display mode: '",
"+",
"zoom",
")",
"if",
"layout",
"in",
"self",
".",
"layout_options",
":",
"self",
".",
"layout_mode",
"=",
"layout",
"else",
":",
"raise",
"Exception",
"(",
"'Incorrect layout display mode: '",
"+",
"layout",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite.close | Prompt the objects to output pdf code, and save to file. | pypdflite/pdflite.py | def close(self):
""" Prompt the objects to output pdf code, and save to file. """
self.document._set_page_numbers()
# Places header, pages, page content first.
self._put_header()
self._put_pages()
self._put_resources()
# Information object
self._put_information()
# Catalog object
self._put_catalog()
# Cross-reference object
#self._put_cross_reference()
# Trailer object
self._put_trailer()
if hasattr(self.destination, "write"):
output = self._output_to_io()
elif self.destination == 'string':
output = self._output_to_string()
else:
self._output_to_file()
output = None
return output | def close(self):
""" Prompt the objects to output pdf code, and save to file. """
self.document._set_page_numbers()
# Places header, pages, page content first.
self._put_header()
self._put_pages()
self._put_resources()
# Information object
self._put_information()
# Catalog object
self._put_catalog()
# Cross-reference object
#self._put_cross_reference()
# Trailer object
self._put_trailer()
if hasattr(self.destination, "write"):
output = self._output_to_io()
elif self.destination == 'string':
output = self._output_to_string()
else:
self._output_to_file()
output = None
return output | [
"Prompt",
"the",
"objects",
"to",
"output",
"pdf",
"code",
"and",
"save",
"to",
"file",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L90-L113 | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"document",
".",
"_set_page_numbers",
"(",
")",
"# Places header, pages, page content first.\r",
"self",
".",
"_put_header",
"(",
")",
"self",
".",
"_put_pages",
"(",
")",
"self",
".",
"_put_resources",
"(",
")",
"# Information object\r",
"self",
".",
"_put_information",
"(",
")",
"# Catalog object\r",
"self",
".",
"_put_catalog",
"(",
")",
"# Cross-reference object\r",
"#self._put_cross_reference()\r",
"# Trailer object\r",
"self",
".",
"_put_trailer",
"(",
")",
"if",
"hasattr",
"(",
"self",
".",
"destination",
",",
"\"write\"",
")",
":",
"output",
"=",
"self",
".",
"_output_to_io",
"(",
")",
"elif",
"self",
".",
"destination",
"==",
"'string'",
":",
"output",
"=",
"self",
".",
"_output_to_string",
"(",
")",
"else",
":",
"self",
".",
"_output_to_file",
"(",
")",
"output",
"=",
"None",
"return",
"output"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._put_header | Standard first line in a PDF. | pypdflite/pdflite.py | def _put_header(self):
""" Standard first line in a PDF. """
self.session._out('%%PDF-%s' % self.pdf_version)
if self.session.compression:
self.session.buffer += '%' + chr(235) + chr(236) + chr(237) + chr(238) + "\n" | def _put_header(self):
""" Standard first line in a PDF. """
self.session._out('%%PDF-%s' % self.pdf_version)
if self.session.compression:
self.session.buffer += '%' + chr(235) + chr(236) + chr(237) + chr(238) + "\n" | [
"Standard",
"first",
"line",
"in",
"a",
"PDF",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L116-L120 | [
"def",
"_put_header",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'%%PDF-%s'",
"%",
"self",
".",
"pdf_version",
")",
"if",
"self",
".",
"session",
".",
"compression",
":",
"self",
".",
"session",
".",
"buffer",
"+=",
"'%'",
"+",
"chr",
"(",
"235",
")",
"+",
"chr",
"(",
"236",
")",
"+",
"chr",
"(",
"237",
")",
"+",
"chr",
"(",
"238",
")",
"+",
"\"\\n\""
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._put_pages | First, the Document object does the heavy-lifting for the
individual page objects and content.
Then, the overall "Pages" object is generated. | pypdflite/pdflite.py | def _put_pages(self):
""" First, the Document object does the heavy-lifting for the
individual page objects and content.
Then, the overall "Pages" object is generated.
"""
self.document._get_orientation_changes()
self.document._output_pages()
# Pages Object, provides reference to page objects (Kids list).
self.session._add_object(1)
self.session._out('<</Type /Pages')
kids = '/Kids ['
for i in xrange(0, len(self.document.pages)):
kids += str(3 + 2 * i) + ' 0 R '
self.session._out(kids + ']')
self.session._out('/Count %s' % len(self.document.pages))
# Overall size of the default PDF page
self.session._out('/MediaBox [0 0 %.2f %.2f]' %
(self.document.page.width,
self.document.page.height))
self.session._out('>>')
self.session._out('endobj') | def _put_pages(self):
""" First, the Document object does the heavy-lifting for the
individual page objects and content.
Then, the overall "Pages" object is generated.
"""
self.document._get_orientation_changes()
self.document._output_pages()
# Pages Object, provides reference to page objects (Kids list).
self.session._add_object(1)
self.session._out('<</Type /Pages')
kids = '/Kids ['
for i in xrange(0, len(self.document.pages)):
kids += str(3 + 2 * i) + ' 0 R '
self.session._out(kids + ']')
self.session._out('/Count %s' % len(self.document.pages))
# Overall size of the default PDF page
self.session._out('/MediaBox [0 0 %.2f %.2f]' %
(self.document.page.width,
self.document.page.height))
self.session._out('>>')
self.session._out('endobj') | [
"First",
"the",
"Document",
"object",
"does",
"the",
"heavy",
"-",
"lifting",
"for",
"the",
"individual",
"page",
"objects",
"and",
"content",
".",
"Then",
"the",
"overall",
"Pages",
"object",
"is",
"generated",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L122-L146 | [
"def",
"_put_pages",
"(",
"self",
")",
":",
"self",
".",
"document",
".",
"_get_orientation_changes",
"(",
")",
"self",
".",
"document",
".",
"_output_pages",
"(",
")",
"# Pages Object, provides reference to page objects (Kids list).\r",
"self",
".",
"session",
".",
"_add_object",
"(",
"1",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'<</Type /Pages'",
")",
"kids",
"=",
"'/Kids ['",
"for",
"i",
"in",
"xrange",
"(",
"0",
",",
"len",
"(",
"self",
".",
"document",
".",
"pages",
")",
")",
":",
"kids",
"+=",
"str",
"(",
"3",
"+",
"2",
"*",
"i",
")",
"+",
"' 0 R '",
"self",
".",
"session",
".",
"_out",
"(",
"kids",
"+",
"']'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Count %s'",
"%",
"len",
"(",
"self",
".",
"document",
".",
"pages",
")",
")",
"# Overall size of the default PDF page\r",
"self",
".",
"session",
".",
"_out",
"(",
"'/MediaBox [0 0 %.2f %.2f]'",
"%",
"(",
"self",
".",
"document",
".",
"page",
".",
"width",
",",
"self",
".",
"document",
".",
"page",
".",
"height",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'>>'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'endobj'",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._put_resource_dict | Creates PDF reference to resource objects. | pypdflite/pdflite.py | def _put_resource_dict(self):
""" Creates PDF reference to resource objects.
"""
self.session._add_object(2)
self.session._out('<<')
self.session._out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]')
self.session._out('/Font <<')
for font in self.document.fonts:
self.session._out('/F%s %s 0 R' % (font.index, font.number))
self.session._out('>>')
if self.document.images:
self.session._out('/XObject <<')
for image in self.document.images:
self.session._out('/I%s %s 0 R' % (image.index, image.number))
self.session._out('>>')
self.session._out('>>')
self.session._out('endobj') | def _put_resource_dict(self):
""" Creates PDF reference to resource objects.
"""
self.session._add_object(2)
self.session._out('<<')
self.session._out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]')
self.session._out('/Font <<')
for font in self.document.fonts:
self.session._out('/F%s %s 0 R' % (font.index, font.number))
self.session._out('>>')
if self.document.images:
self.session._out('/XObject <<')
for image in self.document.images:
self.session._out('/I%s %s 0 R' % (image.index, image.number))
self.session._out('>>')
self.session._out('>>')
self.session._out('endobj') | [
"Creates",
"PDF",
"reference",
"to",
"resource",
"objects",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L171-L188 | [
"def",
"_put_resource_dict",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"_add_object",
"(",
"2",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'<<'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Font <<'",
")",
"for",
"font",
"in",
"self",
".",
"document",
".",
"fonts",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/F%s %s 0 R'",
"%",
"(",
"font",
".",
"index",
",",
"font",
".",
"number",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'>>'",
")",
"if",
"self",
".",
"document",
".",
"images",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/XObject <<'",
")",
"for",
"image",
"in",
"self",
".",
"document",
".",
"images",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/I%s %s 0 R'",
"%",
"(",
"image",
".",
"index",
",",
"image",
".",
"number",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'>>'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'>>'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'endobj'",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._put_information | PDF Information object. | pypdflite/pdflite.py | def _put_information(self):
"""PDF Information object."""
self.session._add_object()
self.session._out('<<')
self.session._out('/Producer ' + self._text_to_string(
'PDFLite, https://github.com/katerina7479'))
if self.title:
self.session._out('/Title ' + self._text_to_string(self.title))
if self.subject:
self.session._out('/Subject ' + self._text_to_string(self.subject))
if self.author:
self.session._out('/Author ' + self._text_to_string(self.author))
if self.keywords:
self.session._out('/Keywords ' +
self._text_to_string(self.keywords))
if self.creator:
self.session._out('/Creator ' + self._text_to_string(self.creator))
self.session._out('/CreationDate ' + self._text_to_string(
'D:' + datetime.now().strftime('%Y%m%d%H%M%S')))
self.session._out('>>')
self.session._out('endobj') | def _put_information(self):
"""PDF Information object."""
self.session._add_object()
self.session._out('<<')
self.session._out('/Producer ' + self._text_to_string(
'PDFLite, https://github.com/katerina7479'))
if self.title:
self.session._out('/Title ' + self._text_to_string(self.title))
if self.subject:
self.session._out('/Subject ' + self._text_to_string(self.subject))
if self.author:
self.session._out('/Author ' + self._text_to_string(self.author))
if self.keywords:
self.session._out('/Keywords ' +
self._text_to_string(self.keywords))
if self.creator:
self.session._out('/Creator ' + self._text_to_string(self.creator))
self.session._out('/CreationDate ' + self._text_to_string(
'D:' + datetime.now().strftime('%Y%m%d%H%M%S')))
self.session._out('>>')
self.session._out('endobj') | [
"PDF",
"Information",
"object",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L190-L210 | [
"def",
"_put_information",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"_add_object",
"(",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'<<'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Producer '",
"+",
"self",
".",
"_text_to_string",
"(",
"'PDFLite, https://github.com/katerina7479'",
")",
")",
"if",
"self",
".",
"title",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/Title '",
"+",
"self",
".",
"_text_to_string",
"(",
"self",
".",
"title",
")",
")",
"if",
"self",
".",
"subject",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/Subject '",
"+",
"self",
".",
"_text_to_string",
"(",
"self",
".",
"subject",
")",
")",
"if",
"self",
".",
"author",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/Author '",
"+",
"self",
".",
"_text_to_string",
"(",
"self",
".",
"author",
")",
")",
"if",
"self",
".",
"keywords",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/Keywords '",
"+",
"self",
".",
"_text_to_string",
"(",
"self",
".",
"keywords",
")",
")",
"if",
"self",
".",
"creator",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/Creator '",
"+",
"self",
".",
"_text_to_string",
"(",
"self",
".",
"creator",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/CreationDate '",
"+",
"self",
".",
"_text_to_string",
"(",
"'D:'",
"+",
"datetime",
".",
"now",
"(",
")",
".",
"strftime",
"(",
"'%Y%m%d%H%M%S'",
")",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'>>'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'endobj'",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._put_catalog | Catalog object. | pypdflite/pdflite.py | def _put_catalog(self):
"""Catalog object."""
self.session._add_object()
self.session._out('<<')
self.session._out('/Type /Catalog')
self.session._out('/Pages 1 0 R')
if self.zoom_mode == 'fullpage':
self.session._out('/OpenAction [3 0 R /Fit]')
elif self.zoom_mode == 'fullwidth':
self.session._out('/OpenAction [3 0 R /FitH null]')
elif self.zoom_mode == 'real':
self.session._out('/OpenAction [3 0 R /XYZ null null 1]')
elif not isinstance(self.zoom_mode, basestring):
self.session._out(
'/OpenAction [3 0 R /XYZ null null ' +
(self.zoom_mode / 100) + ']')
if self.layout_mode == 'single':
self.session._out('/PageLayout /SinglePage')
elif self.layout_mode == 'continuous':
self.session._out('/PageLayout /OneColumn')
elif self.layout_mode == 'two':
self.session._out('/PageLayout /TwoColumnLeft')
self.session._out('>>')
self.session._out('endobj') | def _put_catalog(self):
"""Catalog object."""
self.session._add_object()
self.session._out('<<')
self.session._out('/Type /Catalog')
self.session._out('/Pages 1 0 R')
if self.zoom_mode == 'fullpage':
self.session._out('/OpenAction [3 0 R /Fit]')
elif self.zoom_mode == 'fullwidth':
self.session._out('/OpenAction [3 0 R /FitH null]')
elif self.zoom_mode == 'real':
self.session._out('/OpenAction [3 0 R /XYZ null null 1]')
elif not isinstance(self.zoom_mode, basestring):
self.session._out(
'/OpenAction [3 0 R /XYZ null null ' +
(self.zoom_mode / 100) + ']')
if self.layout_mode == 'single':
self.session._out('/PageLayout /SinglePage')
elif self.layout_mode == 'continuous':
self.session._out('/PageLayout /OneColumn')
elif self.layout_mode == 'two':
self.session._out('/PageLayout /TwoColumnLeft')
self.session._out('>>')
self.session._out('endobj') | [
"Catalog",
"object",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L212-L237 | [
"def",
"_put_catalog",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"_add_object",
"(",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'<<'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Type /Catalog'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Pages 1 0 R'",
")",
"if",
"self",
".",
"zoom_mode",
"==",
"'fullpage'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/OpenAction [3 0 R /Fit]'",
")",
"elif",
"self",
".",
"zoom_mode",
"==",
"'fullwidth'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/OpenAction [3 0 R /FitH null]'",
")",
"elif",
"self",
".",
"zoom_mode",
"==",
"'real'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/OpenAction [3 0 R /XYZ null null 1]'",
")",
"elif",
"not",
"isinstance",
"(",
"self",
".",
"zoom_mode",
",",
"basestring",
")",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/OpenAction [3 0 R /XYZ null null '",
"+",
"(",
"self",
".",
"zoom_mode",
"/",
"100",
")",
"+",
"']'",
")",
"if",
"self",
".",
"layout_mode",
"==",
"'single'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/PageLayout /SinglePage'",
")",
"elif",
"self",
".",
"layout_mode",
"==",
"'continuous'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/PageLayout /OneColumn'",
")",
"elif",
"self",
".",
"layout_mode",
"==",
"'two'",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'/PageLayout /TwoColumnLeft'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'>>'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'endobj'",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._put_cross_reference | Cross Reference Object, calculates
the position in bytes to the start
(first number) of each object in
order by number (zero is special)
from the beginning of the file. | pypdflite/pdflite.py | def _put_cross_reference(self):
""" Cross Reference Object, calculates
the position in bytes to the start
(first number) of each object in
order by number (zero is special)
from the beginning of the file.
"""
self.session._out('xref')
self.session._out('0 %s' % len(self.session.objects))
self.session._out('0000000000 65535 f ')
for obj in self.session.objects:
if isinstance(obj, basestring):
pass
else:
self.session._out('%010d 00000 n ' % obj.offset) | def _put_cross_reference(self):
""" Cross Reference Object, calculates
the position in bytes to the start
(first number) of each object in
order by number (zero is special)
from the beginning of the file.
"""
self.session._out('xref')
self.session._out('0 %s' % len(self.session.objects))
self.session._out('0000000000 65535 f ')
for obj in self.session.objects:
if isinstance(obj, basestring):
pass
else:
self.session._out('%010d 00000 n ' % obj.offset) | [
"Cross",
"Reference",
"Object",
"calculates",
"the",
"position",
"in",
"bytes",
"to",
"the",
"start",
"(",
"first",
"number",
")",
"of",
"each",
"object",
"in",
"order",
"by",
"number",
"(",
"zero",
"is",
"special",
")",
"from",
"the",
"beginning",
"of",
"the",
"file",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L239-L254 | [
"def",
"_put_cross_reference",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'xref'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'0 %s'",
"%",
"len",
"(",
"self",
".",
"session",
".",
"objects",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'0000000000 65535 f '",
")",
"for",
"obj",
"in",
"self",
".",
"session",
".",
"objects",
":",
"if",
"isinstance",
"(",
"obj",
",",
"basestring",
")",
":",
"pass",
"else",
":",
"self",
".",
"session",
".",
"_out",
"(",
"'%010d 00000 n '",
"%",
"obj",
".",
"offset",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._put_trailer | Final Trailer calculations, and end-of-file
reference. | pypdflite/pdflite.py | def _put_trailer(self):
""" Final Trailer calculations, and end-of-file
reference.
"""
startxref = len(self.session.buffer)
self._put_cross_reference()
md5 = hashlib.md5()
md5.update(datetime.now().strftime('%Y%m%d%H%M%S'))
try:
md5.update(self.filepath)
except TypeError:
pass
if self.title:
md5.update(self.title)
if self.subject:
md5.update(self.subject)
if self.author:
md5.update(self.author)
if self.keywords:
md5.update(self.keywords)
if self.creator:
md5.update(self.creator)
objnum = len(self.session.objects)
self.session._out('trailer')
self.session._out('<<')
self.session._out('/Size %s' % objnum)
self.session._out('/Root %s 0 R' % (objnum - 1))
self.session._out('/Info %s 0 R' % (objnum - 2))
self.session._out('/ID [ <%s> <%s>]' % (md5.hexdigest(),md5.hexdigest()))
self.session._out('>>')
self.session._out('startxref')
self.session._out(startxref)
self.session._out('%%EOF') | def _put_trailer(self):
""" Final Trailer calculations, and end-of-file
reference.
"""
startxref = len(self.session.buffer)
self._put_cross_reference()
md5 = hashlib.md5()
md5.update(datetime.now().strftime('%Y%m%d%H%M%S'))
try:
md5.update(self.filepath)
except TypeError:
pass
if self.title:
md5.update(self.title)
if self.subject:
md5.update(self.subject)
if self.author:
md5.update(self.author)
if self.keywords:
md5.update(self.keywords)
if self.creator:
md5.update(self.creator)
objnum = len(self.session.objects)
self.session._out('trailer')
self.session._out('<<')
self.session._out('/Size %s' % objnum)
self.session._out('/Root %s 0 R' % (objnum - 1))
self.session._out('/Info %s 0 R' % (objnum - 2))
self.session._out('/ID [ <%s> <%s>]' % (md5.hexdigest(),md5.hexdigest()))
self.session._out('>>')
self.session._out('startxref')
self.session._out(startxref)
self.session._out('%%EOF') | [
"Final",
"Trailer",
"calculations",
"and",
"end",
"-",
"of",
"-",
"file",
"reference",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L256-L292 | [
"def",
"_put_trailer",
"(",
"self",
")",
":",
"startxref",
"=",
"len",
"(",
"self",
".",
"session",
".",
"buffer",
")",
"self",
".",
"_put_cross_reference",
"(",
")",
"md5",
"=",
"hashlib",
".",
"md5",
"(",
")",
"md5",
".",
"update",
"(",
"datetime",
".",
"now",
"(",
")",
".",
"strftime",
"(",
"'%Y%m%d%H%M%S'",
")",
")",
"try",
":",
"md5",
".",
"update",
"(",
"self",
".",
"filepath",
")",
"except",
"TypeError",
":",
"pass",
"if",
"self",
".",
"title",
":",
"md5",
".",
"update",
"(",
"self",
".",
"title",
")",
"if",
"self",
".",
"subject",
":",
"md5",
".",
"update",
"(",
"self",
".",
"subject",
")",
"if",
"self",
".",
"author",
":",
"md5",
".",
"update",
"(",
"self",
".",
"author",
")",
"if",
"self",
".",
"keywords",
":",
"md5",
".",
"update",
"(",
"self",
".",
"keywords",
")",
"if",
"self",
".",
"creator",
":",
"md5",
".",
"update",
"(",
"self",
".",
"creator",
")",
"objnum",
"=",
"len",
"(",
"self",
".",
"session",
".",
"objects",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'trailer'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'<<'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Size %s'",
"%",
"objnum",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Root %s 0 R'",
"%",
"(",
"objnum",
"-",
"1",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/Info %s 0 R'",
"%",
"(",
"objnum",
"-",
"2",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'/ID [ <%s> <%s>]'",
"%",
"(",
"md5",
".",
"hexdigest",
"(",
")",
",",
"md5",
".",
"hexdigest",
"(",
")",
")",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'>>'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'startxref'",
")",
"self",
".",
"session",
".",
"_out",
"(",
"startxref",
")",
"self",
".",
"session",
".",
"_out",
"(",
"'%%EOF'",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._output_to_file | Save to filepath specified on
init. (Will throw an error if
the document is already open). | pypdflite/pdflite.py | def _output_to_file(self):
""" Save to filepath specified on
init. (Will throw an error if
the document is already open).
"""
f = open(self.filepath, 'wb')
if not f:
raise Exception('Unable to create output file: ', self.filepath)
f.write(self.session.buffer)
f.close() | def _output_to_file(self):
""" Save to filepath specified on
init. (Will throw an error if
the document is already open).
"""
f = open(self.filepath, 'wb')
if not f:
raise Exception('Unable to create output file: ', self.filepath)
f.write(self.session.buffer)
f.close() | [
"Save",
"to",
"filepath",
"specified",
"on",
"init",
".",
"(",
"Will",
"throw",
"an",
"error",
"if",
"the",
"document",
"is",
"already",
"open",
")",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L294-L304 | [
"def",
"_output_to_file",
"(",
"self",
")",
":",
"f",
"=",
"open",
"(",
"self",
".",
"filepath",
",",
"'wb'",
")",
"if",
"not",
"f",
":",
"raise",
"Exception",
"(",
"'Unable to create output file: '",
",",
"self",
".",
"filepath",
")",
"f",
".",
"write",
"(",
"self",
".",
"session",
".",
"buffer",
")",
"f",
".",
"close",
"(",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFLite._text_to_string | Provides for escape characters and converting to
pdf text object (pdf strings are in parantheses).
Mainly for use in the information block here, this
functionality is also present in the text object. | pypdflite/pdflite.py | def _text_to_string(self, text):
""" Provides for escape characters and converting to
pdf text object (pdf strings are in parantheses).
Mainly for use in the information block here, this
functionality is also present in the text object.
"""
if text:
for i,j in [("\\","\\\\"),(")","\\)"),("(", "\\(")]:
text = text.replace(i, j)
text = "(%s)" % text
else:
text = 'None'
return text | def _text_to_string(self, text):
""" Provides for escape characters and converting to
pdf text object (pdf strings are in parantheses).
Mainly for use in the information block here, this
functionality is also present in the text object.
"""
if text:
for i,j in [("\\","\\\\"),(")","\\)"),("(", "\\(")]:
text = text.replace(i, j)
text = "(%s)" % text
else:
text = 'None'
return text | [
"Provides",
"for",
"escape",
"characters",
"and",
"converting",
"to",
"pdf",
"text",
"object",
"(",
"pdf",
"strings",
"are",
"in",
"parantheses",
")",
".",
"Mainly",
"for",
"use",
"in",
"the",
"information",
"block",
"here",
"this",
"functionality",
"is",
"also",
"present",
"in",
"the",
"text",
"object",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdflite.py#L313-L326 | [
"def",
"_text_to_string",
"(",
"self",
",",
"text",
")",
":",
"if",
"text",
":",
"for",
"i",
",",
"j",
"in",
"[",
"(",
"\"\\\\\"",
",",
"\"\\\\\\\\\"",
")",
",",
"(",
"\")\"",
",",
"\"\\\\)\"",
")",
",",
"(",
"\"(\"",
",",
"\"\\\\(\"",
")",
"]",
":",
"text",
"=",
"text",
".",
"replace",
"(",
"i",
",",
"j",
")",
"text",
"=",
"\"(%s)\"",
"%",
"text",
"else",
":",
"text",
"=",
"'None'",
"return",
"text"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | floyd | Floyd's Cycle Detector.
See help(cycle_detector) for more context.
Args:
*args: Two iterators issueing the exact same sequence:
-or-
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found; if called with f and `start`,
the parametres `first` and `period` will be defined indicating
the offset of start of the cycle and the cycle's period. | cycle_detector.py | def floyd(seqs, f=None, start=None, key=lambda x: x):
"""Floyd's Cycle Detector.
See help(cycle_detector) for more context.
Args:
*args: Two iterators issueing the exact same sequence:
-or-
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found; if called with f and `start`,
the parametres `first` and `period` will be defined indicating
the offset of start of the cycle and the cycle's period.
"""
tortise, hare = seqs
yield hare.next()
tortise_value = tortise.next()
hare_value = hare.next()
while hare_value != tortise_value:
yield hare_value
yield hare.next()
hare_value = hare.next()
tortise_value = tortise.next()
if f is None:
raise CycleDetected()
hare_value = f(hare_value)
first = 0
tortise_value = start
while key(tortise_value) != key(hare_value):
tortise_value = f(tortise_value)
hare_value = f(hare_value)
first += 1
period = 1
hare_value = f(tortise_value)
while key(tortise_value) != key(hare_value):
hare_value = f(hare_value)
period += 1
raise CycleDetected(period=period, first=first) | def floyd(seqs, f=None, start=None, key=lambda x: x):
"""Floyd's Cycle Detector.
See help(cycle_detector) for more context.
Args:
*args: Two iterators issueing the exact same sequence:
-or-
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found; if called with f and `start`,
the parametres `first` and `period` will be defined indicating
the offset of start of the cycle and the cycle's period.
"""
tortise, hare = seqs
yield hare.next()
tortise_value = tortise.next()
hare_value = hare.next()
while hare_value != tortise_value:
yield hare_value
yield hare.next()
hare_value = hare.next()
tortise_value = tortise.next()
if f is None:
raise CycleDetected()
hare_value = f(hare_value)
first = 0
tortise_value = start
while key(tortise_value) != key(hare_value):
tortise_value = f(tortise_value)
hare_value = f(hare_value)
first += 1
period = 1
hare_value = f(tortise_value)
while key(tortise_value) != key(hare_value):
hare_value = f(hare_value)
period += 1
raise CycleDetected(period=period, first=first) | [
"Floyd",
"s",
"Cycle",
"Detector",
"."
] | pelotoncycle/cycle_detector | python | https://github.com/pelotoncycle/cycle_detector/blob/a7c1a2e321e232de10f5862f6042471a3c60beb9/cycle_detector.py#L130-L181 | [
"def",
"floyd",
"(",
"seqs",
",",
"f",
"=",
"None",
",",
"start",
"=",
"None",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
")",
":",
"tortise",
",",
"hare",
"=",
"seqs",
"yield",
"hare",
".",
"next",
"(",
")",
"tortise_value",
"=",
"tortise",
".",
"next",
"(",
")",
"hare_value",
"=",
"hare",
".",
"next",
"(",
")",
"while",
"hare_value",
"!=",
"tortise_value",
":",
"yield",
"hare_value",
"yield",
"hare",
".",
"next",
"(",
")",
"hare_value",
"=",
"hare",
".",
"next",
"(",
")",
"tortise_value",
"=",
"tortise",
".",
"next",
"(",
")",
"if",
"f",
"is",
"None",
":",
"raise",
"CycleDetected",
"(",
")",
"hare_value",
"=",
"f",
"(",
"hare_value",
")",
"first",
"=",
"0",
"tortise_value",
"=",
"start",
"while",
"key",
"(",
"tortise_value",
")",
"!=",
"key",
"(",
"hare_value",
")",
":",
"tortise_value",
"=",
"f",
"(",
"tortise_value",
")",
"hare_value",
"=",
"f",
"(",
"hare_value",
")",
"first",
"+=",
"1",
"period",
"=",
"1",
"hare_value",
"=",
"f",
"(",
"tortise_value",
")",
"while",
"key",
"(",
"tortise_value",
")",
"!=",
"key",
"(",
"hare_value",
")",
":",
"hare_value",
"=",
"f",
"(",
"hare_value",
")",
"period",
"+=",
"1",
"raise",
"CycleDetected",
"(",
"period",
"=",
"period",
",",
"first",
"=",
"first",
")"
] | a7c1a2e321e232de10f5862f6042471a3c60beb9 |
test | naive | Naive cycle detector
See help(cycle_detector) for more context.
Args:
sequence: A sequence to detect cyles in.
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found. Will always generate a first
and period value no matter which of the `seqs` or `f` interface
is used. | cycle_detector.py | def naive(seqs, f=None, start=None, key=lambda x: x):
"""Naive cycle detector
See help(cycle_detector) for more context.
Args:
sequence: A sequence to detect cyles in.
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found. Will always generate a first
and period value no matter which of the `seqs` or `f` interface
is used.
"""
history = {}
for step, value in enumerate(seqs[0]):
keyed = key(value)
yield value
if keyed in history:
raise CycleDetected(
first=history[keyed], period=step - history[keyed])
history[keyed] = step | def naive(seqs, f=None, start=None, key=lambda x: x):
"""Naive cycle detector
See help(cycle_detector) for more context.
Args:
sequence: A sequence to detect cyles in.
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found. Will always generate a first
and period value no matter which of the `seqs` or `f` interface
is used.
"""
history = {}
for step, value in enumerate(seqs[0]):
keyed = key(value)
yield value
if keyed in history:
raise CycleDetected(
first=history[keyed], period=step - history[keyed])
history[keyed] = step | [
"Naive",
"cycle",
"detector"
] | pelotoncycle/cycle_detector | python | https://github.com/pelotoncycle/cycle_detector/blob/a7c1a2e321e232de10f5862f6042471a3c60beb9/cycle_detector.py#L185-L214 | [
"def",
"naive",
"(",
"seqs",
",",
"f",
"=",
"None",
",",
"start",
"=",
"None",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
")",
":",
"history",
"=",
"{",
"}",
"for",
"step",
",",
"value",
"in",
"enumerate",
"(",
"seqs",
"[",
"0",
"]",
")",
":",
"keyed",
"=",
"key",
"(",
"value",
")",
"yield",
"value",
"if",
"keyed",
"in",
"history",
":",
"raise",
"CycleDetected",
"(",
"first",
"=",
"history",
"[",
"keyed",
"]",
",",
"period",
"=",
"step",
"-",
"history",
"[",
"keyed",
"]",
")",
"history",
"[",
"keyed",
"]",
"=",
"step"
] | a7c1a2e321e232de10f5862f6042471a3c60beb9 |
test | gosper | Gosper's cycle detector
See help(cycle_detector) for more context.
Args:
sequence: A sequence to detect cyles in.
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found. Unlike Floyd and Brent's,
Gosper's can only detect period of a cycle. It cannot
compute the first position | cycle_detector.py | def gosper(seqs, f=None, start=None, key=lambda x: x):
"""Gosper's cycle detector
See help(cycle_detector) for more context.
Args:
sequence: A sequence to detect cyles in.
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found. Unlike Floyd and Brent's,
Gosper's can only detect period of a cycle. It cannot
compute the first position
"""
tab = []
for c, value in enumerate(seqs[0], start=1):
yield value
try:
e = tab.index(key(value))
raise CycleDetected(
period=c - ((((c >> e) - 1) | 1) << e))
except ValueError:
try:
tab[(c ^ (c - 1)).bit_length() - 1] = key(value)
except IndexError:
tab.append(value) | def gosper(seqs, f=None, start=None, key=lambda x: x):
"""Gosper's cycle detector
See help(cycle_detector) for more context.
Args:
sequence: A sequence to detect cyles in.
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found. Unlike Floyd and Brent's,
Gosper's can only detect period of a cycle. It cannot
compute the first position
"""
tab = []
for c, value in enumerate(seqs[0], start=1):
yield value
try:
e = tab.index(key(value))
raise CycleDetected(
period=c - ((((c >> e) - 1) | 1) << e))
except ValueError:
try:
tab[(c ^ (c - 1)).bit_length() - 1] = key(value)
except IndexError:
tab.append(value) | [
"Gosper",
"s",
"cycle",
"detector"
] | pelotoncycle/cycle_detector | python | https://github.com/pelotoncycle/cycle_detector/blob/a7c1a2e321e232de10f5862f6042471a3c60beb9/cycle_detector.py#L218-L252 | [
"def",
"gosper",
"(",
"seqs",
",",
"f",
"=",
"None",
",",
"start",
"=",
"None",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
")",
":",
"tab",
"=",
"[",
"]",
"for",
"c",
",",
"value",
"in",
"enumerate",
"(",
"seqs",
"[",
"0",
"]",
",",
"start",
"=",
"1",
")",
":",
"yield",
"value",
"try",
":",
"e",
"=",
"tab",
".",
"index",
"(",
"key",
"(",
"value",
")",
")",
"raise",
"CycleDetected",
"(",
"period",
"=",
"c",
"-",
"(",
"(",
"(",
"(",
"c",
">>",
"e",
")",
"-",
"1",
")",
"|",
"1",
")",
"<<",
"e",
")",
")",
"except",
"ValueError",
":",
"try",
":",
"tab",
"[",
"(",
"c",
"^",
"(",
"c",
"-",
"1",
")",
")",
".",
"bit_length",
"(",
")",
"-",
"1",
"]",
"=",
"key",
"(",
"value",
")",
"except",
"IndexError",
":",
"tab",
".",
"append",
"(",
"value",
")"
] | a7c1a2e321e232de10f5862f6042471a3c60beb9 |
test | brent | Brent's Cycle Detector.
See help(cycle_detector) for more context.
Args:
*args: Two iterators issueing the exact same sequence:
-or-
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found; if called with f and `start`,
the parametres `first` and `period` will be defined indicating
the offset of start of the cycle and the cycle's period. | cycle_detector.py | def brent(seqs, f=None, start=None, key=lambda x: x):
"""Brent's Cycle Detector.
See help(cycle_detector) for more context.
Args:
*args: Two iterators issueing the exact same sequence:
-or-
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found; if called with f and `start`,
the parametres `first` and `period` will be defined indicating
the offset of start of the cycle and the cycle's period.
"""
power = period = 1
tortise, hare = seqs
yield hare.next()
tortise_value = tortise.next()
hare_value = hare.next()
while key(tortise_value) != key(hare_value):
yield hare_value
if power == period:
power *= 2
period = 0
if f:
tortise = f_generator(f, hare_value)
tortise_value = tortise.next()
else:
while tortise_value != hare_value:
tortise_value = tortise.next()
hare_value = hare.next()
period += 1
if f is None:
raise CycleDetected()
first = 0
tortise_value = hare_value = start
for _ in xrange(period):
hare_value = f(hare_value)
while key(tortise_value) != key(hare_value):
tortise_value = f(tortise_value)
hare_value = f(hare_value)
first += 1
raise CycleDetected(period=period, first=first) | def brent(seqs, f=None, start=None, key=lambda x: x):
"""Brent's Cycle Detector.
See help(cycle_detector) for more context.
Args:
*args: Two iterators issueing the exact same sequence:
-or-
f, start: Function and starting state for finite state machine
Yields:
Values yielded by sequence_a if it terminates, undefined if a
cycle is found.
Raises:
CycleFound if exception is found; if called with f and `start`,
the parametres `first` and `period` will be defined indicating
the offset of start of the cycle and the cycle's period.
"""
power = period = 1
tortise, hare = seqs
yield hare.next()
tortise_value = tortise.next()
hare_value = hare.next()
while key(tortise_value) != key(hare_value):
yield hare_value
if power == period:
power *= 2
period = 0
if f:
tortise = f_generator(f, hare_value)
tortise_value = tortise.next()
else:
while tortise_value != hare_value:
tortise_value = tortise.next()
hare_value = hare.next()
period += 1
if f is None:
raise CycleDetected()
first = 0
tortise_value = hare_value = start
for _ in xrange(period):
hare_value = f(hare_value)
while key(tortise_value) != key(hare_value):
tortise_value = f(tortise_value)
hare_value = f(hare_value)
first += 1
raise CycleDetected(period=period, first=first) | [
"Brent",
"s",
"Cycle",
"Detector",
"."
] | pelotoncycle/cycle_detector | python | https://github.com/pelotoncycle/cycle_detector/blob/a7c1a2e321e232de10f5862f6042471a3c60beb9/cycle_detector.py#L256-L311 | [
"def",
"brent",
"(",
"seqs",
",",
"f",
"=",
"None",
",",
"start",
"=",
"None",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
")",
":",
"power",
"=",
"period",
"=",
"1",
"tortise",
",",
"hare",
"=",
"seqs",
"yield",
"hare",
".",
"next",
"(",
")",
"tortise_value",
"=",
"tortise",
".",
"next",
"(",
")",
"hare_value",
"=",
"hare",
".",
"next",
"(",
")",
"while",
"key",
"(",
"tortise_value",
")",
"!=",
"key",
"(",
"hare_value",
")",
":",
"yield",
"hare_value",
"if",
"power",
"==",
"period",
":",
"power",
"*=",
"2",
"period",
"=",
"0",
"if",
"f",
":",
"tortise",
"=",
"f_generator",
"(",
"f",
",",
"hare_value",
")",
"tortise_value",
"=",
"tortise",
".",
"next",
"(",
")",
"else",
":",
"while",
"tortise_value",
"!=",
"hare_value",
":",
"tortise_value",
"=",
"tortise",
".",
"next",
"(",
")",
"hare_value",
"=",
"hare",
".",
"next",
"(",
")",
"period",
"+=",
"1",
"if",
"f",
"is",
"None",
":",
"raise",
"CycleDetected",
"(",
")",
"first",
"=",
"0",
"tortise_value",
"=",
"hare_value",
"=",
"start",
"for",
"_",
"in",
"xrange",
"(",
"period",
")",
":",
"hare_value",
"=",
"f",
"(",
"hare_value",
")",
"while",
"key",
"(",
"tortise_value",
")",
"!=",
"key",
"(",
"hare_value",
")",
":",
"tortise_value",
"=",
"f",
"(",
"tortise_value",
")",
"hare_value",
"=",
"f",
"(",
"hare_value",
")",
"first",
"+=",
"1",
"raise",
"CycleDetected",
"(",
"period",
"=",
"period",
",",
"first",
"=",
"first",
")"
] | a7c1a2e321e232de10f5862f6042471a3c60beb9 |
test | PDFCursor.x_fit | Test to see if the line can has enough space for the given length. | pypdflite/pdfobjects/pdfcursor.py | def x_fit(self, test_length):
""" Test to see if the line can has enough space for the given length. """
if (self.x + test_length) >= self.xmax:
return False
else:
return True | def x_fit(self, test_length):
""" Test to see if the line can has enough space for the given length. """
if (self.x + test_length) >= self.xmax:
return False
else:
return True | [
"Test",
"to",
"see",
"if",
"the",
"line",
"can",
"has",
"enough",
"space",
"for",
"the",
"given",
"length",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfcursor.py#L79-L84 | [
"def",
"x_fit",
"(",
"self",
",",
"test_length",
")",
":",
"if",
"(",
"self",
".",
"x",
"+",
"test_length",
")",
">=",
"self",
".",
"xmax",
":",
"return",
"False",
"else",
":",
"return",
"True"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFCursor.y_fit | Test to see if the page has enough space for the given text height. | pypdflite/pdfobjects/pdfcursor.py | def y_fit(self, test_length):
""" Test to see if the page has enough space for the given text height. """
if (self.y + test_length) >= self.ymax:
return False
else:
return True | def y_fit(self, test_length):
""" Test to see if the page has enough space for the given text height. """
if (self.y + test_length) >= self.ymax:
return False
else:
return True | [
"Test",
"to",
"see",
"if",
"the",
"page",
"has",
"enough",
"space",
"for",
"the",
"given",
"text",
"height",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfcursor.py#L86-L91 | [
"def",
"y_fit",
"(",
"self",
",",
"test_length",
")",
":",
"if",
"(",
"self",
".",
"y",
"+",
"test_length",
")",
">=",
"self",
".",
"ymax",
":",
"return",
"False",
"else",
":",
"return",
"True"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFCursor.x_is_greater_than | Comparison for x coordinate | pypdflite/pdfobjects/pdfcursor.py | def x_is_greater_than(self, test_ordinate):
""" Comparison for x coordinate"""
self._is_coordinate(test_ordinate)
if self.x > test_ordinate.x:
return True
else:
return False | def x_is_greater_than(self, test_ordinate):
""" Comparison for x coordinate"""
self._is_coordinate(test_ordinate)
if self.x > test_ordinate.x:
return True
else:
return False | [
"Comparison",
"for",
"x",
"coordinate"
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfcursor.py#L112-L118 | [
"def",
"x_is_greater_than",
"(",
"self",
",",
"test_ordinate",
")",
":",
"self",
".",
"_is_coordinate",
"(",
"test_ordinate",
")",
"if",
"self",
".",
"x",
">",
"test_ordinate",
".",
"x",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFCursor.y_is_greater_than | Comparison for y coordinate | pypdflite/pdfobjects/pdfcursor.py | def y_is_greater_than(self, test_ordinate):
"""Comparison for y coordinate"""
self._is_coordinate(test_ordinate)
if self.y > test_ordinate.y:
return True
else:
return False | def y_is_greater_than(self, test_ordinate):
"""Comparison for y coordinate"""
self._is_coordinate(test_ordinate)
if self.y > test_ordinate.y:
return True
else:
return False | [
"Comparison",
"for",
"y",
"coordinate"
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfcursor.py#L120-L126 | [
"def",
"y_is_greater_than",
"(",
"self",
",",
"test_ordinate",
")",
":",
"self",
".",
"_is_coordinate",
"(",
"test_ordinate",
")",
"if",
"self",
".",
"y",
">",
"test_ordinate",
".",
"y",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFCursor.copy | Create a copy, and return it. | pypdflite/pdfobjects/pdfcursor.py | def copy(self):
""" Create a copy, and return it."""
new_cursor = self.__class__(self.x, self.y)
new_cursor.set_bounds(self.xmin, self.ymin, self.xmax, self.ymax, self.ymaxmax)
new_cursor.set_deltas(self.dx, self.dy)
return new_cursor | def copy(self):
""" Create a copy, and return it."""
new_cursor = self.__class__(self.x, self.y)
new_cursor.set_bounds(self.xmin, self.ymin, self.xmax, self.ymax, self.ymaxmax)
new_cursor.set_deltas(self.dx, self.dy)
return new_cursor | [
"Create",
"a",
"copy",
"and",
"return",
"it",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfcursor.py#L160-L165 | [
"def",
"copy",
"(",
"self",
")",
":",
"new_cursor",
"=",
"self",
".",
"__class__",
"(",
"self",
".",
"x",
",",
"self",
".",
"y",
")",
"new_cursor",
".",
"set_bounds",
"(",
"self",
".",
"xmin",
",",
"self",
".",
"ymin",
",",
"self",
".",
"xmax",
",",
"self",
".",
"ymax",
",",
"self",
".",
"ymaxmax",
")",
"new_cursor",
".",
"set_deltas",
"(",
"self",
".",
"dx",
",",
"self",
".",
"dy",
")",
"return",
"new_cursor"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFCursor.x_plus | Mutable x addition. Defaults to set delta value. | pypdflite/pdfobjects/pdfcursor.py | def x_plus(self, dx=None):
""" Mutable x addition. Defaults to set delta value. """
if dx is None:
self.x += self.dx
else:
self.x = self.x + dx | def x_plus(self, dx=None):
""" Mutable x addition. Defaults to set delta value. """
if dx is None:
self.x += self.dx
else:
self.x = self.x + dx | [
"Mutable",
"x",
"addition",
".",
"Defaults",
"to",
"set",
"delta",
"value",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfcursor.py#L193-L198 | [
"def",
"x_plus",
"(",
"self",
",",
"dx",
"=",
"None",
")",
":",
"if",
"dx",
"is",
"None",
":",
"self",
".",
"x",
"+=",
"self",
".",
"dx",
"else",
":",
"self",
".",
"x",
"=",
"self",
".",
"x",
"+",
"dx"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFCursor.y_plus | Mutable y addition. Defaults to set delta value. | pypdflite/pdfobjects/pdfcursor.py | def y_plus(self, dy=None):
""" Mutable y addition. Defaults to set delta value. """
if dy is None:
self.y += self.dy
else:
self.y = self.y + dy | def y_plus(self, dy=None):
""" Mutable y addition. Defaults to set delta value. """
if dy is None:
self.y += self.dy
else:
self.y = self.y + dy | [
"Mutable",
"y",
"addition",
".",
"Defaults",
"to",
"set",
"delta",
"value",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfcursor.py#L200-L205 | [
"def",
"y_plus",
"(",
"self",
",",
"dy",
"=",
"None",
")",
":",
"if",
"dy",
"is",
"None",
":",
"self",
".",
"y",
"+=",
"self",
".",
"dy",
"else",
":",
"self",
".",
"y",
"=",
"self",
".",
"y",
"+",
"dy"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFPage.set_page_size | Valid choices: 'a3, 'a4', 'a5', 'letter', 'legal', '11x17'. | pypdflite/pdfobjects/pdfpage.py | def set_page_size(self, layout):
""" Valid choices: 'a3, 'a4', 'a5', 'letter', 'legal', '11x17'.
"""
self.layout = layout.lower()
if self.layout in self.layout_dict:
self.page_size = self.layout_dict[self.layout]
else:
dimensions = self.layout.split('x')
if len(dimensions) == 2:
self.page_size = (float(dimensions[0]) * 72, float(dimensions[1]) * 72)
else:
raise IndexError("Page is two dimensions, given: %s" % len(dimensions)) | def set_page_size(self, layout):
""" Valid choices: 'a3, 'a4', 'a5', 'letter', 'legal', '11x17'.
"""
self.layout = layout.lower()
if self.layout in self.layout_dict:
self.page_size = self.layout_dict[self.layout]
else:
dimensions = self.layout.split('x')
if len(dimensions) == 2:
self.page_size = (float(dimensions[0]) * 72, float(dimensions[1]) * 72)
else:
raise IndexError("Page is two dimensions, given: %s" % len(dimensions)) | [
"Valid",
"choices",
":",
"a3",
"a4",
"a5",
"letter",
"legal",
"11x17",
"."
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdfpage.py#L54-L66 | [
"def",
"set_page_size",
"(",
"self",
",",
"layout",
")",
":",
"self",
".",
"layout",
"=",
"layout",
".",
"lower",
"(",
")",
"if",
"self",
".",
"layout",
"in",
"self",
".",
"layout_dict",
":",
"self",
".",
"page_size",
"=",
"self",
".",
"layout_dict",
"[",
"self",
".",
"layout",
"]",
"else",
":",
"dimensions",
"=",
"self",
".",
"layout",
".",
"split",
"(",
"'x'",
")",
"if",
"len",
"(",
"dimensions",
")",
"==",
"2",
":",
"self",
".",
"page_size",
"=",
"(",
"float",
"(",
"dimensions",
"[",
"0",
"]",
")",
"*",
"72",
",",
"float",
"(",
"dimensions",
"[",
"1",
"]",
")",
"*",
"72",
")",
"else",
":",
"raise",
"IndexError",
"(",
"\"Page is two dimensions, given: %s\"",
"%",
"len",
"(",
"dimensions",
")",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | PDFTable._draw | Don't use this, use document.draw_table | pypdflite/pdfobjects/pdftable.py | def _draw(self):
""" Don't use this, use document.draw_table """
self._compile()
self.rows[0]._advance_first_row()
self._set_borders()
self._draw_fill()
self._draw_borders()
self._draw_text()
self._set_final_cursor() | def _draw(self):
""" Don't use this, use document.draw_table """
self._compile()
self.rows[0]._advance_first_row()
self._set_borders()
self._draw_fill()
self._draw_borders()
self._draw_text()
self._set_final_cursor() | [
"Don",
"t",
"use",
"this",
"use",
"document",
".",
"draw_table"
] | katerina7479/pypdflite | python | https://github.com/katerina7479/pypdflite/blob/ac2501f30d6619eae9dea5644717575ca9263d0a/pypdflite/pdfobjects/pdftable.py#L72-L80 | [
"def",
"_draw",
"(",
"self",
")",
":",
"self",
".",
"_compile",
"(",
")",
"self",
".",
"rows",
"[",
"0",
"]",
".",
"_advance_first_row",
"(",
")",
"self",
".",
"_set_borders",
"(",
")",
"self",
".",
"_draw_fill",
"(",
")",
"self",
".",
"_draw_borders",
"(",
")",
"self",
".",
"_draw_text",
"(",
")",
"self",
".",
"_set_final_cursor",
"(",
")"
] | ac2501f30d6619eae9dea5644717575ca9263d0a |
test | Labels.create | Creates a new label and returns the response
:param name: The label name
:type name: str
:param description: An optional description for the label. The name is
used if no description is provided.
:type description: str
:param color: The hex color for the label (ex: 'ff0000' for red). If no
color is provided, a random one will be assigned.
:type color: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def create(self, name, description=None, color=None):
"""
Creates a new label and returns the response
:param name: The label name
:type name: str
:param description: An optional description for the label. The name is
used if no description is provided.
:type description: str
:param color: The hex color for the label (ex: 'ff0000' for red). If no
color is provided, a random one will be assigned.
:type color: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
data = {
'name': name,
'title': name,
'description': description or name,
'appearance': {
'color': color or random_color()
}
}
# Yes, it's confusing. the `/tags/` endpoint is used for labels
return self._post(
request=ApiActions.CREATE.value,
uri=ApiUri.TAGS.value,
params=data
) | def create(self, name, description=None, color=None):
"""
Creates a new label and returns the response
:param name: The label name
:type name: str
:param description: An optional description for the label. The name is
used if no description is provided.
:type description: str
:param color: The hex color for the label (ex: 'ff0000' for red). If no
color is provided, a random one will be assigned.
:type color: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
data = {
'name': name,
'title': name,
'description': description or name,
'appearance': {
'color': color or random_color()
}
}
# Yes, it's confusing. the `/tags/` endpoint is used for labels
return self._post(
request=ApiActions.CREATE.value,
uri=ApiUri.TAGS.value,
params=data
) | [
"Creates",
"a",
"new",
"label",
"and",
"returns",
"the",
"response"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L75-L110 | [
"def",
"create",
"(",
"self",
",",
"name",
",",
"description",
"=",
"None",
",",
"color",
"=",
"None",
")",
":",
"data",
"=",
"{",
"'name'",
":",
"name",
",",
"'title'",
":",
"name",
",",
"'description'",
":",
"description",
"or",
"name",
",",
"'appearance'",
":",
"{",
"'color'",
":",
"color",
"or",
"random_color",
"(",
")",
"}",
"}",
"# Yes, it's confusing. the `/tags/` endpoint is used for labels",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"CREATE",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"TAGS",
".",
"value",
",",
"params",
"=",
"data",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Labels.list | Get all current labels
:return: The Logentries API response
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def list(self):
"""
Get all current labels
:return: The Logentries API response
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
return self._post(
request='list',
uri=ApiUri.TAGS.value,
).get('tags') | def list(self):
"""
Get all current labels
:return: The Logentries API response
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
return self._post(
request='list',
uri=ApiUri.TAGS.value,
).get('tags') | [
"Get",
"all",
"current",
"labels"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L112-L126 | [
"def",
"list",
"(",
"self",
")",
":",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"'list'",
",",
"uri",
"=",
"ApiUri",
".",
"TAGS",
".",
"value",
",",
")",
".",
"get",
"(",
"'tags'",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Labels.get | Get labels by name
:param name: The label name, it must be an exact match.
:type name: str
:return: A list of matching labels. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def get(self, name):
"""
Get labels by name
:param name: The label name, it must be an exact match.
:type name: str
:return: A list of matching labels. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
labels = self.list()
return [
label
for label
in labels
if name == label.get('name')
] | def get(self, name):
"""
Get labels by name
:param name: The label name, it must be an exact match.
:type name: str
:return: A list of matching labels. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
labels = self.list()
return [
label
for label
in labels
if name == label.get('name')
] | [
"Get",
"labels",
"by",
"name"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L128-L149 | [
"def",
"get",
"(",
"self",
",",
"name",
")",
":",
"labels",
"=",
"self",
".",
"list",
"(",
")",
"return",
"[",
"label",
"for",
"label",
"in",
"labels",
"if",
"name",
"==",
"label",
".",
"get",
"(",
"'name'",
")",
"]"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Labels.update | Update a Label
:param label: The data to update. Must include keys:
* id (str)
* appearance (dict)
* description (str)
* name (str)
* title (str)
:type label: dict
Example:
.. code-block:: python
Labels().update(
label={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'appearance': {'color': '278abe'},
'name': 'My Sandbox',
'description': 'My Sandbox',
'title': 'My Sandbox',
}
)
:return:
:rtype: dict | logentries_api/resources.py | def update(self, label):
"""
Update a Label
:param label: The data to update. Must include keys:
* id (str)
* appearance (dict)
* description (str)
* name (str)
* title (str)
:type label: dict
Example:
.. code-block:: python
Labels().update(
label={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'appearance': {'color': '278abe'},
'name': 'My Sandbox',
'description': 'My Sandbox',
'title': 'My Sandbox',
}
)
:return:
:rtype: dict
"""
data = {
'id': label['id'],
'name': label['name'],
'appearance': label['appearance'],
'description': label['description'],
'title': label['title'],
}
return self._post(
request=ApiActions.UPDATE.value,
uri=ApiUri.TAGS.value,
params=data
) | def update(self, label):
"""
Update a Label
:param label: The data to update. Must include keys:
* id (str)
* appearance (dict)
* description (str)
* name (str)
* title (str)
:type label: dict
Example:
.. code-block:: python
Labels().update(
label={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'appearance': {'color': '278abe'},
'name': 'My Sandbox',
'description': 'My Sandbox',
'title': 'My Sandbox',
}
)
:return:
:rtype: dict
"""
data = {
'id': label['id'],
'name': label['name'],
'appearance': label['appearance'],
'description': label['description'],
'title': label['title'],
}
return self._post(
request=ApiActions.UPDATE.value,
uri=ApiUri.TAGS.value,
params=data
) | [
"Update",
"a",
"Label"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L151-L192 | [
"def",
"update",
"(",
"self",
",",
"label",
")",
":",
"data",
"=",
"{",
"'id'",
":",
"label",
"[",
"'id'",
"]",
",",
"'name'",
":",
"label",
"[",
"'name'",
"]",
",",
"'appearance'",
":",
"label",
"[",
"'appearance'",
"]",
",",
"'description'",
":",
"label",
"[",
"'description'",
"]",
",",
"'title'",
":",
"label",
"[",
"'title'",
"]",
",",
"}",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"UPDATE",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"TAGS",
".",
"value",
",",
"params",
"=",
"data",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Labels.delete | Delete the specified label
:param id: the label's ID
:type id: str
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def delete(self, id):
"""
Delete the specified label
:param id: the label's ID
:type id: str
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
return self._post(
request=ApiActions.DELETE.value,
uri=ApiUri.TAGS.value,
params={'id': id}
) | def delete(self, id):
"""
Delete the specified label
:param id: the label's ID
:type id: str
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
return self._post(
request=ApiActions.DELETE.value,
uri=ApiUri.TAGS.value,
params={'id': id}
) | [
"Delete",
"the",
"specified",
"label"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L194-L209 | [
"def",
"delete",
"(",
"self",
",",
"id",
")",
":",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"DELETE",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"TAGS",
".",
"value",
",",
"params",
"=",
"{",
"'id'",
":",
"id",
"}",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Tags.create | Create a new tag
:param label_id: The Label ID (the 'sn' key of the create label response)
:type label_id: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def create(self, label_id):
"""
Create a new tag
:param label_id: The Label ID (the 'sn' key of the create label response)
:type label_id: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
data = {
'type': 'tagit',
'rate_count': 0,
'rate_range': 'day',
'limit_count': 0,
'limit_range': 'day',
'schedule': [],
'enabled': True,
'args': {
'sn': label_id,
'tag_sn': label_id
}
}
# Yes, it's confusing. the `/actions/` endpoint is used for tags, while
# the /tags/ endpoint is used for labels.
return self._post(
request=ApiActions.CREATE.value,
uri=ApiUri.ACTIONS.value,
params=data
) | def create(self, label_id):
"""
Create a new tag
:param label_id: The Label ID (the 'sn' key of the create label response)
:type label_id: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
data = {
'type': 'tagit',
'rate_count': 0,
'rate_range': 'day',
'limit_count': 0,
'limit_range': 'day',
'schedule': [],
'enabled': True,
'args': {
'sn': label_id,
'tag_sn': label_id
}
}
# Yes, it's confusing. the `/actions/` endpoint is used for tags, while
# the /tags/ endpoint is used for labels.
return self._post(
request=ApiActions.CREATE.value,
uri=ApiUri.ACTIONS.value,
params=data
) | [
"Create",
"a",
"new",
"tag"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L219-L252 | [
"def",
"create",
"(",
"self",
",",
"label_id",
")",
":",
"data",
"=",
"{",
"'type'",
":",
"'tagit'",
",",
"'rate_count'",
":",
"0",
",",
"'rate_range'",
":",
"'day'",
",",
"'limit_count'",
":",
"0",
",",
"'limit_range'",
":",
"'day'",
",",
"'schedule'",
":",
"[",
"]",
",",
"'enabled'",
":",
"True",
",",
"'args'",
":",
"{",
"'sn'",
":",
"label_id",
",",
"'tag_sn'",
":",
"label_id",
"}",
"}",
"# Yes, it's confusing. the `/actions/` endpoint is used for tags, while",
"# the /tags/ endpoint is used for labels.",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"CREATE",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"ACTIONS",
".",
"value",
",",
"params",
"=",
"data",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Tags.list | Get all current tags
:return: All tags
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def list(self):
"""
Get all current tags
:return: All tags
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
return list(
filter(
lambda x: x.get('type') == 'tagit', # pragma: no cover
self._post(
request=ApiActions.LIST.value,
uri=ApiUri.ACTIONS.value,
).get('actions')
)
) | def list(self):
"""
Get all current tags
:return: All tags
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
return list(
filter(
lambda x: x.get('type') == 'tagit', # pragma: no cover
self._post(
request=ApiActions.LIST.value,
uri=ApiUri.ACTIONS.value,
).get('actions')
)
) | [
"Get",
"all",
"current",
"tags"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L254-L273 | [
"def",
"list",
"(",
"self",
")",
":",
"return",
"list",
"(",
"filter",
"(",
"lambda",
"x",
":",
"x",
".",
"get",
"(",
"'type'",
")",
"==",
"'tagit'",
",",
"# pragma: no cover",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"LIST",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"ACTIONS",
".",
"value",
",",
")",
".",
"get",
"(",
"'actions'",
")",
")",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Tags.get | Get tags by a label's sn key
:param label_sn: A corresponding label's ``sn`` key.
:type label_sn: str or int
:return: A list of matching tags. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def get(self, label_sn):
"""
Get tags by a label's sn key
:param label_sn: A corresponding label's ``sn`` key.
:type label_sn: str or int
:return: A list of matching tags. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
tags = self.list()
return [
tag
for tag
in tags
if str(label_sn) in tag.get('args', {}).values()
] | def get(self, label_sn):
"""
Get tags by a label's sn key
:param label_sn: A corresponding label's ``sn`` key.
:type label_sn: str or int
:return: A list of matching tags. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
tags = self.list()
return [
tag
for tag
in tags
if str(label_sn) in tag.get('args', {}).values()
] | [
"Get",
"tags",
"by",
"a",
"label",
"s",
"sn",
"key"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L275-L296 | [
"def",
"get",
"(",
"self",
",",
"label_sn",
")",
":",
"tags",
"=",
"self",
".",
"list",
"(",
")",
"return",
"[",
"tag",
"for",
"tag",
"in",
"tags",
"if",
"str",
"(",
"label_sn",
")",
"in",
"tag",
".",
"get",
"(",
"'args'",
",",
"{",
"}",
")",
".",
"values",
"(",
")",
"]"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Hooks.create | Create a hook
:param name: The hook's name (should be the same as the tag)
:type name: str
:param regexes: The list of regular expressions that Logentries expects.
Ex: `['user_agent = /curl\/[\d.]*/']` Would match where the
user-agent is curl.
:type regexes: list of str
:param tag_id: The ids of the tags to associate the hook with.
(The 'id' key of the create tag response)
:type tag_id: list of str
:param logs: The logs to add the hook to. Comes from the 'key'
key in the log dict.
:type logs: list of str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def create(self, name, regexes, tag_ids, logs=None):
"""
Create a hook
:param name: The hook's name (should be the same as the tag)
:type name: str
:param regexes: The list of regular expressions that Logentries expects.
Ex: `['user_agent = /curl\/[\d.]*/']` Would match where the
user-agent is curl.
:type regexes: list of str
:param tag_id: The ids of the tags to associate the hook with.
(The 'id' key of the create tag response)
:type tag_id: list of str
:param logs: The logs to add the hook to. Comes from the 'key'
key in the log dict.
:type logs: list of str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
data = {
'name': name,
'triggers': regexes,
'sources': logs or [],
'groups': [],
'actions': tag_ids
}
return self._post(
request=ApiActions.CREATE.value,
uri=ApiUri.HOOKS.value,
params=data
) | def create(self, name, regexes, tag_ids, logs=None):
"""
Create a hook
:param name: The hook's name (should be the same as the tag)
:type name: str
:param regexes: The list of regular expressions that Logentries expects.
Ex: `['user_agent = /curl\/[\d.]*/']` Would match where the
user-agent is curl.
:type regexes: list of str
:param tag_id: The ids of the tags to associate the hook with.
(The 'id' key of the create tag response)
:type tag_id: list of str
:param logs: The logs to add the hook to. Comes from the 'key'
key in the log dict.
:type logs: list of str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
data = {
'name': name,
'triggers': regexes,
'sources': logs or [],
'groups': [],
'actions': tag_ids
}
return self._post(
request=ApiActions.CREATE.value,
uri=ApiUri.HOOKS.value,
params=data
) | [
"Create",
"a",
"hook"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L322-L360 | [
"def",
"create",
"(",
"self",
",",
"name",
",",
"regexes",
",",
"tag_ids",
",",
"logs",
"=",
"None",
")",
":",
"data",
"=",
"{",
"'name'",
":",
"name",
",",
"'triggers'",
":",
"regexes",
",",
"'sources'",
":",
"logs",
"or",
"[",
"]",
",",
"'groups'",
":",
"[",
"]",
",",
"'actions'",
":",
"tag_ids",
"}",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"CREATE",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"HOOKS",
".",
"value",
",",
"params",
"=",
"data",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Hooks.list | Get all current hooks
:return: All hooks
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def list(self):
"""
Get all current hooks
:return: All hooks
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
return self._post(
request=ApiActions.LIST.value,
uri=ApiUri.HOOKS.value,
).get('hooks') | def list(self):
"""
Get all current hooks
:return: All hooks
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
return self._post(
request=ApiActions.LIST.value,
uri=ApiUri.HOOKS.value,
).get('hooks') | [
"Get",
"all",
"current",
"hooks"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L362-L376 | [
"def",
"list",
"(",
"self",
")",
":",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"LIST",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"HOOKS",
".",
"value",
",",
")",
".",
"get",
"(",
"'hooks'",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Hooks.get | Get hooks by name or tag_id.
:param name_or_tag_id: The hook's name or associated tag['id']
:type name_or_tag_id: str
:return: A list of matching tags. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def get(self, name_or_tag_id):
"""
Get hooks by name or tag_id.
:param name_or_tag_id: The hook's name or associated tag['id']
:type name_or_tag_id: str
:return: A list of matching tags. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
hooks = self.list()
return [
hook
for hook
in hooks
if name_or_tag_id in hook.get('actions')
or name_or_tag_id == hook.get('name')
] | def get(self, name_or_tag_id):
"""
Get hooks by name or tag_id.
:param name_or_tag_id: The hook's name or associated tag['id']
:type name_or_tag_id: str
:return: A list of matching tags. An empty list is returned if there are
not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
hooks = self.list()
return [
hook
for hook
in hooks
if name_or_tag_id in hook.get('actions')
or name_or_tag_id == hook.get('name')
] | [
"Get",
"hooks",
"by",
"name",
"or",
"tag_id",
".",
":",
"param",
"name_or_tag_id",
":",
"The",
"hook",
"s",
"name",
"or",
"associated",
"tag",
"[",
"id",
"]",
":",
"type",
"name_or_tag_id",
":",
"str"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L378-L400 | [
"def",
"get",
"(",
"self",
",",
"name_or_tag_id",
")",
":",
"hooks",
"=",
"self",
".",
"list",
"(",
")",
"return",
"[",
"hook",
"for",
"hook",
"in",
"hooks",
"if",
"name_or_tag_id",
"in",
"hook",
".",
"get",
"(",
"'actions'",
")",
"or",
"name_or_tag_id",
"==",
"hook",
".",
"get",
"(",
"'name'",
")",
"]"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Hooks.update | Update a hook
:param hook: The data to update. Must include keys:
* id (str)
* name (str)
* triggers (list of str)
* sources (list of str)
* groups (list of str)
* actions (list of str)
:type hook: dict
Example:
.. code-block:: python
Hooks().update(
hook={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'name': 'My Sandbox',
'triggers': [
'host = you.example.com'
],
'sources': [
'4d42c719-4005-4929-aa4a-994da4b95040'
],
'groups': [],
'actions': [
'9f6adf69-37b9-4a4b-88fb-c3fc4c781a11',
'ddc36d71-33cb-4f4f-be1b-8591814b1946'
],
}
)
:return:
:rtype: dict | logentries_api/resources.py | def update(self, hook):
"""
Update a hook
:param hook: The data to update. Must include keys:
* id (str)
* name (str)
* triggers (list of str)
* sources (list of str)
* groups (list of str)
* actions (list of str)
:type hook: dict
Example:
.. code-block:: python
Hooks().update(
hook={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'name': 'My Sandbox',
'triggers': [
'host = you.example.com'
],
'sources': [
'4d42c719-4005-4929-aa4a-994da4b95040'
],
'groups': [],
'actions': [
'9f6adf69-37b9-4a4b-88fb-c3fc4c781a11',
'ddc36d71-33cb-4f4f-be1b-8591814b1946'
],
}
)
:return:
:rtype: dict
"""
data = {
'id': hook['id'],
'name': hook['name'],
'triggers': hook['triggers'],
'sources': hook['sources'],
'groups': hook['groups'],
'actions': hook['actions'],
}
return self._post(
request=ApiActions.UPDATE.value,
uri=ApiUri.HOOKS.value,
params=data
) | def update(self, hook):
"""
Update a hook
:param hook: The data to update. Must include keys:
* id (str)
* name (str)
* triggers (list of str)
* sources (list of str)
* groups (list of str)
* actions (list of str)
:type hook: dict
Example:
.. code-block:: python
Hooks().update(
hook={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'name': 'My Sandbox',
'triggers': [
'host = you.example.com'
],
'sources': [
'4d42c719-4005-4929-aa4a-994da4b95040'
],
'groups': [],
'actions': [
'9f6adf69-37b9-4a4b-88fb-c3fc4c781a11',
'ddc36d71-33cb-4f4f-be1b-8591814b1946'
],
}
)
:return:
:rtype: dict
"""
data = {
'id': hook['id'],
'name': hook['name'],
'triggers': hook['triggers'],
'sources': hook['sources'],
'groups': hook['groups'],
'actions': hook['actions'],
}
return self._post(
request=ApiActions.UPDATE.value,
uri=ApiUri.HOOKS.value,
params=data
) | [
"Update",
"a",
"hook"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L402-L453 | [
"def",
"update",
"(",
"self",
",",
"hook",
")",
":",
"data",
"=",
"{",
"'id'",
":",
"hook",
"[",
"'id'",
"]",
",",
"'name'",
":",
"hook",
"[",
"'name'",
"]",
",",
"'triggers'",
":",
"hook",
"[",
"'triggers'",
"]",
",",
"'sources'",
":",
"hook",
"[",
"'sources'",
"]",
",",
"'groups'",
":",
"hook",
"[",
"'groups'",
"]",
",",
"'actions'",
":",
"hook",
"[",
"'actions'",
"]",
",",
"}",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"UPDATE",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"HOOKS",
".",
"value",
",",
"params",
"=",
"data",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Alerts.create | Create a new alert
:param alert_config: A list of AlertConfig classes (Ex:
``[EmailAlertConfig('me@mydomain.com')]``)
:type alert_config: list of
:class:`PagerDutyAlertConfig<logentries_api.alerts.PagerDutyAlertConfig>`,
:class:`WebHookAlertConfig<logentries_api.alerts.WebHookAlertConfig>`,
:class:`EmailAlertConfig<logentries_api.alerts.EmailAlertConfig>`,
:class:`SlackAlertConfig<logentries_api.alerts.SlackAlertConfig>`, or
:class:`HipChatAlertConfig<logentries_api.alerts.HipChatAlertConfig>`
:param occurrence_frequency_count: How many times per
``alert_frequency_unit`` for a match before issuing an alert.
Defaults to 1
:type occurrence_frequency_count: int
:param occurrence_frequency_unit: The time period to monitor for sending
an alert. Must be 'day', or 'hour'. Defaults to 'hour'
:type occurrence_frequency_unit: str
:param alert_frequency_count: How many times per
``alert_frequency_unit`` to issue an alert. Defaults to 1
:type alert_frequency_count: int
:param alert_frequency_unit: How often to regulate sending alerts.
Must be 'day', or 'hour'. Defaults to 'hour'
:type alert_frequency_unit: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def create(self,
alert_config,
occurrence_frequency_count=None,
occurrence_frequency_unit=None,
alert_frequency_count=None,
alert_frequency_unit=None):
"""
Create a new alert
:param alert_config: A list of AlertConfig classes (Ex:
``[EmailAlertConfig('me@mydomain.com')]``)
:type alert_config: list of
:class:`PagerDutyAlertConfig<logentries_api.alerts.PagerDutyAlertConfig>`,
:class:`WebHookAlertConfig<logentries_api.alerts.WebHookAlertConfig>`,
:class:`EmailAlertConfig<logentries_api.alerts.EmailAlertConfig>`,
:class:`SlackAlertConfig<logentries_api.alerts.SlackAlertConfig>`, or
:class:`HipChatAlertConfig<logentries_api.alerts.HipChatAlertConfig>`
:param occurrence_frequency_count: How many times per
``alert_frequency_unit`` for a match before issuing an alert.
Defaults to 1
:type occurrence_frequency_count: int
:param occurrence_frequency_unit: The time period to monitor for sending
an alert. Must be 'day', or 'hour'. Defaults to 'hour'
:type occurrence_frequency_unit: str
:param alert_frequency_count: How many times per
``alert_frequency_unit`` to issue an alert. Defaults to 1
:type alert_frequency_count: int
:param alert_frequency_unit: How often to regulate sending alerts.
Must be 'day', or 'hour'. Defaults to 'hour'
:type alert_frequency_unit: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
data = {
'rate_count': occurrence_frequency_count or 1,
'rate_range': occurrence_frequency_unit or 'hour',
'limit_count': alert_frequency_count or 1,
'limit_range': alert_frequency_unit or 'hour',
'schedule': [],
'enabled': True,
}
data.update(alert_config.args())
# Yes, it's confusing. the `/actions/` endpoint is used for alerts, while
# the /tags/ endpoint is used for labels.
return self._post(
request=ApiActions.CREATE.value,
uri=ApiUri.ACTIONS.value,
params=data
) | def create(self,
alert_config,
occurrence_frequency_count=None,
occurrence_frequency_unit=None,
alert_frequency_count=None,
alert_frequency_unit=None):
"""
Create a new alert
:param alert_config: A list of AlertConfig classes (Ex:
``[EmailAlertConfig('me@mydomain.com')]``)
:type alert_config: list of
:class:`PagerDutyAlertConfig<logentries_api.alerts.PagerDutyAlertConfig>`,
:class:`WebHookAlertConfig<logentries_api.alerts.WebHookAlertConfig>`,
:class:`EmailAlertConfig<logentries_api.alerts.EmailAlertConfig>`,
:class:`SlackAlertConfig<logentries_api.alerts.SlackAlertConfig>`, or
:class:`HipChatAlertConfig<logentries_api.alerts.HipChatAlertConfig>`
:param occurrence_frequency_count: How many times per
``alert_frequency_unit`` for a match before issuing an alert.
Defaults to 1
:type occurrence_frequency_count: int
:param occurrence_frequency_unit: The time period to monitor for sending
an alert. Must be 'day', or 'hour'. Defaults to 'hour'
:type occurrence_frequency_unit: str
:param alert_frequency_count: How many times per
``alert_frequency_unit`` to issue an alert. Defaults to 1
:type alert_frequency_count: int
:param alert_frequency_unit: How often to regulate sending alerts.
Must be 'day', or 'hour'. Defaults to 'hour'
:type alert_frequency_unit: str
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
data = {
'rate_count': occurrence_frequency_count or 1,
'rate_range': occurrence_frequency_unit or 'hour',
'limit_count': alert_frequency_count or 1,
'limit_range': alert_frequency_unit or 'hour',
'schedule': [],
'enabled': True,
}
data.update(alert_config.args())
# Yes, it's confusing. the `/actions/` endpoint is used for alerts, while
# the /tags/ endpoint is used for labels.
return self._post(
request=ApiActions.CREATE.value,
uri=ApiUri.ACTIONS.value,
params=data
) | [
"Create",
"a",
"new",
"alert"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L478-L536 | [
"def",
"create",
"(",
"self",
",",
"alert_config",
",",
"occurrence_frequency_count",
"=",
"None",
",",
"occurrence_frequency_unit",
"=",
"None",
",",
"alert_frequency_count",
"=",
"None",
",",
"alert_frequency_unit",
"=",
"None",
")",
":",
"data",
"=",
"{",
"'rate_count'",
":",
"occurrence_frequency_count",
"or",
"1",
",",
"'rate_range'",
":",
"occurrence_frequency_unit",
"or",
"'hour'",
",",
"'limit_count'",
":",
"alert_frequency_count",
"or",
"1",
",",
"'limit_range'",
":",
"alert_frequency_unit",
"or",
"'hour'",
",",
"'schedule'",
":",
"[",
"]",
",",
"'enabled'",
":",
"True",
",",
"}",
"data",
".",
"update",
"(",
"alert_config",
".",
"args",
"(",
")",
")",
"# Yes, it's confusing. the `/actions/` endpoint is used for alerts, while",
"# the /tags/ endpoint is used for labels.",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"CREATE",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"ACTIONS",
".",
"value",
",",
"params",
"=",
"data",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Alerts.get | Get alerts that match the alert type and args.
:param alert_type: The type of the alert. Must be one of 'pagerduty',
'mailto', 'webhook', 'slack', or 'hipchat'
:type alert_type: str
:param alert_args: The args for the alert. The provided args must be a
subset of the actual alert args. If no args are provided, all
alerts matching the ``alert_type`` are returned. For example:
``.get('mailto', alert_args={'direct': 'me@mydomain.com'})`` or
``.get('slack', {'url': 'https://hooks.slack.com/services...'})``
:return: A list of matching alerts. An empty list is returned if there
are not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/resources.py | def get(self, alert_type, alert_args=None):
"""
Get alerts that match the alert type and args.
:param alert_type: The type of the alert. Must be one of 'pagerduty',
'mailto', 'webhook', 'slack', or 'hipchat'
:type alert_type: str
:param alert_args: The args for the alert. The provided args must be a
subset of the actual alert args. If no args are provided, all
alerts matching the ``alert_type`` are returned. For example:
``.get('mailto', alert_args={'direct': 'me@mydomain.com'})`` or
``.get('slack', {'url': 'https://hooks.slack.com/services...'})``
:return: A list of matching alerts. An empty list is returned if there
are not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
alert_args = alert_args or {}
alerts = self.list()
return [
alert
for alert
in alerts
if alert.get('type') == alert_type
and dict_is_subset(alert_args, alert.get('args'))
] | def get(self, alert_type, alert_args=None):
"""
Get alerts that match the alert type and args.
:param alert_type: The type of the alert. Must be one of 'pagerduty',
'mailto', 'webhook', 'slack', or 'hipchat'
:type alert_type: str
:param alert_args: The args for the alert. The provided args must be a
subset of the actual alert args. If no args are provided, all
alerts matching the ``alert_type`` are returned. For example:
``.get('mailto', alert_args={'direct': 'me@mydomain.com'})`` or
``.get('slack', {'url': 'https://hooks.slack.com/services...'})``
:return: A list of matching alerts. An empty list is returned if there
are not any matches
:rtype: list of dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
alert_args = alert_args or {}
alerts = self.list()
return [
alert
for alert
in alerts
if alert.get('type') == alert_type
and dict_is_subset(alert_args, alert.get('args'))
] | [
"Get",
"alerts",
"that",
"match",
"the",
"alert",
"type",
"and",
"args",
"."
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L560-L591 | [
"def",
"get",
"(",
"self",
",",
"alert_type",
",",
"alert_args",
"=",
"None",
")",
":",
"alert_args",
"=",
"alert_args",
"or",
"{",
"}",
"alerts",
"=",
"self",
".",
"list",
"(",
")",
"return",
"[",
"alert",
"for",
"alert",
"in",
"alerts",
"if",
"alert",
".",
"get",
"(",
"'type'",
")",
"==",
"alert_type",
"and",
"dict_is_subset",
"(",
"alert_args",
",",
"alert",
".",
"get",
"(",
"'args'",
")",
")",
"]"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | Alerts.update | Update an alert
:param alert: The data to update. Must include keys:
* id (str)
* rate_count (int)
* rate_range (str): 'day' or 'hour'
* limit_count (int)
* limit_range (str): 'day' or 'hour'
* type (str)
* schedule (list)
* args (dict)
:type alert: dict
Example:
.. code-block:: python
Alert().update(
alert={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'args': {'direct': 'you@example.com'},
'rate_count': 1,
'rate_range': 'hour',
'limit_count': 1,
'limit_range': 'hour',
'schedule': [],
'enabled': True,
'type': 'mailto',
}
)
:return:
:rtype: dict | logentries_api/resources.py | def update(self, alert):
"""
Update an alert
:param alert: The data to update. Must include keys:
* id (str)
* rate_count (int)
* rate_range (str): 'day' or 'hour'
* limit_count (int)
* limit_range (str): 'day' or 'hour'
* type (str)
* schedule (list)
* args (dict)
:type alert: dict
Example:
.. code-block:: python
Alert().update(
alert={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'args': {'direct': 'you@example.com'},
'rate_count': 1,
'rate_range': 'hour',
'limit_count': 1,
'limit_range': 'hour',
'schedule': [],
'enabled': True,
'type': 'mailto',
}
)
:return:
:rtype: dict
"""
data = {
'id': alert['id'],
'args': alert['args'],
'rate_count': alert['rate_count'],
'rate_range': alert['rate_range'],
'limit_count': alert['limit_count'],
'limit_range': alert['limit_range'],
'schedule': alert['schedule'],
'enabled': alert['enabled'],
'type': alert['type'],
}
return self._post(
request=ApiActions.UPDATE.value,
uri=ApiUri.ACTIONS.value,
params=data
) | def update(self, alert):
"""
Update an alert
:param alert: The data to update. Must include keys:
* id (str)
* rate_count (int)
* rate_range (str): 'day' or 'hour'
* limit_count (int)
* limit_range (str): 'day' or 'hour'
* type (str)
* schedule (list)
* args (dict)
:type alert: dict
Example:
.. code-block:: python
Alert().update(
alert={
'id': 'd9d4596e-49e4-4135-b3b3-847f9e7c1f43',
'args': {'direct': 'you@example.com'},
'rate_count': 1,
'rate_range': 'hour',
'limit_count': 1,
'limit_range': 'hour',
'schedule': [],
'enabled': True,
'type': 'mailto',
}
)
:return:
:rtype: dict
"""
data = {
'id': alert['id'],
'args': alert['args'],
'rate_count': alert['rate_count'],
'rate_range': alert['rate_range'],
'limit_count': alert['limit_count'],
'limit_range': alert['limit_range'],
'schedule': alert['schedule'],
'enabled': alert['enabled'],
'type': alert['type'],
}
return self._post(
request=ApiActions.UPDATE.value,
uri=ApiUri.ACTIONS.value,
params=data
) | [
"Update",
"an",
"alert"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/resources.py#L593-L646 | [
"def",
"update",
"(",
"self",
",",
"alert",
")",
":",
"data",
"=",
"{",
"'id'",
":",
"alert",
"[",
"'id'",
"]",
",",
"'args'",
":",
"alert",
"[",
"'args'",
"]",
",",
"'rate_count'",
":",
"alert",
"[",
"'rate_count'",
"]",
",",
"'rate_range'",
":",
"alert",
"[",
"'rate_range'",
"]",
",",
"'limit_count'",
":",
"alert",
"[",
"'limit_count'",
"]",
",",
"'limit_range'",
":",
"alert",
"[",
"'limit_range'",
"]",
",",
"'schedule'",
":",
"alert",
"[",
"'schedule'",
"]",
",",
"'enabled'",
":",
"alert",
"[",
"'enabled'",
"]",
",",
"'type'",
":",
"alert",
"[",
"'type'",
"]",
",",
"}",
"return",
"self",
".",
"_post",
"(",
"request",
"=",
"ApiActions",
".",
"UPDATE",
".",
"value",
",",
"uri",
"=",
"ApiUri",
".",
"ACTIONS",
".",
"value",
",",
"params",
"=",
"data",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | setup | Initialize this Sphinx extension | sage_package/sphinx.py | def setup(app):
"""
Initialize this Sphinx extension
"""
app.setup_extension('sphinx.ext.todo')
app.setup_extension('sphinx.ext.mathjax')
app.setup_extension("sphinx.ext.intersphinx")
app.config.intersphinx_mapping.update({
'https://docs.python.org/': None
})
app.config.intersphinx_mapping.update({
sage_doc_url + doc + "/": None
for doc in sage_documents
})
app.config.intersphinx_mapping.update({
sage_doc_url + "reference/" + module: None
for module in sage_modules
})
app.setup_extension("sphinx.ext.extlinks")
app.config.extlinks.update({
'python': ('https://docs.python.org/release/'+pythonversion+'/%s', ''),
# Sage trac ticket shortcuts. For example, :trac:`7549` .
'trac': ('https://trac.sagemath.org/%s', 'trac ticket #'),
'wikipedia': ('https://en.wikipedia.org/wiki/%s', 'Wikipedia article '),
'arxiv': ('http://arxiv.org/abs/%s', 'Arxiv '),
'oeis': ('https://oeis.org/%s', 'OEIS sequence '),
'doi': ('https://dx.doi.org/%s', 'doi:'),
'pari': ('http://pari.math.u-bordeaux.fr/dochtml/help/%s', 'pari:'),
'mathscinet': ('http://www.ams.org/mathscinet-getitem?mr=%s', 'MathSciNet ')
})
app.config.html_theme = 'sage' | def setup(app):
"""
Initialize this Sphinx extension
"""
app.setup_extension('sphinx.ext.todo')
app.setup_extension('sphinx.ext.mathjax')
app.setup_extension("sphinx.ext.intersphinx")
app.config.intersphinx_mapping.update({
'https://docs.python.org/': None
})
app.config.intersphinx_mapping.update({
sage_doc_url + doc + "/": None
for doc in sage_documents
})
app.config.intersphinx_mapping.update({
sage_doc_url + "reference/" + module: None
for module in sage_modules
})
app.setup_extension("sphinx.ext.extlinks")
app.config.extlinks.update({
'python': ('https://docs.python.org/release/'+pythonversion+'/%s', ''),
# Sage trac ticket shortcuts. For example, :trac:`7549` .
'trac': ('https://trac.sagemath.org/%s', 'trac ticket #'),
'wikipedia': ('https://en.wikipedia.org/wiki/%s', 'Wikipedia article '),
'arxiv': ('http://arxiv.org/abs/%s', 'Arxiv '),
'oeis': ('https://oeis.org/%s', 'OEIS sequence '),
'doi': ('https://dx.doi.org/%s', 'doi:'),
'pari': ('http://pari.math.u-bordeaux.fr/dochtml/help/%s', 'pari:'),
'mathscinet': ('http://www.ams.org/mathscinet-getitem?mr=%s', 'MathSciNet ')
})
app.config.html_theme = 'sage' | [
"Initialize",
"this",
"Sphinx",
"extension"
] | sagemath/sage-package | python | https://github.com/sagemath/sage-package/blob/6e511753fb0667b202f497fc00b763647456a066/sage_package/sphinx.py#L37-L70 | [
"def",
"setup",
"(",
"app",
")",
":",
"app",
".",
"setup_extension",
"(",
"'sphinx.ext.todo'",
")",
"app",
".",
"setup_extension",
"(",
"'sphinx.ext.mathjax'",
")",
"app",
".",
"setup_extension",
"(",
"\"sphinx.ext.intersphinx\"",
")",
"app",
".",
"config",
".",
"intersphinx_mapping",
".",
"update",
"(",
"{",
"'https://docs.python.org/'",
":",
"None",
"}",
")",
"app",
".",
"config",
".",
"intersphinx_mapping",
".",
"update",
"(",
"{",
"sage_doc_url",
"+",
"doc",
"+",
"\"/\"",
":",
"None",
"for",
"doc",
"in",
"sage_documents",
"}",
")",
"app",
".",
"config",
".",
"intersphinx_mapping",
".",
"update",
"(",
"{",
"sage_doc_url",
"+",
"\"reference/\"",
"+",
"module",
":",
"None",
"for",
"module",
"in",
"sage_modules",
"}",
")",
"app",
".",
"setup_extension",
"(",
"\"sphinx.ext.extlinks\"",
")",
"app",
".",
"config",
".",
"extlinks",
".",
"update",
"(",
"{",
"'python'",
":",
"(",
"'https://docs.python.org/release/'",
"+",
"pythonversion",
"+",
"'/%s'",
",",
"''",
")",
",",
"# Sage trac ticket shortcuts. For example, :trac:`7549` .",
"'trac'",
":",
"(",
"'https://trac.sagemath.org/%s'",
",",
"'trac ticket #'",
")",
",",
"'wikipedia'",
":",
"(",
"'https://en.wikipedia.org/wiki/%s'",
",",
"'Wikipedia article '",
")",
",",
"'arxiv'",
":",
"(",
"'http://arxiv.org/abs/%s'",
",",
"'Arxiv '",
")",
",",
"'oeis'",
":",
"(",
"'https://oeis.org/%s'",
",",
"'OEIS sequence '",
")",
",",
"'doi'",
":",
"(",
"'https://dx.doi.org/%s'",
",",
"'doi:'",
")",
",",
"'pari'",
":",
"(",
"'http://pari.math.u-bordeaux.fr/dochtml/help/%s'",
",",
"'pari:'",
")",
",",
"'mathscinet'",
":",
"(",
"'http://www.ams.org/mathscinet-getitem?mr=%s'",
",",
"'MathSciNet '",
")",
"}",
")",
"app",
".",
"config",
".",
"html_theme",
"=",
"'sage'"
] | 6e511753fb0667b202f497fc00b763647456a066 |
test | themes_path | Retrieve the location of the themes directory from the location of this package
This is taken from Sphinx's theme documentation | sage_package/sphinx.py | def themes_path():
"""
Retrieve the location of the themes directory from the location of this package
This is taken from Sphinx's theme documentation
"""
package_dir = os.path.abspath(os.path.dirname(__file__))
return os.path.join(package_dir, 'themes') | def themes_path():
"""
Retrieve the location of the themes directory from the location of this package
This is taken from Sphinx's theme documentation
"""
package_dir = os.path.abspath(os.path.dirname(__file__))
return os.path.join(package_dir, 'themes') | [
"Retrieve",
"the",
"location",
"of",
"the",
"themes",
"directory",
"from",
"the",
"location",
"of",
"this",
"package"
] | sagemath/sage-package | python | https://github.com/sagemath/sage-package/blob/6e511753fb0667b202f497fc00b763647456a066/sage_package/sphinx.py#L72-L79 | [
"def",
"themes_path",
"(",
")",
":",
"package_dir",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
"return",
"os",
".",
"path",
".",
"join",
"(",
"package_dir",
",",
"'themes'",
")"
] | 6e511753fb0667b202f497fc00b763647456a066 |
test | Resource._post | A wrapper for posting things.
:param request: The request type. Must be one of the
:class:`ApiActions<logentries_api.base.ApiActions>`
:type request: str
:param uri: The API endpoint to hit. Must be one of
:class:`ApiUri<logentries_api.base.ApiUri>`
:type uri: str
:param params: A dictionary of supplemental kw args
:type params: dict
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/base.py | def _post(self, request, uri, params=None):
"""
A wrapper for posting things.
:param request: The request type. Must be one of the
:class:`ApiActions<logentries_api.base.ApiActions>`
:type request: str
:param uri: The API endpoint to hit. Must be one of
:class:`ApiUri<logentries_api.base.ApiUri>`
:type uri: str
:param params: A dictionary of supplemental kw args
:type params: dict
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
request_data = {
'acl': self.account_key,
'account': self.account_key,
'request': request,
}
request_data.update(params or {})
response = requests.post(
url='https://api.logentries.com/v2/{}'.format(uri),
headers=self.headers,
data=json.dumps(request_data)
)
if not response.ok:
raise ServerException(
'{}: {}'.format(response.status_code, response.text))
return response.json() | def _post(self, request, uri, params=None):
"""
A wrapper for posting things.
:param request: The request type. Must be one of the
:class:`ApiActions<logentries_api.base.ApiActions>`
:type request: str
:param uri: The API endpoint to hit. Must be one of
:class:`ApiUri<logentries_api.base.ApiUri>`
:type uri: str
:param params: A dictionary of supplemental kw args
:type params: dict
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
request_data = {
'acl': self.account_key,
'account': self.account_key,
'request': request,
}
request_data.update(params or {})
response = requests.post(
url='https://api.logentries.com/v2/{}'.format(uri),
headers=self.headers,
data=json.dumps(request_data)
)
if not response.ok:
raise ServerException(
'{}: {}'.format(response.status_code, response.text))
return response.json() | [
"A",
"wrapper",
"for",
"posting",
"things",
"."
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/base.py#L49-L88 | [
"def",
"_post",
"(",
"self",
",",
"request",
",",
"uri",
",",
"params",
"=",
"None",
")",
":",
"request_data",
"=",
"{",
"'acl'",
":",
"self",
".",
"account_key",
",",
"'account'",
":",
"self",
".",
"account_key",
",",
"'request'",
":",
"request",
",",
"}",
"request_data",
".",
"update",
"(",
"params",
"or",
"{",
"}",
")",
"response",
"=",
"requests",
".",
"post",
"(",
"url",
"=",
"'https://api.logentries.com/v2/{}'",
".",
"format",
"(",
"uri",
")",
",",
"headers",
"=",
"self",
".",
"headers",
",",
"data",
"=",
"json",
".",
"dumps",
"(",
"request_data",
")",
")",
"if",
"not",
"response",
".",
"ok",
":",
"raise",
"ServerException",
"(",
"'{}: {}'",
".",
"format",
"(",
"response",
".",
"status_code",
",",
"response",
".",
"text",
")",
")",
"return",
"response",
".",
"json",
"(",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | LogSets.list | Get all log sets
:return: Returns a dictionary where the key is the hostname or log set,
and the value is a list of the log keys
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/logs.py | def list(self):
"""
Get all log sets
:return: Returns a dictionary where the key is the hostname or log set,
and the value is a list of the log keys
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
response = requests.get(self.base_url)
if not response.ok:
raise ServerException(
'{}: {}'.format(response.status_code, response.text))
return {
host.get('name'): [
log.get('key')
for log
in host.get('logs')]
for host
in response.json().get('list')
} | def list(self):
"""
Get all log sets
:return: Returns a dictionary where the key is the hostname or log set,
and the value is a list of the log keys
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
response = requests.get(self.base_url)
if not response.ok:
raise ServerException(
'{}: {}'.format(response.status_code, response.text))
return {
host.get('name'): [
log.get('key')
for log
in host.get('logs')]
for host
in response.json().get('list')
} | [
"Get",
"all",
"log",
"sets"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/logs.py#L15-L40 | [
"def",
"list",
"(",
"self",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"self",
".",
"base_url",
")",
"if",
"not",
"response",
".",
"ok",
":",
"raise",
"ServerException",
"(",
"'{}: {}'",
".",
"format",
"(",
"response",
".",
"status_code",
",",
"response",
".",
"text",
")",
")",
"return",
"{",
"host",
".",
"get",
"(",
"'name'",
")",
":",
"[",
"log",
".",
"get",
"(",
"'key'",
")",
"for",
"log",
"in",
"host",
".",
"get",
"(",
"'logs'",
")",
"]",
"for",
"host",
"in",
"response",
".",
"json",
"(",
")",
".",
"get",
"(",
"'list'",
")",
"}"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | LogSets.get | Get a specific log or log set
:param log_set: The log set or log to get. Ex: `.get(log_set='app')` or
`.get(log_set='app/log')`
:type log_set: str
:returns: The response of your log set or log
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries | logentries_api/logs.py | def get(self, log_set):
"""
Get a specific log or log set
:param log_set: The log set or log to get. Ex: `.get(log_set='app')` or
`.get(log_set='app/log')`
:type log_set: str
:returns: The response of your log set or log
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
response = requests.get(self.base_url + log_set.rstrip('/'))
if not response.ok:
raise ServerException(
'{}: {}'.format(response.status_code, response.text))
return response.json() | def get(self, log_set):
"""
Get a specific log or log set
:param log_set: The log set or log to get. Ex: `.get(log_set='app')` or
`.get(log_set='app/log')`
:type log_set: str
:returns: The response of your log set or log
:rtype: dict
:raises: This will raise a
:class:`ServerException<logentries_api.exceptions.ServerException>`
if there is an error from Logentries
"""
response = requests.get(self.base_url + log_set.rstrip('/'))
if not response.ok:
raise ServerException(
'{}: {}'.format(response.status_code, response.text))
return response.json() | [
"Get",
"a",
"specific",
"log",
"or",
"log",
"set"
] | ambitioninc/python-logentries-api | python | https://github.com/ambitioninc/python-logentries-api/blob/77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc/logentries_api/logs.py#L42-L62 | [
"def",
"get",
"(",
"self",
",",
"log_set",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"self",
".",
"base_url",
"+",
"log_set",
".",
"rstrip",
"(",
"'/'",
")",
")",
"if",
"not",
"response",
".",
"ok",
":",
"raise",
"ServerException",
"(",
"'{}: {}'",
".",
"format",
"(",
"response",
".",
"status_code",
",",
"response",
".",
"text",
")",
")",
"return",
"response",
".",
"json",
"(",
")"
] | 77ff1a7a2995d7ea2725b74e34c0f880f4ee23bc |
test | find_attacker_slider | Find a slider attacker
Parameters
----------
dest_list : list
To store the results.
occ_bb : int, bitboard
Occupancy bitboard.
piece_bb : int, bitboard
Bitboard with the position of the attacker piece.
target_bb : int, bitboard
Occupancy bitboard without any of the sliders in question.
pos : int
Target position.
pos_map : function
Mapping between a board position and its position in a single
rotated/translated rank produced with domain_trans.
domain_trans : function
Transformation from a rank/file/diagonal/anti-diagonal containing pos
to a single rank
pos_inv_map : function
Inverse of pos_map | lib/papageorge/model.py | def find_attacker_slider(dest_list, occ_bb, piece_bb, target_bb, pos,
domain):
""" Find a slider attacker
Parameters
----------
dest_list : list
To store the results.
occ_bb : int, bitboard
Occupancy bitboard.
piece_bb : int, bitboard
Bitboard with the position of the attacker piece.
target_bb : int, bitboard
Occupancy bitboard without any of the sliders in question.
pos : int
Target position.
pos_map : function
Mapping between a board position and its position in a single
rotated/translated rank produced with domain_trans.
domain_trans : function
Transformation from a rank/file/diagonal/anti-diagonal containing pos
to a single rank
pos_inv_map : function
Inverse of pos_map
"""
pos_map, domain_trans, pos_inv_map = domain
r = reach[pos_map(pos)][domain_trans(target_bb, pos)]
m = r & domain_trans(piece_bb, pos)
while m:
r = m&-m
rpos = r.bit_length()-1
if not (ray[rpos][pos_map(pos)] & domain_trans(occ_bb, pos)):
dest_list.append(pos_inv_map(rpos, pos))
m ^= r | def find_attacker_slider(dest_list, occ_bb, piece_bb, target_bb, pos,
domain):
""" Find a slider attacker
Parameters
----------
dest_list : list
To store the results.
occ_bb : int, bitboard
Occupancy bitboard.
piece_bb : int, bitboard
Bitboard with the position of the attacker piece.
target_bb : int, bitboard
Occupancy bitboard without any of the sliders in question.
pos : int
Target position.
pos_map : function
Mapping between a board position and its position in a single
rotated/translated rank produced with domain_trans.
domain_trans : function
Transformation from a rank/file/diagonal/anti-diagonal containing pos
to a single rank
pos_inv_map : function
Inverse of pos_map
"""
pos_map, domain_trans, pos_inv_map = domain
r = reach[pos_map(pos)][domain_trans(target_bb, pos)]
m = r & domain_trans(piece_bb, pos)
while m:
r = m&-m
rpos = r.bit_length()-1
if not (ray[rpos][pos_map(pos)] & domain_trans(occ_bb, pos)):
dest_list.append(pos_inv_map(rpos, pos))
m ^= r | [
"Find",
"a",
"slider",
"attacker"
] | drestebon/papageorge | python | https://github.com/drestebon/papageorge/blob/a30ea59bf6b4f5d151bd3f476a0a8357d89495d4/lib/papageorge/model.py#L256-L289 | [
"def",
"find_attacker_slider",
"(",
"dest_list",
",",
"occ_bb",
",",
"piece_bb",
",",
"target_bb",
",",
"pos",
",",
"domain",
")",
":",
"pos_map",
",",
"domain_trans",
",",
"pos_inv_map",
"=",
"domain",
"r",
"=",
"reach",
"[",
"pos_map",
"(",
"pos",
")",
"]",
"[",
"domain_trans",
"(",
"target_bb",
",",
"pos",
")",
"]",
"m",
"=",
"r",
"&",
"domain_trans",
"(",
"piece_bb",
",",
"pos",
")",
"while",
"m",
":",
"r",
"=",
"m",
"&",
"-",
"m",
"rpos",
"=",
"r",
".",
"bit_length",
"(",
")",
"-",
"1",
"if",
"not",
"(",
"ray",
"[",
"rpos",
"]",
"[",
"pos_map",
"(",
"pos",
")",
"]",
"&",
"domain_trans",
"(",
"occ_bb",
",",
"pos",
")",
")",
":",
"dest_list",
".",
"append",
"(",
"pos_inv_map",
"(",
"rpos",
",",
"pos",
")",
")",
"m",
"^=",
"r"
] | a30ea59bf6b4f5d151bd3f476a0a8357d89495d4 |
test | TRANSIT.duration | The approximate transit duration for the general case of an eccentric orbit | pysyzygy/transit.py | def duration(self):
'''
The approximate transit duration for the general case of an eccentric orbit
'''
ecc = self.ecc if not np.isnan(self.ecc) else np.sqrt(self.ecw**2 + self.esw**2)
esw = self.esw if not np.isnan(self.esw) else ecc * np.sin(self.w)
aRs = ((G * self.rhos * (1. + self.MpMs) *
(self.per * DAYSEC)**2.) / (3. * np.pi))**(1./3.)
inc = np.arccos(self.bcirc/aRs)
becc = self.bcirc * (1 - ecc**2)/(1 - esw)
tdur = self.per / 2. / np.pi * np.arcsin(((1. + self.RpRs)**2 -
becc**2)**0.5 / (np.sin(inc) * aRs))
tdur *= np.sqrt(1. - ecc**2.)/(1. - esw)
return tdur | def duration(self):
'''
The approximate transit duration for the general case of an eccentric orbit
'''
ecc = self.ecc if not np.isnan(self.ecc) else np.sqrt(self.ecw**2 + self.esw**2)
esw = self.esw if not np.isnan(self.esw) else ecc * np.sin(self.w)
aRs = ((G * self.rhos * (1. + self.MpMs) *
(self.per * DAYSEC)**2.) / (3. * np.pi))**(1./3.)
inc = np.arccos(self.bcirc/aRs)
becc = self.bcirc * (1 - ecc**2)/(1 - esw)
tdur = self.per / 2. / np.pi * np.arcsin(((1. + self.RpRs)**2 -
becc**2)**0.5 / (np.sin(inc) * aRs))
tdur *= np.sqrt(1. - ecc**2.)/(1. - esw)
return tdur | [
"The",
"approximate",
"transit",
"duration",
"for",
"the",
"general",
"case",
"of",
"an",
"eccentric",
"orbit"
] | rodluger/pysyzygy | python | https://github.com/rodluger/pysyzygy/blob/d2b64251047cc0f0d0adeb6feab4054e7fce4b7a/pysyzygy/transit.py#L154-L168 | [
"def",
"duration",
"(",
"self",
")",
":",
"ecc",
"=",
"self",
".",
"ecc",
"if",
"not",
"np",
".",
"isnan",
"(",
"self",
".",
"ecc",
")",
"else",
"np",
".",
"sqrt",
"(",
"self",
".",
"ecw",
"**",
"2",
"+",
"self",
".",
"esw",
"**",
"2",
")",
"esw",
"=",
"self",
".",
"esw",
"if",
"not",
"np",
".",
"isnan",
"(",
"self",
".",
"esw",
")",
"else",
"ecc",
"*",
"np",
".",
"sin",
"(",
"self",
".",
"w",
")",
"aRs",
"=",
"(",
"(",
"G",
"*",
"self",
".",
"rhos",
"*",
"(",
"1.",
"+",
"self",
".",
"MpMs",
")",
"*",
"(",
"self",
".",
"per",
"*",
"DAYSEC",
")",
"**",
"2.",
")",
"/",
"(",
"3.",
"*",
"np",
".",
"pi",
")",
")",
"**",
"(",
"1.",
"/",
"3.",
")",
"inc",
"=",
"np",
".",
"arccos",
"(",
"self",
".",
"bcirc",
"/",
"aRs",
")",
"becc",
"=",
"self",
".",
"bcirc",
"*",
"(",
"1",
"-",
"ecc",
"**",
"2",
")",
"/",
"(",
"1",
"-",
"esw",
")",
"tdur",
"=",
"self",
".",
"per",
"/",
"2.",
"/",
"np",
".",
"pi",
"*",
"np",
".",
"arcsin",
"(",
"(",
"(",
"1.",
"+",
"self",
".",
"RpRs",
")",
"**",
"2",
"-",
"becc",
"**",
"2",
")",
"**",
"0.5",
"/",
"(",
"np",
".",
"sin",
"(",
"inc",
")",
"*",
"aRs",
")",
")",
"tdur",
"*=",
"np",
".",
"sqrt",
"(",
"1.",
"-",
"ecc",
"**",
"2.",
")",
"/",
"(",
"1.",
"-",
"esw",
")",
"return",
"tdur"
] | d2b64251047cc0f0d0adeb6feab4054e7fce4b7a |
test | Transit.update | Update the transit keyword arguments | pysyzygy/transit.py | def update(self, **kwargs):
'''
Update the transit keyword arguments
'''
if kwargs.get('verify_kwargs', True):
valid = [y[0] for x in [TRANSIT, LIMBDARK, SETTINGS] for y in x._fields_] # List of valid kwargs
valid += ['b', 'times'] # These are special!
for k in kwargs.keys():
if k not in valid:
raise Exception("Invalid kwarg '%s'." % k)
if ('q1' in kwargs.keys()) and ('q2' in kwargs.keys()):
kwargs.update({'ldmodel': KIPPING})
elif ('c1' in kwargs.keys()) and ('c2' in kwargs.keys()) and \
('c3' in kwargs.keys()) and ('c4' in kwargs.keys()):
kwargs.update({'ldmodel': NONLINEAR})
self.limbdark.update(**kwargs)
self.transit.update(**kwargs)
self.settings.update(**kwargs) | def update(self, **kwargs):
'''
Update the transit keyword arguments
'''
if kwargs.get('verify_kwargs', True):
valid = [y[0] for x in [TRANSIT, LIMBDARK, SETTINGS] for y in x._fields_] # List of valid kwargs
valid += ['b', 'times'] # These are special!
for k in kwargs.keys():
if k not in valid:
raise Exception("Invalid kwarg '%s'." % k)
if ('q1' in kwargs.keys()) and ('q2' in kwargs.keys()):
kwargs.update({'ldmodel': KIPPING})
elif ('c1' in kwargs.keys()) and ('c2' in kwargs.keys()) and \
('c3' in kwargs.keys()) and ('c4' in kwargs.keys()):
kwargs.update({'ldmodel': NONLINEAR})
self.limbdark.update(**kwargs)
self.transit.update(**kwargs)
self.settings.update(**kwargs) | [
"Update",
"the",
"transit",
"keyword",
"arguments"
] | rodluger/pysyzygy | python | https://github.com/rodluger/pysyzygy/blob/d2b64251047cc0f0d0adeb6feab4054e7fce4b7a/pysyzygy/transit.py#L467-L488 | [
"def",
"update",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
".",
"get",
"(",
"'verify_kwargs'",
",",
"True",
")",
":",
"valid",
"=",
"[",
"y",
"[",
"0",
"]",
"for",
"x",
"in",
"[",
"TRANSIT",
",",
"LIMBDARK",
",",
"SETTINGS",
"]",
"for",
"y",
"in",
"x",
".",
"_fields_",
"]",
"# List of valid kwargs",
"valid",
"+=",
"[",
"'b'",
",",
"'times'",
"]",
"# These are special!",
"for",
"k",
"in",
"kwargs",
".",
"keys",
"(",
")",
":",
"if",
"k",
"not",
"in",
"valid",
":",
"raise",
"Exception",
"(",
"\"Invalid kwarg '%s'.\"",
"%",
"k",
")",
"if",
"(",
"'q1'",
"in",
"kwargs",
".",
"keys",
"(",
")",
")",
"and",
"(",
"'q2'",
"in",
"kwargs",
".",
"keys",
"(",
")",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"'ldmodel'",
":",
"KIPPING",
"}",
")",
"elif",
"(",
"'c1'",
"in",
"kwargs",
".",
"keys",
"(",
")",
")",
"and",
"(",
"'c2'",
"in",
"kwargs",
".",
"keys",
"(",
")",
")",
"and",
"(",
"'c3'",
"in",
"kwargs",
".",
"keys",
"(",
")",
")",
"and",
"(",
"'c4'",
"in",
"kwargs",
".",
"keys",
"(",
")",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"'ldmodel'",
":",
"NONLINEAR",
"}",
")",
"self",
".",
"limbdark",
".",
"update",
"(",
"*",
"*",
"kwargs",
")",
"self",
".",
"transit",
".",
"update",
"(",
"*",
"*",
"kwargs",
")",
"self",
".",
"settings",
".",
"update",
"(",
"*",
"*",
"kwargs",
")"
] | d2b64251047cc0f0d0adeb6feab4054e7fce4b7a |
test | Transit.Compute | Computes the light curve model | pysyzygy/transit.py | def Compute(self):
'''
Computes the light curve model
'''
err = _Compute(self.transit, self.limbdark, self.settings, self.arrays)
if err != _ERR_NONE: RaiseError(err) | def Compute(self):
'''
Computes the light curve model
'''
err = _Compute(self.transit, self.limbdark, self.settings, self.arrays)
if err != _ERR_NONE: RaiseError(err) | [
"Computes",
"the",
"light",
"curve",
"model"
] | rodluger/pysyzygy | python | https://github.com/rodluger/pysyzygy/blob/d2b64251047cc0f0d0adeb6feab4054e7fce4b7a/pysyzygy/transit.py#L528-L535 | [
"def",
"Compute",
"(",
"self",
")",
":",
"err",
"=",
"_Compute",
"(",
"self",
".",
"transit",
",",
"self",
".",
"limbdark",
",",
"self",
".",
"settings",
",",
"self",
".",
"arrays",
")",
"if",
"err",
"!=",
"_ERR_NONE",
":",
"RaiseError",
"(",
"err",
")"
] | d2b64251047cc0f0d0adeb6feab4054e7fce4b7a |
test | Transit.Bin | Bins the light curve model to the provided time array | pysyzygy/transit.py | def Bin(self):
'''
Bins the light curve model to the provided time array
'''
err = _Bin(self.transit, self.limbdark, self.settings, self.arrays)
if err != _ERR_NONE: RaiseError(err) | def Bin(self):
'''
Bins the light curve model to the provided time array
'''
err = _Bin(self.transit, self.limbdark, self.settings, self.arrays)
if err != _ERR_NONE: RaiseError(err) | [
"Bins",
"the",
"light",
"curve",
"model",
"to",
"the",
"provided",
"time",
"array"
] | rodluger/pysyzygy | python | https://github.com/rodluger/pysyzygy/blob/d2b64251047cc0f0d0adeb6feab4054e7fce4b7a/pysyzygy/transit.py#L537-L544 | [
"def",
"Bin",
"(",
"self",
")",
":",
"err",
"=",
"_Bin",
"(",
"self",
".",
"transit",
",",
"self",
".",
"limbdark",
",",
"self",
".",
"settings",
",",
"self",
".",
"arrays",
")",
"if",
"err",
"!=",
"_ERR_NONE",
":",
"RaiseError",
"(",
"err",
")"
] | d2b64251047cc0f0d0adeb6feab4054e7fce4b7a |
test | Transit.Free | Frees the memory used by all of the dynamically allocated C arrays. | pysyzygy/transit.py | def Free(self):
'''
Frees the memory used by all of the dynamically allocated C arrays.
'''
if self.arrays._calloc:
_dbl_free(self.arrays._time)
_dbl_free(self.arrays._flux)
_dbl_free(self.arrays._bflx)
_dbl_free(self.arrays._M)
_dbl_free(self.arrays._E)
_dbl_free(self.arrays._f)
_dbl_free(self.arrays._r)
_dbl_free(self.arrays._x)
_dbl_free(self.arrays._y)
_dbl_free(self.arrays._z)
self.arrays._calloc = 0
if self.arrays._balloc:
_dbl_free(self.arrays._b)
self.arrays._balloc = 0
if self.arrays._ialloc:
_dbl_free(self.arrays._iarr)
self.arrays._ialloc = 0 | def Free(self):
'''
Frees the memory used by all of the dynamically allocated C arrays.
'''
if self.arrays._calloc:
_dbl_free(self.arrays._time)
_dbl_free(self.arrays._flux)
_dbl_free(self.arrays._bflx)
_dbl_free(self.arrays._M)
_dbl_free(self.arrays._E)
_dbl_free(self.arrays._f)
_dbl_free(self.arrays._r)
_dbl_free(self.arrays._x)
_dbl_free(self.arrays._y)
_dbl_free(self.arrays._z)
self.arrays._calloc = 0
if self.arrays._balloc:
_dbl_free(self.arrays._b)
self.arrays._balloc = 0
if self.arrays._ialloc:
_dbl_free(self.arrays._iarr)
self.arrays._ialloc = 0 | [
"Frees",
"the",
"memory",
"used",
"by",
"all",
"of",
"the",
"dynamically",
"allocated",
"C",
"arrays",
"."
] | rodluger/pysyzygy | python | https://github.com/rodluger/pysyzygy/blob/d2b64251047cc0f0d0adeb6feab4054e7fce4b7a/pysyzygy/transit.py#L546-L569 | [
"def",
"Free",
"(",
"self",
")",
":",
"if",
"self",
".",
"arrays",
".",
"_calloc",
":",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_time",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_flux",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_bflx",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_M",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_E",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_f",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_r",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_x",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_y",
")",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_z",
")",
"self",
".",
"arrays",
".",
"_calloc",
"=",
"0",
"if",
"self",
".",
"arrays",
".",
"_balloc",
":",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_b",
")",
"self",
".",
"arrays",
".",
"_balloc",
"=",
"0",
"if",
"self",
".",
"arrays",
".",
"_ialloc",
":",
"_dbl_free",
"(",
"self",
".",
"arrays",
".",
"_iarr",
")",
"self",
".",
"arrays",
".",
"_ialloc",
"=",
"0"
] | d2b64251047cc0f0d0adeb6feab4054e7fce4b7a |
test | BaseNNTPClient.__recv | Reads data from the socket.
Raises:
NNTPError: When connection times out or read from socket fails. | nntp/nntp.py | def __recv(self, size=4096):
"""Reads data from the socket.
Raises:
NNTPError: When connection times out or read from socket fails.
"""
data = self.socket.recv(size)
if not data:
raise NNTPError("Failed to read from socket")
self.__buffer.write(data) | def __recv(self, size=4096):
"""Reads data from the socket.
Raises:
NNTPError: When connection times out or read from socket fails.
"""
data = self.socket.recv(size)
if not data:
raise NNTPError("Failed to read from socket")
self.__buffer.write(data) | [
"Reads",
"data",
"from",
"the",
"socket",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L135-L144 | [
"def",
"__recv",
"(",
"self",
",",
"size",
"=",
"4096",
")",
":",
"data",
"=",
"self",
".",
"socket",
".",
"recv",
"(",
"size",
")",
"if",
"not",
"data",
":",
"raise",
"NNTPError",
"(",
"\"Failed to read from socket\"",
")",
"self",
".",
"__buffer",
".",
"write",
"(",
"data",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.__line_gen | Generator that reads a line of data from the server.
It first attempts to read from the internal buffer. If there is not
enough data to read a line it then requests more data from the server
and adds it to the buffer. This process repeats until a line of data
can be read from the internal buffer.
Yields:
A line of data when it becomes available. | nntp/nntp.py | def __line_gen(self):
"""Generator that reads a line of data from the server.
It first attempts to read from the internal buffer. If there is not
enough data to read a line it then requests more data from the server
and adds it to the buffer. This process repeats until a line of data
can be read from the internal buffer.
Yields:
A line of data when it becomes available.
"""
while True:
line = self.__buffer.readline()
if not line:
self.__recv()
continue
yield line | def __line_gen(self):
"""Generator that reads a line of data from the server.
It first attempts to read from the internal buffer. If there is not
enough data to read a line it then requests more data from the server
and adds it to the buffer. This process repeats until a line of data
can be read from the internal buffer.
Yields:
A line of data when it becomes available.
"""
while True:
line = self.__buffer.readline()
if not line:
self.__recv()
continue
yield line | [
"Generator",
"that",
"reads",
"a",
"line",
"of",
"data",
"from",
"the",
"server",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L146-L162 | [
"def",
"__line_gen",
"(",
"self",
")",
":",
"while",
"True",
":",
"line",
"=",
"self",
".",
"__buffer",
".",
"readline",
"(",
")",
"if",
"not",
"line",
":",
"self",
".",
"__recv",
"(",
")",
"continue",
"yield",
"line"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.__buf_gen | Generator that reads a block of data from the server.
It first attempts to read from the internal buffer. If there is not
enough data in the internal buffer it then requests more data from the
server and adds it to the buffer.
Args:
length: An optional amount of data to retrieve. A length of 0 (the
default) will retrieve a least one buffer of data.
Yields:
A block of data when enough data becomes available.
Note:
If a length of 0 is supplied then the size of the yielded buffer can
vary. If there is data in the internal buffer it will yield all of
that data otherwise it will yield the the data returned by a recv
on the socket. | nntp/nntp.py | def __buf_gen(self, length=0):
"""Generator that reads a block of data from the server.
It first attempts to read from the internal buffer. If there is not
enough data in the internal buffer it then requests more data from the
server and adds it to the buffer.
Args:
length: An optional amount of data to retrieve. A length of 0 (the
default) will retrieve a least one buffer of data.
Yields:
A block of data when enough data becomes available.
Note:
If a length of 0 is supplied then the size of the yielded buffer can
vary. If there is data in the internal buffer it will yield all of
that data otherwise it will yield the the data returned by a recv
on the socket.
"""
while True:
buf = self.__buffer.read(length)
if not buf:
self.__recv()
continue
yield buf | def __buf_gen(self, length=0):
"""Generator that reads a block of data from the server.
It first attempts to read from the internal buffer. If there is not
enough data in the internal buffer it then requests more data from the
server and adds it to the buffer.
Args:
length: An optional amount of data to retrieve. A length of 0 (the
default) will retrieve a least one buffer of data.
Yields:
A block of data when enough data becomes available.
Note:
If a length of 0 is supplied then the size of the yielded buffer can
vary. If there is data in the internal buffer it will yield all of
that data otherwise it will yield the the data returned by a recv
on the socket.
"""
while True:
buf = self.__buffer.read(length)
if not buf:
self.__recv()
continue
yield buf | [
"Generator",
"that",
"reads",
"a",
"block",
"of",
"data",
"from",
"the",
"server",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L164-L189 | [
"def",
"__buf_gen",
"(",
"self",
",",
"length",
"=",
"0",
")",
":",
"while",
"True",
":",
"buf",
"=",
"self",
".",
"__buffer",
".",
"read",
"(",
"length",
")",
"if",
"not",
"buf",
":",
"self",
".",
"__recv",
"(",
")",
"continue",
"yield",
"buf"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.status | Reads a command response status.
If there is no response message then the returned status message will
be an empty string.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPProtocolError: If the status line can't be parsed.
NNTPTemporaryError: For status code 400-499
NNTPPermanentError: For status code 500-599
Returns:
A tuple of status code (as an integer) and status message. | nntp/nntp.py | def status(self):
"""Reads a command response status.
If there is no response message then the returned status message will
be an empty string.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPProtocolError: If the status line can't be parsed.
NNTPTemporaryError: For status code 400-499
NNTPPermanentError: For status code 500-599
Returns:
A tuple of status code (as an integer) and status message.
"""
line = next(self.__line_gen()).rstrip()
parts = line.split(None, 1)
try:
code, message = int(parts[0]), ""
except ValueError:
raise NNTPProtocolError(line)
if code < 100 or code >= 600:
raise NNTPProtocolError(line)
if len(parts) > 1:
message = parts[1]
if 400 <= code <= 499:
raise NNTPTemporaryError(code, message)
if 500 <= code <= 599:
raise NNTPPermanentError(code, message)
return code, message | def status(self):
"""Reads a command response status.
If there is no response message then the returned status message will
be an empty string.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPProtocolError: If the status line can't be parsed.
NNTPTemporaryError: For status code 400-499
NNTPPermanentError: For status code 500-599
Returns:
A tuple of status code (as an integer) and status message.
"""
line = next(self.__line_gen()).rstrip()
parts = line.split(None, 1)
try:
code, message = int(parts[0]), ""
except ValueError:
raise NNTPProtocolError(line)
if code < 100 or code >= 600:
raise NNTPProtocolError(line)
if len(parts) > 1:
message = parts[1]
if 400 <= code <= 499:
raise NNTPTemporaryError(code, message)
if 500 <= code <= 599:
raise NNTPPermanentError(code, message)
return code, message | [
"Reads",
"a",
"command",
"response",
"status",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L191-L226 | [
"def",
"status",
"(",
"self",
")",
":",
"line",
"=",
"next",
"(",
"self",
".",
"__line_gen",
"(",
")",
")",
".",
"rstrip",
"(",
")",
"parts",
"=",
"line",
".",
"split",
"(",
"None",
",",
"1",
")",
"try",
":",
"code",
",",
"message",
"=",
"int",
"(",
"parts",
"[",
"0",
"]",
")",
",",
"\"\"",
"except",
"ValueError",
":",
"raise",
"NNTPProtocolError",
"(",
"line",
")",
"if",
"code",
"<",
"100",
"or",
"code",
">=",
"600",
":",
"raise",
"NNTPProtocolError",
"(",
"line",
")",
"if",
"len",
"(",
"parts",
")",
">",
"1",
":",
"message",
"=",
"parts",
"[",
"1",
"]",
"if",
"400",
"<=",
"code",
"<=",
"499",
":",
"raise",
"NNTPTemporaryError",
"(",
"code",
",",
"message",
")",
"if",
"500",
"<=",
"code",
"<=",
"599",
":",
"raise",
"NNTPPermanentError",
"(",
"code",
",",
"message",
")",
"return",
"code",
",",
"message"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.__info_plain_gen | Generator for the lines of an info (textual) response.
When a terminating line (line containing single period) is received the
generator exits.
If there is a line begining with an 'escaped' period then the extra
period is trimmed.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails. | nntp/nntp.py | def __info_plain_gen(self):
"""Generator for the lines of an info (textual) response.
When a terminating line (line containing single period) is received the
generator exits.
If there is a line begining with an 'escaped' period then the extra
period is trimmed.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails.
"""
self.__generating = True
for line in self.__line_gen():
if line == ".\r\n":
break
if line.startswith("."):
yield line[1:]
yield line
self.__generating = False | def __info_plain_gen(self):
"""Generator for the lines of an info (textual) response.
When a terminating line (line containing single period) is received the
generator exits.
If there is a line begining with an 'escaped' period then the extra
period is trimmed.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails.
"""
self.__generating = True
for line in self.__line_gen():
if line == ".\r\n":
break
if line.startswith("."):
yield line[1:]
yield line
self.__generating = False | [
"Generator",
"for",
"the",
"lines",
"of",
"an",
"info",
"(",
"textual",
")",
"response",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L228-L252 | [
"def",
"__info_plain_gen",
"(",
"self",
")",
":",
"self",
".",
"__generating",
"=",
"True",
"for",
"line",
"in",
"self",
".",
"__line_gen",
"(",
")",
":",
"if",
"line",
"==",
"\".\\r\\n\"",
":",
"break",
"if",
"line",
".",
"startswith",
"(",
"\".\"",
")",
":",
"yield",
"line",
"[",
"1",
":",
"]",
"yield",
"line",
"self",
".",
"__generating",
"=",
"False"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.__info_gzip_gen | Generator for the lines of a compressed info (textual) response.
Compressed responses are an extension to the NNTP protocol supported by
some usenet servers to reduce the bandwidth of heavily used range style
commands that can return large amounts of textual data.
This function handles gzip compressed responses that have the
terminating line inside or outside the compressed data. From experience
if the 'XFEATURE COMPRESS GZIP' command causes the terminating '.\\r\\n'
to follow the compressed data and 'XFEATURE COMPRESS GZIP TERMINATOR'
causes the terminator to be the last part of the compressed data (i.e
the reply the gzipped version of the original reply - terminating line
included)
This function will produce that same output as the __info_plain_gen()
function. In other words it takes care of decompression.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPDataError: If decompression fails. | nntp/nntp.py | def __info_gzip_gen(self):
"""Generator for the lines of a compressed info (textual) response.
Compressed responses are an extension to the NNTP protocol supported by
some usenet servers to reduce the bandwidth of heavily used range style
commands that can return large amounts of textual data.
This function handles gzip compressed responses that have the
terminating line inside or outside the compressed data. From experience
if the 'XFEATURE COMPRESS GZIP' command causes the terminating '.\\r\\n'
to follow the compressed data and 'XFEATURE COMPRESS GZIP TERMINATOR'
causes the terminator to be the last part of the compressed data (i.e
the reply the gzipped version of the original reply - terminating line
included)
This function will produce that same output as the __info_plain_gen()
function. In other words it takes care of decompression.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPDataError: If decompression fails.
"""
self.__generating = True
inflate = zlib.decompressobj(15+32)
done, buf = False, fifo.Fifo()
while not done:
try:
data = inflate.decompress(next(self.__buf_gen()))
except zlib.error:
raise NNTPDataError("Decompression failed")
if data:
buf.write(data)
if inflate.unused_data:
buf.write(inflate.unused_data)
for line in buf:
if line == ".\r\n":
done = True
break
if line.startswith("."):
yield line[1:]
yield line
self.__generating = False | def __info_gzip_gen(self):
"""Generator for the lines of a compressed info (textual) response.
Compressed responses are an extension to the NNTP protocol supported by
some usenet servers to reduce the bandwidth of heavily used range style
commands that can return large amounts of textual data.
This function handles gzip compressed responses that have the
terminating line inside or outside the compressed data. From experience
if the 'XFEATURE COMPRESS GZIP' command causes the terminating '.\\r\\n'
to follow the compressed data and 'XFEATURE COMPRESS GZIP TERMINATOR'
causes the terminator to be the last part of the compressed data (i.e
the reply the gzipped version of the original reply - terminating line
included)
This function will produce that same output as the __info_plain_gen()
function. In other words it takes care of decompression.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPDataError: If decompression fails.
"""
self.__generating = True
inflate = zlib.decompressobj(15+32)
done, buf = False, fifo.Fifo()
while not done:
try:
data = inflate.decompress(next(self.__buf_gen()))
except zlib.error:
raise NNTPDataError("Decompression failed")
if data:
buf.write(data)
if inflate.unused_data:
buf.write(inflate.unused_data)
for line in buf:
if line == ".\r\n":
done = True
break
if line.startswith("."):
yield line[1:]
yield line
self.__generating = False | [
"Generator",
"for",
"the",
"lines",
"of",
"a",
"compressed",
"info",
"(",
"textual",
")",
"response",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L254-L301 | [
"def",
"__info_gzip_gen",
"(",
"self",
")",
":",
"self",
".",
"__generating",
"=",
"True",
"inflate",
"=",
"zlib",
".",
"decompressobj",
"(",
"15",
"+",
"32",
")",
"done",
",",
"buf",
"=",
"False",
",",
"fifo",
".",
"Fifo",
"(",
")",
"while",
"not",
"done",
":",
"try",
":",
"data",
"=",
"inflate",
".",
"decompress",
"(",
"next",
"(",
"self",
".",
"__buf_gen",
"(",
")",
")",
")",
"except",
"zlib",
".",
"error",
":",
"raise",
"NNTPDataError",
"(",
"\"Decompression failed\"",
")",
"if",
"data",
":",
"buf",
".",
"write",
"(",
"data",
")",
"if",
"inflate",
".",
"unused_data",
":",
"buf",
".",
"write",
"(",
"inflate",
".",
"unused_data",
")",
"for",
"line",
"in",
"buf",
":",
"if",
"line",
"==",
"\".\\r\\n\"",
":",
"done",
"=",
"True",
"break",
"if",
"line",
".",
"startswith",
"(",
"\".\"",
")",
":",
"yield",
"line",
"[",
"1",
":",
"]",
"yield",
"line",
"self",
".",
"__generating",
"=",
"False"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.__info_yenczlib_gen | Generator for the lines of a compressed info (textual) response.
Compressed responses are an extension to the NNTP protocol supported by
some usenet servers to reduce the bandwidth of heavily used range style
commands that can return large amounts of textual data. The server
returns that same data as it would for the uncompressed versions of the
command the difference being that the data is zlib deflated and then
yEnc encoded.
This function will produce that same output as the info_gen()
function. In other words it takes care of decoding and decompression.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPDataError: When there is an error parsing the yEnc header or
trailer, if the CRC check fails or decompressing data fails. | nntp/nntp.py | def __info_yenczlib_gen(self):
"""Generator for the lines of a compressed info (textual) response.
Compressed responses are an extension to the NNTP protocol supported by
some usenet servers to reduce the bandwidth of heavily used range style
commands that can return large amounts of textual data. The server
returns that same data as it would for the uncompressed versions of the
command the difference being that the data is zlib deflated and then
yEnc encoded.
This function will produce that same output as the info_gen()
function. In other words it takes care of decoding and decompression.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPDataError: When there is an error parsing the yEnc header or
trailer, if the CRC check fails or decompressing data fails.
"""
escape = 0
dcrc32 = 0
inflate = zlib.decompressobj(-15)
# header
header = next(self.__info_plain_gen())
if not header.startswith("=ybegin"):
raise NNTPDataError("Bad yEnc header")
# data
buf, trailer = fifo.Fifo(), ""
for line in self.__info_plain_gen():
if line.startswith("=yend"):
trailer = line
continue
data, escape, dcrc32 = yenc.decode(line, escape, dcrc32)
try:
data = inflate.decompress(data)
except zlib.error:
raise NNTPDataError("Decompression failed")
if not data:
continue
buf.write(data)
for l in buf:
yield l
# trailer
if not trailer:
raise NNTPDataError("Missing yEnc trailer")
# expected crc32
ecrc32 = yenc.crc32(trailer)
if ecrc32 is None:
raise NNTPDataError("Bad yEnc trailer")
# check crc32
if ecrc32 != dcrc32 & 0xffffffff:
raise NNTPDataError("Bad yEnc CRC") | def __info_yenczlib_gen(self):
"""Generator for the lines of a compressed info (textual) response.
Compressed responses are an extension to the NNTP protocol supported by
some usenet servers to reduce the bandwidth of heavily used range style
commands that can return large amounts of textual data. The server
returns that same data as it would for the uncompressed versions of the
command the difference being that the data is zlib deflated and then
yEnc encoded.
This function will produce that same output as the info_gen()
function. In other words it takes care of decoding and decompression.
Yields:
A line of the info response.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPDataError: When there is an error parsing the yEnc header or
trailer, if the CRC check fails or decompressing data fails.
"""
escape = 0
dcrc32 = 0
inflate = zlib.decompressobj(-15)
# header
header = next(self.__info_plain_gen())
if not header.startswith("=ybegin"):
raise NNTPDataError("Bad yEnc header")
# data
buf, trailer = fifo.Fifo(), ""
for line in self.__info_plain_gen():
if line.startswith("=yend"):
trailer = line
continue
data, escape, dcrc32 = yenc.decode(line, escape, dcrc32)
try:
data = inflate.decompress(data)
except zlib.error:
raise NNTPDataError("Decompression failed")
if not data:
continue
buf.write(data)
for l in buf:
yield l
# trailer
if not trailer:
raise NNTPDataError("Missing yEnc trailer")
# expected crc32
ecrc32 = yenc.crc32(trailer)
if ecrc32 is None:
raise NNTPDataError("Bad yEnc trailer")
# check crc32
if ecrc32 != dcrc32 & 0xffffffff:
raise NNTPDataError("Bad yEnc CRC") | [
"Generator",
"for",
"the",
"lines",
"of",
"a",
"compressed",
"info",
"(",
"textual",
")",
"response",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L303-L362 | [
"def",
"__info_yenczlib_gen",
"(",
"self",
")",
":",
"escape",
"=",
"0",
"dcrc32",
"=",
"0",
"inflate",
"=",
"zlib",
".",
"decompressobj",
"(",
"-",
"15",
")",
"# header",
"header",
"=",
"next",
"(",
"self",
".",
"__info_plain_gen",
"(",
")",
")",
"if",
"not",
"header",
".",
"startswith",
"(",
"\"=ybegin\"",
")",
":",
"raise",
"NNTPDataError",
"(",
"\"Bad yEnc header\"",
")",
"# data",
"buf",
",",
"trailer",
"=",
"fifo",
".",
"Fifo",
"(",
")",
",",
"\"\"",
"for",
"line",
"in",
"self",
".",
"__info_plain_gen",
"(",
")",
":",
"if",
"line",
".",
"startswith",
"(",
"\"=yend\"",
")",
":",
"trailer",
"=",
"line",
"continue",
"data",
",",
"escape",
",",
"dcrc32",
"=",
"yenc",
".",
"decode",
"(",
"line",
",",
"escape",
",",
"dcrc32",
")",
"try",
":",
"data",
"=",
"inflate",
".",
"decompress",
"(",
"data",
")",
"except",
"zlib",
".",
"error",
":",
"raise",
"NNTPDataError",
"(",
"\"Decompression failed\"",
")",
"if",
"not",
"data",
":",
"continue",
"buf",
".",
"write",
"(",
"data",
")",
"for",
"l",
"in",
"buf",
":",
"yield",
"l",
"# trailer",
"if",
"not",
"trailer",
":",
"raise",
"NNTPDataError",
"(",
"\"Missing yEnc trailer\"",
")",
"# expected crc32",
"ecrc32",
"=",
"yenc",
".",
"crc32",
"(",
"trailer",
")",
"if",
"ecrc32",
"is",
"None",
":",
"raise",
"NNTPDataError",
"(",
"\"Bad yEnc trailer\"",
")",
"# check crc32",
"if",
"ecrc32",
"!=",
"dcrc32",
"&",
"0xffffffff",
":",
"raise",
"NNTPDataError",
"(",
"\"Bad yEnc CRC\"",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.info_gen | Dispatcher for the info generators.
Determines which __info_*_gen() should be used based on the supplied
parameters.
Args:
code: The status code for the command response.
message: The status message for the command reponse.
compressed: Force decompression. Useful for xz* commands.
Returns:
An info generator. | nntp/nntp.py | def info_gen(self, code, message, compressed=False):
"""Dispatcher for the info generators.
Determines which __info_*_gen() should be used based on the supplied
parameters.
Args:
code: The status code for the command response.
message: The status message for the command reponse.
compressed: Force decompression. Useful for xz* commands.
Returns:
An info generator.
"""
if "COMPRESS=GZIP" in message:
return self.__info_gzip_gen()
if compressed:
return self.__info_yenczlib_gen()
return self.__info_plain_gen() | def info_gen(self, code, message, compressed=False):
"""Dispatcher for the info generators.
Determines which __info_*_gen() should be used based on the supplied
parameters.
Args:
code: The status code for the command response.
message: The status message for the command reponse.
compressed: Force decompression. Useful for xz* commands.
Returns:
An info generator.
"""
if "COMPRESS=GZIP" in message:
return self.__info_gzip_gen()
if compressed:
return self.__info_yenczlib_gen()
return self.__info_plain_gen() | [
"Dispatcher",
"for",
"the",
"info",
"generators",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L364-L382 | [
"def",
"info_gen",
"(",
"self",
",",
"code",
",",
"message",
",",
"compressed",
"=",
"False",
")",
":",
"if",
"\"COMPRESS=GZIP\"",
"in",
"message",
":",
"return",
"self",
".",
"__info_gzip_gen",
"(",
")",
"if",
"compressed",
":",
"return",
"self",
".",
"__info_yenczlib_gen",
"(",
")",
"return",
"self",
".",
"__info_plain_gen",
"(",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.info | The complete content of an info response.
This should only used for commands that return small or known amounts of
data.
Returns:
A the complete content of a textual response. | nntp/nntp.py | def info(self, code, message, compressed=False):
"""The complete content of an info response.
This should only used for commands that return small or known amounts of
data.
Returns:
A the complete content of a textual response.
"""
return "".join([x for x in self.info_gen(code, message, compressed)]) | def info(self, code, message, compressed=False):
"""The complete content of an info response.
This should only used for commands that return small or known amounts of
data.
Returns:
A the complete content of a textual response.
"""
return "".join([x for x in self.info_gen(code, message, compressed)]) | [
"The",
"complete",
"content",
"of",
"an",
"info",
"response",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L384-L393 | [
"def",
"info",
"(",
"self",
",",
"code",
",",
"message",
",",
"compressed",
"=",
"False",
")",
":",
"return",
"\"\"",
".",
"join",
"(",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
",",
"compressed",
")",
"]",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | BaseNNTPClient.command | Call a command on the server.
If the user has not authenticated then authentication will be done
as part of calling the command on the server.
For commands that don't return a status message the status message
will default to an empty string.
Args:
verb: The verb of the command to call.
args: The arguments of the command as a string (default None).
Returns:
A tuple of status code (as an integer) and status message.
Note:
You can run raw commands by supplying the full command (including
args) in the verb.
Note: Although it is possible you shouldn't issue more than one command
at a time by adding newlines to the verb as it will most likely lead
to undesirable results. | nntp/nntp.py | def command(self, verb, args=None):
"""Call a command on the server.
If the user has not authenticated then authentication will be done
as part of calling the command on the server.
For commands that don't return a status message the status message
will default to an empty string.
Args:
verb: The verb of the command to call.
args: The arguments of the command as a string (default None).
Returns:
A tuple of status code (as an integer) and status message.
Note:
You can run raw commands by supplying the full command (including
args) in the verb.
Note: Although it is possible you shouldn't issue more than one command
at a time by adding newlines to the verb as it will most likely lead
to undesirable results.
"""
if self.__generating:
raise NNTPSyncError("Command issued while a generator is active")
cmd = verb
if args:
cmd += " " + args
cmd += "\r\n"
self.socket.sendall(cmd)
try:
code, message = self.status()
except NNTPTemporaryError as e:
if e.code() != 480:
raise e
code, message = self.command("AUTHINFO USER", self.username)
if code == 381:
code, message = self.command("AUTHINFO PASS", self.password)
if code != 281:
raise NNTPReplyError(code, message)
code, message = self.command(verb, args)
return code, message | def command(self, verb, args=None):
"""Call a command on the server.
If the user has not authenticated then authentication will be done
as part of calling the command on the server.
For commands that don't return a status message the status message
will default to an empty string.
Args:
verb: The verb of the command to call.
args: The arguments of the command as a string (default None).
Returns:
A tuple of status code (as an integer) and status message.
Note:
You can run raw commands by supplying the full command (including
args) in the verb.
Note: Although it is possible you shouldn't issue more than one command
at a time by adding newlines to the verb as it will most likely lead
to undesirable results.
"""
if self.__generating:
raise NNTPSyncError("Command issued while a generator is active")
cmd = verb
if args:
cmd += " " + args
cmd += "\r\n"
self.socket.sendall(cmd)
try:
code, message = self.status()
except NNTPTemporaryError as e:
if e.code() != 480:
raise e
code, message = self.command("AUTHINFO USER", self.username)
if code == 381:
code, message = self.command("AUTHINFO PASS", self.password)
if code != 281:
raise NNTPReplyError(code, message)
code, message = self.command(verb, args)
return code, message | [
"Call",
"a",
"command",
"on",
"the",
"server",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L395-L441 | [
"def",
"command",
"(",
"self",
",",
"verb",
",",
"args",
"=",
"None",
")",
":",
"if",
"self",
".",
"__generating",
":",
"raise",
"NNTPSyncError",
"(",
"\"Command issued while a generator is active\"",
")",
"cmd",
"=",
"verb",
"if",
"args",
":",
"cmd",
"+=",
"\" \"",
"+",
"args",
"cmd",
"+=",
"\"\\r\\n\"",
"self",
".",
"socket",
".",
"sendall",
"(",
"cmd",
")",
"try",
":",
"code",
",",
"message",
"=",
"self",
".",
"status",
"(",
")",
"except",
"NNTPTemporaryError",
"as",
"e",
":",
"if",
"e",
".",
"code",
"(",
")",
"!=",
"480",
":",
"raise",
"e",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"AUTHINFO USER\"",
",",
"self",
".",
"username",
")",
"if",
"code",
"==",
"381",
":",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"AUTHINFO PASS\"",
",",
"self",
".",
"password",
")",
"if",
"code",
"!=",
"281",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"verb",
",",
"args",
")",
"return",
"code",
",",
"message"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.capabilities | CAPABILITIES command.
Determines the capabilities of the server.
Although RFC3977 states that this is a required command for servers to
implement not all servers do, so expect that NNTPPermanentError may be
raised when this command is issued.
See <http://tools.ietf.org/html/rfc3977#section-5.2>
Args:
keyword: Passed directly to the server, however, this is unused by
the server according to RFC3977.
Returns:
A list of capabilities supported by the server. The VERSION
capability is the first capability in the list. | nntp/nntp.py | def capabilities(self, keyword=None):
"""CAPABILITIES command.
Determines the capabilities of the server.
Although RFC3977 states that this is a required command for servers to
implement not all servers do, so expect that NNTPPermanentError may be
raised when this command is issued.
See <http://tools.ietf.org/html/rfc3977#section-5.2>
Args:
keyword: Passed directly to the server, however, this is unused by
the server according to RFC3977.
Returns:
A list of capabilities supported by the server. The VERSION
capability is the first capability in the list.
"""
args = keyword
code, message = self.command("CAPABILITIES", args)
if code != 101:
raise NNTPReplyError(code, message)
return [x.strip() for x in self.info_gen(code, message)] | def capabilities(self, keyword=None):
"""CAPABILITIES command.
Determines the capabilities of the server.
Although RFC3977 states that this is a required command for servers to
implement not all servers do, so expect that NNTPPermanentError may be
raised when this command is issued.
See <http://tools.ietf.org/html/rfc3977#section-5.2>
Args:
keyword: Passed directly to the server, however, this is unused by
the server according to RFC3977.
Returns:
A list of capabilities supported by the server. The VERSION
capability is the first capability in the list.
"""
args = keyword
code, message = self.command("CAPABILITIES", args)
if code != 101:
raise NNTPReplyError(code, message)
return [x.strip() for x in self.info_gen(code, message)] | [
"CAPABILITIES",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L505-L530 | [
"def",
"capabilities",
"(",
"self",
",",
"keyword",
"=",
"None",
")",
":",
"args",
"=",
"keyword",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"CAPABILITIES\"",
",",
"args",
")",
"if",
"code",
"!=",
"101",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"return",
"[",
"x",
".",
"strip",
"(",
")",
"for",
"x",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
")",
"]"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.mode_reader | MODE READER command.
Instructs a mode-switching server to switch modes.
See <http://tools.ietf.org/html/rfc3977#section-5.3>
Returns:
Boolean value indicating whether posting is allowed or not. | nntp/nntp.py | def mode_reader(self):
"""MODE READER command.
Instructs a mode-switching server to switch modes.
See <http://tools.ietf.org/html/rfc3977#section-5.3>
Returns:
Boolean value indicating whether posting is allowed or not.
"""
code, message = self.command("MODE READER")
if not code in [200, 201]:
raise NNTPReplyError(code, message)
return code == 200 | def mode_reader(self):
"""MODE READER command.
Instructs a mode-switching server to switch modes.
See <http://tools.ietf.org/html/rfc3977#section-5.3>
Returns:
Boolean value indicating whether posting is allowed or not.
"""
code, message = self.command("MODE READER")
if not code in [200, 201]:
raise NNTPReplyError(code, message)
return code == 200 | [
"MODE",
"READER",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L532-L546 | [
"def",
"mode_reader",
"(",
"self",
")",
":",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"MODE READER\"",
")",
"if",
"not",
"code",
"in",
"[",
"200",
",",
"201",
"]",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"return",
"code",
"==",
"200"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.quit | QUIT command.
Tells the server to close the connection. After the server acknowledges
the request to quit the connection is closed both at the server and
client. Only useful for graceful shutdown. If you are in a generator
use close() instead.
Once this method has been called, no other methods of the NNTPClient
object should be called.
See <http://tools.ietf.org/html/rfc3977#section-5.4> | nntp/nntp.py | def quit(self):
"""QUIT command.
Tells the server to close the connection. After the server acknowledges
the request to quit the connection is closed both at the server and
client. Only useful for graceful shutdown. If you are in a generator
use close() instead.
Once this method has been called, no other methods of the NNTPClient
object should be called.
See <http://tools.ietf.org/html/rfc3977#section-5.4>
"""
code, message = self.command("QUIT")
if code != 205:
raise NNTPReplyError(code, message)
self.socket.close() | def quit(self):
"""QUIT command.
Tells the server to close the connection. After the server acknowledges
the request to quit the connection is closed both at the server and
client. Only useful for graceful shutdown. If you are in a generator
use close() instead.
Once this method has been called, no other methods of the NNTPClient
object should be called.
See <http://tools.ietf.org/html/rfc3977#section-5.4>
"""
code, message = self.command("QUIT")
if code != 205:
raise NNTPReplyError(code, message)
self.socket.close() | [
"QUIT",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L548-L565 | [
"def",
"quit",
"(",
"self",
")",
":",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"QUIT\"",
")",
"if",
"code",
"!=",
"205",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"self",
".",
"socket",
".",
"close",
"(",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.date | DATE command.
Coordinated Universal time from the perspective of the usenet server.
It can be used to provide information that might be useful when using
the NEWNEWS command.
See <http://tools.ietf.org/html/rfc3977#section-7.1>
Returns:
The UTC time according to the server as a datetime object.
Raises:
NNTPDataError: If the timestamp can't be parsed. | nntp/nntp.py | def date(self):
"""DATE command.
Coordinated Universal time from the perspective of the usenet server.
It can be used to provide information that might be useful when using
the NEWNEWS command.
See <http://tools.ietf.org/html/rfc3977#section-7.1>
Returns:
The UTC time according to the server as a datetime object.
Raises:
NNTPDataError: If the timestamp can't be parsed.
"""
code, message = self.command("DATE")
if code != 111:
raise NNTPReplyError(code, message)
ts = date.datetimeobj(message, fmt="%Y%m%d%H%M%S")
return ts | def date(self):
"""DATE command.
Coordinated Universal time from the perspective of the usenet server.
It can be used to provide information that might be useful when using
the NEWNEWS command.
See <http://tools.ietf.org/html/rfc3977#section-7.1>
Returns:
The UTC time according to the server as a datetime object.
Raises:
NNTPDataError: If the timestamp can't be parsed.
"""
code, message = self.command("DATE")
if code != 111:
raise NNTPReplyError(code, message)
ts = date.datetimeobj(message, fmt="%Y%m%d%H%M%S")
return ts | [
"DATE",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L570-L591 | [
"def",
"date",
"(",
"self",
")",
":",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"DATE\"",
")",
"if",
"code",
"!=",
"111",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"ts",
"=",
"date",
".",
"datetimeobj",
"(",
"message",
",",
"fmt",
"=",
"\"%Y%m%d%H%M%S\"",
")",
"return",
"ts"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.help | HELP command.
Provides a short summary of commands that are understood by the usenet
server.
See <http://tools.ietf.org/html/rfc3977#section-7.2>
Returns:
The help text from the server. | nntp/nntp.py | def help(self):
"""HELP command.
Provides a short summary of commands that are understood by the usenet
server.
See <http://tools.ietf.org/html/rfc3977#section-7.2>
Returns:
The help text from the server.
"""
code, message = self.command("HELP")
if code != 100:
raise NNTPReplyError(code, message)
return self.info(code, message) | def help(self):
"""HELP command.
Provides a short summary of commands that are understood by the usenet
server.
See <http://tools.ietf.org/html/rfc3977#section-7.2>
Returns:
The help text from the server.
"""
code, message = self.command("HELP")
if code != 100:
raise NNTPReplyError(code, message)
return self.info(code, message) | [
"HELP",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L593-L608 | [
"def",
"help",
"(",
"self",
")",
":",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"HELP\"",
")",
"if",
"code",
"!=",
"100",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"return",
"self",
".",
"info",
"(",
"code",
",",
"message",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.newgroups_gen | Generator for the NEWGROUPS command.
Generates a list of newsgroups created on the server since the specified
timestamp.
See <http://tools.ietf.org/html/rfc3977#section-7.3>
Args:
timestamp: Datetime object giving 'created since' datetime.
Yields:
A tuple containing the name, low water mark, high water mark,
and status for the newsgroup.
Note: If the datetime object supplied as the timestamp is naive (tzinfo
is None) then it is assumed to be given as GMT. | nntp/nntp.py | def newgroups_gen(self, timestamp):
"""Generator for the NEWGROUPS command.
Generates a list of newsgroups created on the server since the specified
timestamp.
See <http://tools.ietf.org/html/rfc3977#section-7.3>
Args:
timestamp: Datetime object giving 'created since' datetime.
Yields:
A tuple containing the name, low water mark, high water mark,
and status for the newsgroup.
Note: If the datetime object supplied as the timestamp is naive (tzinfo
is None) then it is assumed to be given as GMT.
"""
if timestamp.tzinfo:
ts = timestamp.asttimezone(date.TZ_GMT)
else:
ts = timestamp.replace(tzinfo=date.TZ_GMT)
args = ts.strftime("%Y%m%d %H%M%S %Z")
code, message = self.command("NEWGROUPS", args)
if code != 231:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
yield utils.parse_newsgroup(line) | def newgroups_gen(self, timestamp):
"""Generator for the NEWGROUPS command.
Generates a list of newsgroups created on the server since the specified
timestamp.
See <http://tools.ietf.org/html/rfc3977#section-7.3>
Args:
timestamp: Datetime object giving 'created since' datetime.
Yields:
A tuple containing the name, low water mark, high water mark,
and status for the newsgroup.
Note: If the datetime object supplied as the timestamp is naive (tzinfo
is None) then it is assumed to be given as GMT.
"""
if timestamp.tzinfo:
ts = timestamp.asttimezone(date.TZ_GMT)
else:
ts = timestamp.replace(tzinfo=date.TZ_GMT)
args = ts.strftime("%Y%m%d %H%M%S %Z")
code, message = self.command("NEWGROUPS", args)
if code != 231:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
yield utils.parse_newsgroup(line) | [
"Generator",
"for",
"the",
"NEWGROUPS",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L610-L640 | [
"def",
"newgroups_gen",
"(",
"self",
",",
"timestamp",
")",
":",
"if",
"timestamp",
".",
"tzinfo",
":",
"ts",
"=",
"timestamp",
".",
"asttimezone",
"(",
"date",
".",
"TZ_GMT",
")",
"else",
":",
"ts",
"=",
"timestamp",
".",
"replace",
"(",
"tzinfo",
"=",
"date",
".",
"TZ_GMT",
")",
"args",
"=",
"ts",
".",
"strftime",
"(",
"\"%Y%m%d %H%M%S %Z\"",
")",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"NEWGROUPS\"",
",",
"args",
")",
"if",
"code",
"!=",
"231",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"for",
"line",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
")",
":",
"yield",
"utils",
".",
"parse_newsgroup",
"(",
"line",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.newnews_gen | Generator for the NEWNEWS command.
Generates a list of message-ids for articles created since the specified
timestamp for newsgroups with names that match the given pattern.
See <http://tools.ietf.org/html/rfc3977#section-7.4>
Args:
pattern: Glob matching newsgroups of intrest.
timestamp: Datetime object giving 'created since' datetime.
Yields:
A message-id as string.
Note: If the datetime object supplied as the timestamp is naive (tzinfo
is None) then it is assumed to be given as GMT. If tzinfo is set
then it will be converted to GMT by this function. | nntp/nntp.py | def newnews_gen(self, pattern, timestamp):
"""Generator for the NEWNEWS command.
Generates a list of message-ids for articles created since the specified
timestamp for newsgroups with names that match the given pattern.
See <http://tools.ietf.org/html/rfc3977#section-7.4>
Args:
pattern: Glob matching newsgroups of intrest.
timestamp: Datetime object giving 'created since' datetime.
Yields:
A message-id as string.
Note: If the datetime object supplied as the timestamp is naive (tzinfo
is None) then it is assumed to be given as GMT. If tzinfo is set
then it will be converted to GMT by this function.
"""
if timestamp.tzinfo:
ts = timestamp.asttimezone(date.TZ_GMT)
else:
ts = timestamp.replace(tzinfo=date.TZ_GMT)
args = pattern
args += " " + ts.strftime("%Y%m%d %H%M%S %Z")
code, message = self.command("NEWNEWS", args)
if code != 230:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
yield line.strip() | def newnews_gen(self, pattern, timestamp):
"""Generator for the NEWNEWS command.
Generates a list of message-ids for articles created since the specified
timestamp for newsgroups with names that match the given pattern.
See <http://tools.ietf.org/html/rfc3977#section-7.4>
Args:
pattern: Glob matching newsgroups of intrest.
timestamp: Datetime object giving 'created since' datetime.
Yields:
A message-id as string.
Note: If the datetime object supplied as the timestamp is naive (tzinfo
is None) then it is assumed to be given as GMT. If tzinfo is set
then it will be converted to GMT by this function.
"""
if timestamp.tzinfo:
ts = timestamp.asttimezone(date.TZ_GMT)
else:
ts = timestamp.replace(tzinfo=date.TZ_GMT)
args = pattern
args += " " + ts.strftime("%Y%m%d %H%M%S %Z")
code, message = self.command("NEWNEWS", args)
if code != 230:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
yield line.strip() | [
"Generator",
"for",
"the",
"NEWNEWS",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L658-L690 | [
"def",
"newnews_gen",
"(",
"self",
",",
"pattern",
",",
"timestamp",
")",
":",
"if",
"timestamp",
".",
"tzinfo",
":",
"ts",
"=",
"timestamp",
".",
"asttimezone",
"(",
"date",
".",
"TZ_GMT",
")",
"else",
":",
"ts",
"=",
"timestamp",
".",
"replace",
"(",
"tzinfo",
"=",
"date",
".",
"TZ_GMT",
")",
"args",
"=",
"pattern",
"args",
"+=",
"\" \"",
"+",
"ts",
".",
"strftime",
"(",
"\"%Y%m%d %H%M%S %Z\"",
")",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"NEWNEWS\"",
",",
"args",
")",
"if",
"code",
"!=",
"230",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"for",
"line",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
")",
":",
"yield",
"line",
".",
"strip",
"(",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.newnews | NEWNEWS command.
Retrieves a list of message-ids for articles created since the specified
timestamp for newsgroups with names that match the given pattern. See
newnews_gen() for more details.
See <http://tools.ietf.org/html/rfc3977#section-7.4>
Args:
pattern: Glob matching newsgroups of intrest.
timestamp: Datetime object giving 'created since' datetime.
Returns:
A list of message-ids as given by newnews_gen() | nntp/nntp.py | def newnews(self, pattern, timestamp):
"""NEWNEWS command.
Retrieves a list of message-ids for articles created since the specified
timestamp for newsgroups with names that match the given pattern. See
newnews_gen() for more details.
See <http://tools.ietf.org/html/rfc3977#section-7.4>
Args:
pattern: Glob matching newsgroups of intrest.
timestamp: Datetime object giving 'created since' datetime.
Returns:
A list of message-ids as given by newnews_gen()
"""
return [x for x in self.newnews_gen(pattern, timestamp)] | def newnews(self, pattern, timestamp):
"""NEWNEWS command.
Retrieves a list of message-ids for articles created since the specified
timestamp for newsgroups with names that match the given pattern. See
newnews_gen() for more details.
See <http://tools.ietf.org/html/rfc3977#section-7.4>
Args:
pattern: Glob matching newsgroups of intrest.
timestamp: Datetime object giving 'created since' datetime.
Returns:
A list of message-ids as given by newnews_gen()
"""
return [x for x in self.newnews_gen(pattern, timestamp)] | [
"NEWNEWS",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L692-L708 | [
"def",
"newnews",
"(",
"self",
",",
"pattern",
",",
"timestamp",
")",
":",
"return",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"newnews_gen",
"(",
"pattern",
",",
"timestamp",
")",
"]"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.list_active_gen | Generator for the LIST ACTIVE command.
Generates a list of active newsgroups that match the specified pattern.
If no pattern is specfied then all active groups are generated.
See <http://tools.ietf.org/html/rfc3977#section-7.6.3>
Args:
pattern: Glob matching newsgroups of intrest.
Yields:
A tuple containing the name, low water mark, high water mark,
and status for the newsgroup. | nntp/nntp.py | def list_active_gen(self, pattern=None):
"""Generator for the LIST ACTIVE command.
Generates a list of active newsgroups that match the specified pattern.
If no pattern is specfied then all active groups are generated.
See <http://tools.ietf.org/html/rfc3977#section-7.6.3>
Args:
pattern: Glob matching newsgroups of intrest.
Yields:
A tuple containing the name, low water mark, high water mark,
and status for the newsgroup.
"""
args = pattern
if args is None:
cmd = "LIST"
else:
cmd = "LIST ACTIVE"
code, message = self.command(cmd, args)
if code != 215:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
yield utils.parse_newsgroup(line) | def list_active_gen(self, pattern=None):
"""Generator for the LIST ACTIVE command.
Generates a list of active newsgroups that match the specified pattern.
If no pattern is specfied then all active groups are generated.
See <http://tools.ietf.org/html/rfc3977#section-7.6.3>
Args:
pattern: Glob matching newsgroups of intrest.
Yields:
A tuple containing the name, low water mark, high water mark,
and status for the newsgroup.
"""
args = pattern
if args is None:
cmd = "LIST"
else:
cmd = "LIST ACTIVE"
code, message = self.command(cmd, args)
if code != 215:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
yield utils.parse_newsgroup(line) | [
"Generator",
"for",
"the",
"LIST",
"ACTIVE",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L713-L740 | [
"def",
"list_active_gen",
"(",
"self",
",",
"pattern",
"=",
"None",
")",
":",
"args",
"=",
"pattern",
"if",
"args",
"is",
"None",
":",
"cmd",
"=",
"\"LIST\"",
"else",
":",
"cmd",
"=",
"\"LIST ACTIVE\"",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"cmd",
",",
"args",
")",
"if",
"code",
"!=",
"215",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"for",
"line",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
")",
":",
"yield",
"utils",
".",
"parse_newsgroup",
"(",
"line",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.list_active_times_gen | Generator for the LIST ACTIVE.TIMES command.
Generates a list of newsgroups including the creation time and who
created them.
See <http://tools.ietf.org/html/rfc3977#section-7.6.4>
Yields:
A tuple containing the name, creation date as a datetime object and
creator as a string for the newsgroup. | nntp/nntp.py | def list_active_times_gen(self):
"""Generator for the LIST ACTIVE.TIMES command.
Generates a list of newsgroups including the creation time and who
created them.
See <http://tools.ietf.org/html/rfc3977#section-7.6.4>
Yields:
A tuple containing the name, creation date as a datetime object and
creator as a string for the newsgroup.
"""
code, message = self.command("LIST ACTIVE.TIMES")
if code != 215:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
parts = line.split()
try:
name = parts[0]
timestamp = date.datetimeobj_epoch(parts[1])
creator = parts[2]
except (IndexError, ValueError):
raise NNTPDataError("Invalid LIST ACTIVE.TIMES")
yield name, timestamp, creator | def list_active_times_gen(self):
"""Generator for the LIST ACTIVE.TIMES command.
Generates a list of newsgroups including the creation time and who
created them.
See <http://tools.ietf.org/html/rfc3977#section-7.6.4>
Yields:
A tuple containing the name, creation date as a datetime object and
creator as a string for the newsgroup.
"""
code, message = self.command("LIST ACTIVE.TIMES")
if code != 215:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
parts = line.split()
try:
name = parts[0]
timestamp = date.datetimeobj_epoch(parts[1])
creator = parts[2]
except (IndexError, ValueError):
raise NNTPDataError("Invalid LIST ACTIVE.TIMES")
yield name, timestamp, creator | [
"Generator",
"for",
"the",
"LIST",
"ACTIVE",
".",
"TIMES",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L758-L782 | [
"def",
"list_active_times_gen",
"(",
"self",
")",
":",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"LIST ACTIVE.TIMES\"",
")",
"if",
"code",
"!=",
"215",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"for",
"line",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
")",
":",
"parts",
"=",
"line",
".",
"split",
"(",
")",
"try",
":",
"name",
"=",
"parts",
"[",
"0",
"]",
"timestamp",
"=",
"date",
".",
"datetimeobj_epoch",
"(",
"parts",
"[",
"1",
"]",
")",
"creator",
"=",
"parts",
"[",
"2",
"]",
"except",
"(",
"IndexError",
",",
"ValueError",
")",
":",
"raise",
"NNTPDataError",
"(",
"\"Invalid LIST ACTIVE.TIMES\"",
")",
"yield",
"name",
",",
"timestamp",
",",
"creator"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.list_newsgroups_gen | Generator for the LIST NEWSGROUPS command.
Generates a list of newsgroups including the name and a short
description.
See <http://tools.ietf.org/html/rfc3977#section-7.6.6>
Args:
pattern: Glob matching newsgroups of intrest.
Yields:
A tuple containing the name, and description for the newsgroup. | nntp/nntp.py | def list_newsgroups_gen(self, pattern=None):
"""Generator for the LIST NEWSGROUPS command.
Generates a list of newsgroups including the name and a short
description.
See <http://tools.ietf.org/html/rfc3977#section-7.6.6>
Args:
pattern: Glob matching newsgroups of intrest.
Yields:
A tuple containing the name, and description for the newsgroup.
"""
args = pattern
code, message = self.command("LIST NEWSGROUPS", args)
if code != 215:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
parts = line.strip().split()
name, description = parts[0], ""
if len(parts) > 1:
description = parts[1]
yield name, description | def list_newsgroups_gen(self, pattern=None):
"""Generator for the LIST NEWSGROUPS command.
Generates a list of newsgroups including the name and a short
description.
See <http://tools.ietf.org/html/rfc3977#section-7.6.6>
Args:
pattern: Glob matching newsgroups of intrest.
Yields:
A tuple containing the name, and description for the newsgroup.
"""
args = pattern
code, message = self.command("LIST NEWSGROUPS", args)
if code != 215:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
parts = line.strip().split()
name, description = parts[0], ""
if len(parts) > 1:
description = parts[1]
yield name, description | [
"Generator",
"for",
"the",
"LIST",
"NEWSGROUPS",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L817-L842 | [
"def",
"list_newsgroups_gen",
"(",
"self",
",",
"pattern",
"=",
"None",
")",
":",
"args",
"=",
"pattern",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"LIST NEWSGROUPS\"",
",",
"args",
")",
"if",
"code",
"!=",
"215",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"for",
"line",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
")",
":",
"parts",
"=",
"line",
".",
"strip",
"(",
")",
".",
"split",
"(",
")",
"name",
",",
"description",
"=",
"parts",
"[",
"0",
"]",
",",
"\"\"",
"if",
"len",
"(",
"parts",
")",
">",
"1",
":",
"description",
"=",
"parts",
"[",
"1",
"]",
"yield",
"name",
",",
"description"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.list_overview_fmt_gen | Generator for the LIST OVERVIEW.FMT
See list_overview_fmt() for more information.
Yields:
An element in the list returned by list_overview_fmt(). | nntp/nntp.py | def list_overview_fmt_gen(self):
"""Generator for the LIST OVERVIEW.FMT
See list_overview_fmt() for more information.
Yields:
An element in the list returned by list_overview_fmt().
"""
code, message = self.command("LIST OVERVIEW.FMT")
if code != 215:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
try:
name, suffix = line.rstrip().split(":")
except ValueError:
raise NNTPDataError("Invalid LIST OVERVIEW.FMT")
if suffix and not name:
name, suffix = suffix, name
if suffix and suffix != "full":
raise NNTPDataError("Invalid LIST OVERVIEW.FMT")
yield (name, suffix == "full") | def list_overview_fmt_gen(self):
"""Generator for the LIST OVERVIEW.FMT
See list_overview_fmt() for more information.
Yields:
An element in the list returned by list_overview_fmt().
"""
code, message = self.command("LIST OVERVIEW.FMT")
if code != 215:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
try:
name, suffix = line.rstrip().split(":")
except ValueError:
raise NNTPDataError("Invalid LIST OVERVIEW.FMT")
if suffix and not name:
name, suffix = suffix, name
if suffix and suffix != "full":
raise NNTPDataError("Invalid LIST OVERVIEW.FMT")
yield (name, suffix == "full") | [
"Generator",
"for",
"the",
"LIST",
"OVERVIEW",
".",
"FMT"
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L860-L881 | [
"def",
"list_overview_fmt_gen",
"(",
"self",
")",
":",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"LIST OVERVIEW.FMT\"",
")",
"if",
"code",
"!=",
"215",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"for",
"line",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
")",
":",
"try",
":",
"name",
",",
"suffix",
"=",
"line",
".",
"rstrip",
"(",
")",
".",
"split",
"(",
"\":\"",
")",
"except",
"ValueError",
":",
"raise",
"NNTPDataError",
"(",
"\"Invalid LIST OVERVIEW.FMT\"",
")",
"if",
"suffix",
"and",
"not",
"name",
":",
"name",
",",
"suffix",
"=",
"suffix",
",",
"name",
"if",
"suffix",
"and",
"suffix",
"!=",
"\"full\"",
":",
"raise",
"NNTPDataError",
"(",
"\"Invalid LIST OVERVIEW.FMT\"",
")",
"yield",
"(",
"name",
",",
"suffix",
"==",
"\"full\"",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.list_extensions_gen | Generator for the LIST EXTENSIONS command. | nntp/nntp.py | def list_extensions_gen(self):
"""Generator for the LIST EXTENSIONS command.
"""
code, message = self.command("LIST EXTENSIONS")
if code != 202:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
yield line.strip() | def list_extensions_gen(self):
"""Generator for the LIST EXTENSIONS command.
"""
code, message = self.command("LIST EXTENSIONS")
if code != 202:
raise NNTPReplyError(code, message)
for line in self.info_gen(code, message):
yield line.strip() | [
"Generator",
"for",
"the",
"LIST",
"EXTENSIONS",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L888-L896 | [
"def",
"list_extensions_gen",
"(",
"self",
")",
":",
"code",
",",
"message",
"=",
"self",
".",
"command",
"(",
"\"LIST EXTENSIONS\"",
")",
"if",
"code",
"!=",
"202",
":",
"raise",
"NNTPReplyError",
"(",
"code",
",",
"message",
")",
"for",
"line",
"in",
"self",
".",
"info_gen",
"(",
"code",
",",
"message",
")",
":",
"yield",
"line",
".",
"strip",
"(",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
test | NNTPClient.list_gen | Generator for LIST command.
See list() for more information.
Yields:
An element in the list returned by list(). | nntp/nntp.py | def list_gen(self, keyword=None, arg=None):
"""Generator for LIST command.
See list() for more information.
Yields:
An element in the list returned by list().
"""
if keyword:
keyword = keyword.upper()
if keyword is None or keyword == "ACTIVE":
return self.list_active_gen(arg)
if keyword == "ACTIVE.TIMES":
return self.list_active_times_gen()
if keyword == "DISTRIB.PATS":
return self.list_distrib_pats_gen()
if keyword == "HEADERS":
return self.list_headers_gen(arg)
if keyword == "NEWSGROUPS":
return self.list_newsgroups_gen(arg)
if keyword == "OVERVIEW.FMT":
return self.list_overview_fmt_gen()
if keyword == "EXTENSIONS":
return self.list_extensions_gen()
raise NotImplementedError() | def list_gen(self, keyword=None, arg=None):
"""Generator for LIST command.
See list() for more information.
Yields:
An element in the list returned by list().
"""
if keyword:
keyword = keyword.upper()
if keyword is None or keyword == "ACTIVE":
return self.list_active_gen(arg)
if keyword == "ACTIVE.TIMES":
return self.list_active_times_gen()
if keyword == "DISTRIB.PATS":
return self.list_distrib_pats_gen()
if keyword == "HEADERS":
return self.list_headers_gen(arg)
if keyword == "NEWSGROUPS":
return self.list_newsgroups_gen(arg)
if keyword == "OVERVIEW.FMT":
return self.list_overview_fmt_gen()
if keyword == "EXTENSIONS":
return self.list_extensions_gen()
raise NotImplementedError() | [
"Generator",
"for",
"LIST",
"command",
"."
] | greenbender/pynntp | python | https://github.com/greenbender/pynntp/blob/991a76331cdf5d8f9dbf5b18f6e29adc80749a2f/nntp/nntp.py#L903-L929 | [
"def",
"list_gen",
"(",
"self",
",",
"keyword",
"=",
"None",
",",
"arg",
"=",
"None",
")",
":",
"if",
"keyword",
":",
"keyword",
"=",
"keyword",
".",
"upper",
"(",
")",
"if",
"keyword",
"is",
"None",
"or",
"keyword",
"==",
"\"ACTIVE\"",
":",
"return",
"self",
".",
"list_active_gen",
"(",
"arg",
")",
"if",
"keyword",
"==",
"\"ACTIVE.TIMES\"",
":",
"return",
"self",
".",
"list_active_times_gen",
"(",
")",
"if",
"keyword",
"==",
"\"DISTRIB.PATS\"",
":",
"return",
"self",
".",
"list_distrib_pats_gen",
"(",
")",
"if",
"keyword",
"==",
"\"HEADERS\"",
":",
"return",
"self",
".",
"list_headers_gen",
"(",
"arg",
")",
"if",
"keyword",
"==",
"\"NEWSGROUPS\"",
":",
"return",
"self",
".",
"list_newsgroups_gen",
"(",
"arg",
")",
"if",
"keyword",
"==",
"\"OVERVIEW.FMT\"",
":",
"return",
"self",
".",
"list_overview_fmt_gen",
"(",
")",
"if",
"keyword",
"==",
"\"EXTENSIONS\"",
":",
"return",
"self",
".",
"list_extensions_gen",
"(",
")",
"raise",
"NotImplementedError",
"(",
")"
] | 991a76331cdf5d8f9dbf5b18f6e29adc80749a2f |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.