repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
toloco/pyoanda | pyoanda/client.py | Client.get_orders | def get_orders(self, instrument=None, count=50):
"""
See more:
http://developer.oanda.com/rest-live/orders/#getOrdersForAnAccount
"""
url = "{0}/{1}/accounts/{2}/orders".format(
self.domain,
self.API_VERSION,
self.account_id
)
... | python | def get_orders(self, instrument=None, count=50):
"""
See more:
http://developer.oanda.com/rest-live/orders/#getOrdersForAnAccount
"""
url = "{0}/{1}/accounts/{2}/orders".format(
self.domain,
self.API_VERSION,
self.account_id
)
... | [
"def",
"get_orders",
"(",
"self",
",",
"instrument",
"=",
"None",
",",
"count",
"=",
"50",
")",
":",
"url",
"=",
"\"{0}/{1}/accounts/{2}/orders\"",
".",
"format",
"(",
"self",
".",
"domain",
",",
"self",
".",
"API_VERSION",
",",
"self",
".",
"account_id",
... | See more:
http://developer.oanda.com/rest-live/orders/#getOrdersForAnAccount | [
"See",
"more",
":",
"http",
":",
"//",
"developer",
".",
"oanda",
".",
"com",
"/",
"rest",
"-",
"live",
"/",
"orders",
"/",
"#getOrdersForAnAccount"
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L191-L207 |
toloco/pyoanda | pyoanda/client.py | Client.get_order | def get_order(self, order_id):
"""
See more:
http://developer.oanda.com/rest-live/orders/#getInformationForAnOrder
"""
url = "{0}/{1}/accounts/{2}/orders/{3}".format(
self.domain,
self.API_VERSION,
self.account_id,
order_id
... | python | def get_order(self, order_id):
"""
See more:
http://developer.oanda.com/rest-live/orders/#getInformationForAnOrder
"""
url = "{0}/{1}/accounts/{2}/orders/{3}".format(
self.domain,
self.API_VERSION,
self.account_id,
order_id
... | [
"def",
"get_order",
"(",
"self",
",",
"order_id",
")",
":",
"url",
"=",
"\"{0}/{1}/accounts/{2}/orders/{3}\"",
".",
"format",
"(",
"self",
".",
"domain",
",",
"self",
".",
"API_VERSION",
",",
"self",
".",
"account_id",
",",
"order_id",
")",
"try",
":",
"re... | See more:
http://developer.oanda.com/rest-live/orders/#getInformationForAnOrder | [
"See",
"more",
":",
"http",
":",
"//",
"developer",
".",
"oanda",
".",
"com",
"/",
"rest",
"-",
"live",
"/",
"orders",
"/",
"#getInformationForAnOrder"
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L209-L225 |
toloco/pyoanda | pyoanda/client.py | Client.create_order | def create_order(self, order):
"""
See more:
http://developer.oanda.com/rest-live/orders/#createNewOrder
"""
url = "{0}/{1}/accounts/{2}/orders".format(
self.domain,
self.API_VERSION,
self.account_id
)
try:
r... | python | def create_order(self, order):
"""
See more:
http://developer.oanda.com/rest-live/orders/#createNewOrder
"""
url = "{0}/{1}/accounts/{2}/orders".format(
self.domain,
self.API_VERSION,
self.account_id
)
try:
r... | [
"def",
"create_order",
"(",
"self",
",",
"order",
")",
":",
"url",
"=",
"\"{0}/{1}/accounts/{2}/orders\"",
".",
"format",
"(",
"self",
".",
"domain",
",",
"self",
".",
"API_VERSION",
",",
"self",
".",
"account_id",
")",
"try",
":",
"return",
"self",
".",
... | See more:
http://developer.oanda.com/rest-live/orders/#createNewOrder | [
"See",
"more",
":",
"http",
":",
"//",
"developer",
".",
"oanda",
".",
"com",
"/",
"rest",
"-",
"live",
"/",
"orders",
"/",
"#createNewOrder"
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L227-L246 |
toloco/pyoanda | pyoanda/client.py | Client.get_trades | def get_trades(self, max_id=None, count=None, instrument=None, ids=None):
""" Get a list of open trades
Parameters
----------
max_id : int
The server will return trades with id less than or equal
to this, in descending order (for pagination)
... | python | def get_trades(self, max_id=None, count=None, instrument=None, ids=None):
""" Get a list of open trades
Parameters
----------
max_id : int
The server will return trades with id less than or equal
to this, in descending order (for pagination)
... | [
"def",
"get_trades",
"(",
"self",
",",
"max_id",
"=",
"None",
",",
"count",
"=",
"None",
",",
"instrument",
"=",
"None",
",",
"ids",
"=",
"None",
")",
":",
"url",
"=",
"\"{0}/{1}/accounts/{2}/trades\"",
".",
"format",
"(",
"self",
".",
"domain",
",",
"... | Get a list of open trades
Parameters
----------
max_id : int
The server will return trades with id less than or equal
to this, in descending order (for pagination)
count : int
Maximum number of open trades to return. Defaul... | [
"Get",
"a",
"list",
"of",
"open",
"trades"
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L288-L327 |
toloco/pyoanda | pyoanda/client.py | Client.update_trade | def update_trade(
self,
trade_id,
stop_loss=None,
take_profit=None,
trailing_stop=None
):
""" Modify an existing trade.
Note: Only the specified parameters will be modified. All
other parameters will remain unchanged. To remove an
... | python | def update_trade(
self,
trade_id,
stop_loss=None,
take_profit=None,
trailing_stop=None
):
""" Modify an existing trade.
Note: Only the specified parameters will be modified. All
other parameters will remain unchanged. To remove an
... | [
"def",
"update_trade",
"(",
"self",
",",
"trade_id",
",",
"stop_loss",
"=",
"None",
",",
"take_profit",
"=",
"None",
",",
"trailing_stop",
"=",
"None",
")",
":",
"url",
"=",
"\"{0}/{1}/accounts/{2}/trades/{3}\"",
".",
"format",
"(",
"self",
".",
"domain",
",... | Modify an existing trade.
Note: Only the specified parameters will be modified. All
other parameters will remain unchanged. To remove an
optional parameter, set its value to 0.
Parameters
----------
trade_id : int
The id of the tr... | [
"Modify",
"an",
"existing",
"trade",
"."
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L353-L397 |
toloco/pyoanda | pyoanda/client.py | Client.request_transaction_history | def request_transaction_history(self):
""" Request full account history.
Submit a request for a full transaction history. A
successfully accepted submission results in a response
containing a URL in the Location header to a file that will
be available once the r... | python | def request_transaction_history(self):
""" Request full account history.
Submit a request for a full transaction history. A
successfully accepted submission results in a response
containing a URL in the Location header to a file that will
be available once the r... | [
"def",
"request_transaction_history",
"(",
"self",
")",
":",
"url",
"=",
"\"{0}/{1}/accounts/{2}/alltransactions\"",
".",
"format",
"(",
"self",
".",
"domain",
",",
"self",
".",
"API_VERSION",
",",
"self",
".",
"account_id",
")",
"try",
":",
"resp",
"=",
"self... | Request full account history.
Submit a request for a full transaction history. A
successfully accepted submission results in a response
containing a URL in the Location header to a file that will
be available once the request is served. Response for the
URL ... | [
"Request",
"full",
"account",
"history",
"."
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L562-L587 |
toloco/pyoanda | pyoanda/client.py | Client.get_transaction_history | def get_transaction_history(self, max_wait=5.0):
""" Download full account history.
Uses request_transaction_history to get the transaction
history URL, then polls the given URL until it's ready (or
the max_wait time is reached) and provides the decoded
response.... | python | def get_transaction_history(self, max_wait=5.0):
""" Download full account history.
Uses request_transaction_history to get the transaction
history URL, then polls the given URL until it's ready (or
the max_wait time is reached) and provides the decoded
response.... | [
"def",
"get_transaction_history",
"(",
"self",
",",
"max_wait",
"=",
"5.0",
")",
":",
"url",
"=",
"self",
".",
"request_transaction_history",
"(",
")",
"if",
"not",
"url",
":",
"return",
"False",
"ready",
"=",
"False",
"start",
"=",
"time",
"(",
")",
"de... | Download full account history.
Uses request_transaction_history to get the transaction
history URL, then polls the given URL until it's ready (or
the max_wait time is reached) and provides the decoded
response.
Parameters
----------
m... | [
"Download",
"full",
"account",
"history",
"."
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L589-L642 |
toloco/pyoanda | pyoanda/client.py | Client.create_account | def create_account(self, currency=None):
""" Create a new account.
This call is only available on the sandbox system. Please
create accounts on fxtrade.oanda.com on our production
system.
See more:
http://developer.oanda.com/rest-sandbox/accounts/#-a... | python | def create_account(self, currency=None):
""" Create a new account.
This call is only available on the sandbox system. Please
create accounts on fxtrade.oanda.com on our production
system.
See more:
http://developer.oanda.com/rest-sandbox/accounts/#-a... | [
"def",
"create_account",
"(",
"self",
",",
"currency",
"=",
"None",
")",
":",
"url",
"=",
"\"{0}/{1}/accounts\"",
".",
"format",
"(",
"self",
".",
"domain",
",",
"self",
".",
"API_VERSION",
")",
"params",
"=",
"{",
"\"currency\"",
":",
"currency",
"}",
"... | Create a new account.
This call is only available on the sandbox system. Please
create accounts on fxtrade.oanda.com on our production
system.
See more:
http://developer.oanda.com/rest-sandbox/accounts/#-a-name-createtestaccount-a-create-a-test-account | [
"Create",
"a",
"new",
"account",
"."
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L644-L661 |
toloco/pyoanda | pyoanda/client.py | Client.get_accounts | def get_accounts(self, username=None):
""" Get a list of accounts owned by the user.
Parameters
----------
username : string
The name of the user. Note: This is only required on the
sandbox, on production systems your access token will
... | python | def get_accounts(self, username=None):
""" Get a list of accounts owned by the user.
Parameters
----------
username : string
The name of the user. Note: This is only required on the
sandbox, on production systems your access token will
... | [
"def",
"get_accounts",
"(",
"self",
",",
"username",
"=",
"None",
")",
":",
"url",
"=",
"\"{0}/{1}/accounts\"",
".",
"format",
"(",
"self",
".",
"domain",
",",
"self",
".",
"API_VERSION",
")",
"params",
"=",
"{",
"\"username\"",
":",
"username",
"}",
"tr... | Get a list of accounts owned by the user.
Parameters
----------
username : string
The name of the user. Note: This is only required on the
sandbox, on production systems your access token will
identify you.
See more:
... | [
"Get",
"a",
"list",
"of",
"accounts",
"owned",
"by",
"the",
"user",
"."
] | train | https://github.com/toloco/pyoanda/blob/26b3f28a89d07c5c20d2a645884505387f1daae8/pyoanda/client.py#L663-L683 |
ddorn/GUI | GUI/menu.py | MenuElement.choose | def choose(self):
"""Marks the item as the one the user is in."""
if not self.choosed:
self.choosed = True
self.pos = self.pos + Sep(5, 0) | python | def choose(self):
"""Marks the item as the one the user is in."""
if not self.choosed:
self.choosed = True
self.pos = self.pos + Sep(5, 0) | [
"def",
"choose",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"choosed",
":",
"self",
".",
"choosed",
"=",
"True",
"self",
".",
"pos",
"=",
"self",
".",
"pos",
"+",
"Sep",
"(",
"5",
",",
"0",
")"
] | Marks the item as the one the user is in. | [
"Marks",
"the",
"item",
"as",
"the",
"one",
"the",
"user",
"is",
"in",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/menu.py#L127-L131 |
ddorn/GUI | GUI/menu.py | MenuElement.stop_choose | def stop_choose(self):
"""Marks the item as the one the user is not in."""
if self.choosed:
self.choosed = False
self.pos = self.pos + Sep(-5, 0) | python | def stop_choose(self):
"""Marks the item as the one the user is not in."""
if self.choosed:
self.choosed = False
self.pos = self.pos + Sep(-5, 0) | [
"def",
"stop_choose",
"(",
"self",
")",
":",
"if",
"self",
".",
"choosed",
":",
"self",
".",
"choosed",
"=",
"False",
"self",
".",
"pos",
"=",
"self",
".",
"pos",
"+",
"Sep",
"(",
"-",
"5",
",",
"0",
")"
] | Marks the item as the one the user is not in. | [
"Marks",
"the",
"item",
"as",
"the",
"one",
"the",
"user",
"is",
"not",
"in",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/menu.py#L133-L137 |
ddorn/GUI | GUI/menu.py | MenuElement.get_darker_color | def get_darker_color(self):
"""The color of the clicked version of the MenuElement. Darker than the normal one."""
# we change a bit the color in one direction
if bw_contrasted(self._true_color, 30) == WHITE:
color = mix(self._true_color, WHITE, 0.9)
else:
color =... | python | def get_darker_color(self):
"""The color of the clicked version of the MenuElement. Darker than the normal one."""
# we change a bit the color in one direction
if bw_contrasted(self._true_color, 30) == WHITE:
color = mix(self._true_color, WHITE, 0.9)
else:
color =... | [
"def",
"get_darker_color",
"(",
"self",
")",
":",
"# we change a bit the color in one direction",
"if",
"bw_contrasted",
"(",
"self",
".",
"_true_color",
",",
"30",
")",
"==",
"WHITE",
":",
"color",
"=",
"mix",
"(",
"self",
".",
"_true_color",
",",
"WHITE",
",... | The color of the clicked version of the MenuElement. Darker than the normal one. | [
"The",
"color",
"of",
"the",
"clicked",
"version",
"of",
"the",
"MenuElement",
".",
"Darker",
"than",
"the",
"normal",
"one",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/menu.py#L145-L153 |
ddorn/GUI | GUI/menu.py | MenuElement.render | def render(self, screen):
"""Renders the MenuElement"""
self.rect.render(screen)
super(MenuElement, self).render(screen) | python | def render(self, screen):
"""Renders the MenuElement"""
self.rect.render(screen)
super(MenuElement, self).render(screen) | [
"def",
"render",
"(",
"self",
",",
"screen",
")",
":",
"self",
".",
"rect",
".",
"render",
"(",
"screen",
")",
"super",
"(",
"MenuElement",
",",
"self",
")",
".",
"render",
"(",
"screen",
")"
] | Renders the MenuElement | [
"Renders",
"the",
"MenuElement"
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/menu.py#L155-L158 |
ddorn/GUI | GUI/gui_examples/bezier.py | gui | def gui():
"""Main function"""
# #######
# setup all objects
# #######
zones = [ALL]
last_zones = []
COLORS.remove(WHITE)
screen = pygame.display.set_mode(SCREEN_SIZE, DOUBLEBUF)
pygame.display.set_caption('Bezier simulator')
pygame.event.set_allowed([QUIT, KEYDOWN, MOUSEBUTT... | python | def gui():
"""Main function"""
# #######
# setup all objects
# #######
zones = [ALL]
last_zones = []
COLORS.remove(WHITE)
screen = pygame.display.set_mode(SCREEN_SIZE, DOUBLEBUF)
pygame.display.set_caption('Bezier simulator')
pygame.event.set_allowed([QUIT, KEYDOWN, MOUSEBUTT... | [
"def",
"gui",
"(",
")",
":",
"# #######",
"# setup all objects",
"# #######",
"zones",
"=",
"[",
"ALL",
"]",
"last_zones",
"=",
"[",
"]",
"COLORS",
".",
"remove",
"(",
"WHITE",
")",
"screen",
"=",
"pygame",
".",
"display",
".",
"set_mode",
"(",
"SCREEN_S... | Main function | [
"Main",
"function"
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/gui_examples/bezier.py#L17-L105 |
ddorn/GUI | GUI/gui_examples/morpion.py | gui | def gui():
"""Main function"""
# #######
# setup all objects
# #######
os.environ['SDL_VIDEO_CENTERED'] = '1'
clock = pygame.time.Clock()
screen = pygame.display.set_mode(SCREEN_SIZE, DOUBLEBUF | NOFRAME)
pygame.event.set_allowed([QUIT, KEYDOWN, MOUSEBUTTONDOWN])
game = Morpion()
... | python | def gui():
"""Main function"""
# #######
# setup all objects
# #######
os.environ['SDL_VIDEO_CENTERED'] = '1'
clock = pygame.time.Clock()
screen = pygame.display.set_mode(SCREEN_SIZE, DOUBLEBUF | NOFRAME)
pygame.event.set_allowed([QUIT, KEYDOWN, MOUSEBUTTONDOWN])
game = Morpion()
... | [
"def",
"gui",
"(",
")",
":",
"# #######",
"# setup all objects",
"# #######",
"os",
".",
"environ",
"[",
"'SDL_VIDEO_CENTERED'",
"]",
"=",
"'1'",
"clock",
"=",
"pygame",
".",
"time",
".",
"Clock",
"(",
")",
"screen",
"=",
"pygame",
".",
"display",
".",
"... | Main function | [
"Main",
"function"
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/gui_examples/morpion.py#L188-L248 |
ddorn/GUI | GUI/font.py | Font.px_to_pt | def px_to_pt(self, px):
"""Convert a size in pxel to a size in points."""
if px < 200:
pt = self.PX_TO_PT[px]
else:
pt = int(floor((px - 1.21) / 1.332))
return pt | python | def px_to_pt(self, px):
"""Convert a size in pxel to a size in points."""
if px < 200:
pt = self.PX_TO_PT[px]
else:
pt = int(floor((px - 1.21) / 1.332))
return pt | [
"def",
"px_to_pt",
"(",
"self",
",",
"px",
")",
":",
"if",
"px",
"<",
"200",
":",
"pt",
"=",
"self",
".",
"PX_TO_PT",
"[",
"px",
"]",
"else",
":",
"pt",
"=",
"int",
"(",
"floor",
"(",
"(",
"px",
"-",
"1.21",
")",
"/",
"1.332",
")",
")",
"re... | Convert a size in pxel to a size in points. | [
"Convert",
"a",
"size",
"in",
"pxel",
"to",
"a",
"size",
"in",
"points",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/font.py#L45-L52 |
ddorn/GUI | GUI/font.py | Font.set_size | def set_size(self, pt=None, px=None):
"""
Set the size of the font, in px or pt.
The px method is a bit inacurate, there can be one or two px less, and max 4 for big numbers (like 503)
but the size is never over-estimated. It makes almost the good value.
"""
assert (pt,... | python | def set_size(self, pt=None, px=None):
"""
Set the size of the font, in px or pt.
The px method is a bit inacurate, there can be one or two px less, and max 4 for big numbers (like 503)
but the size is never over-estimated. It makes almost the good value.
"""
assert (pt,... | [
"def",
"set_size",
"(",
"self",
",",
"pt",
"=",
"None",
",",
"px",
"=",
"None",
")",
":",
"assert",
"(",
"pt",
",",
"px",
")",
"!=",
"(",
"None",
",",
"None",
")",
"if",
"pt",
"is",
"not",
"None",
":",
"self",
".",
"__init__",
"(",
"pt",
",",... | Set the size of the font, in px or pt.
The px method is a bit inacurate, there can be one or two px less, and max 4 for big numbers (like 503)
but the size is never over-estimated. It makes almost the good value. | [
"Set",
"the",
"size",
"of",
"the",
"font",
"in",
"px",
"or",
"pt",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/font.py#L54-L67 |
ddorn/GUI | GUI/text.py | SimpleText.text | def text(self):
"""Return the string to render."""
if callable(self._text):
return str(self._text())
return str(self._text) | python | def text(self):
"""Return the string to render."""
if callable(self._text):
return str(self._text())
return str(self._text) | [
"def",
"text",
"(",
"self",
")",
":",
"if",
"callable",
"(",
"self",
".",
"_text",
")",
":",
"return",
"str",
"(",
"self",
".",
"_text",
"(",
")",
")",
"return",
"str",
"(",
"self",
".",
"_text",
")"
] | Return the string to render. | [
"Return",
"the",
"string",
"to",
"render",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L55-L59 |
ddorn/GUI | GUI/text.py | SimpleText.color | def color(self, value):
"""Set the color to a new value (tuple). Renders the text if needed."""
if value != self.color:
self._color = value
self._render() | python | def color(self, value):
"""Set the color to a new value (tuple). Renders the text if needed."""
if value != self.color:
self._color = value
self._render() | [
"def",
"color",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"!=",
"self",
".",
"color",
":",
"self",
".",
"_color",
"=",
"value",
"self",
".",
"_render",
"(",
")"
] | Set the color to a new value (tuple). Renders the text if needed. | [
"Set",
"the",
"color",
"to",
"a",
"new",
"value",
"(",
"tuple",
")",
".",
"Renders",
"the",
"text",
"if",
"needed",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L76-L81 |
ddorn/GUI | GUI/text.py | SimpleText.bg_color | def bg_color(self, value):
"""Sets the color to a new value (tuple). Renders the text if needed."""
if value != self.bg_color:
self._bg_color = value
self._render() | python | def bg_color(self, value):
"""Sets the color to a new value (tuple). Renders the text if needed."""
if value != self.bg_color:
self._bg_color = value
self._render() | [
"def",
"bg_color",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"!=",
"self",
".",
"bg_color",
":",
"self",
".",
"_bg_color",
"=",
"value",
"self",
".",
"_render",
"(",
")"
] | Sets the color to a new value (tuple). Renders the text if needed. | [
"Sets",
"the",
"color",
"to",
"a",
"new",
"value",
"(",
"tuple",
")",
".",
"Renders",
"the",
"text",
"if",
"needed",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L84-L89 |
ddorn/GUI | GUI/text.py | SimpleText.set_font_size | def set_font_size(self, pt=None, px=None):
"""Set the font size to the desired size, in pt or px."""
self.font.set_size(pt, px)
self._render() | python | def set_font_size(self, pt=None, px=None):
"""Set the font size to the desired size, in pt or px."""
self.font.set_size(pt, px)
self._render() | [
"def",
"set_font_size",
"(",
"self",
",",
"pt",
"=",
"None",
",",
"px",
"=",
"None",
")",
":",
"self",
".",
"font",
".",
"set_size",
"(",
"pt",
",",
"px",
")",
"self",
".",
"_render",
"(",
")"
] | Set the font size to the desired size, in pt or px. | [
"Set",
"the",
"font",
"size",
"to",
"the",
"desired",
"size",
"in",
"pt",
"or",
"px",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L91-L95 |
ddorn/GUI | GUI/text.py | SimpleText._render | def _render(self):
"""
Render the text.
Avoid using this fonction too many time as it is slow as it is low to render text and blit it.
"""
self._last_text = self.text
self._surface = self.font.render(self.text, True, self.color, self.bg_color)
rect = self._surf... | python | def _render(self):
"""
Render the text.
Avoid using this fonction too many time as it is slow as it is low to render text and blit it.
"""
self._last_text = self.text
self._surface = self.font.render(self.text, True, self.color, self.bg_color)
rect = self._surf... | [
"def",
"_render",
"(",
"self",
")",
":",
"self",
".",
"_last_text",
"=",
"self",
".",
"text",
"self",
".",
"_surface",
"=",
"self",
".",
"font",
".",
"render",
"(",
"self",
".",
"text",
",",
"True",
",",
"self",
".",
"color",
",",
"self",
".",
"b... | Render the text.
Avoid using this fonction too many time as it is slow as it is low to render text and blit it. | [
"Render",
"the",
"text",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L97-L109 |
ddorn/GUI | GUI/text.py | SimpleText.render | def render(self, display):
"""Render basicly the text."""
# to handle changing objects / callable
if self.text != self._last_text:
self._render()
display.blit(self._surface, (self.topleft, self.size)) | python | def render(self, display):
"""Render basicly the text."""
# to handle changing objects / callable
if self.text != self._last_text:
self._render()
display.blit(self._surface, (self.topleft, self.size)) | [
"def",
"render",
"(",
"self",
",",
"display",
")",
":",
"# to handle changing objects / callable",
"if",
"self",
".",
"text",
"!=",
"self",
".",
"_last_text",
":",
"self",
".",
"_render",
"(",
")",
"display",
".",
"blit",
"(",
"self",
".",
"_surface",
",",... | Render basicly the text. | [
"Render",
"basicly",
"the",
"text",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L111-L117 |
ddorn/GUI | GUI/text.py | InLineTextBox.cursor | def cursor(self):
"""The position of the cursor in the text."""
if self._cursor < 0:
self.cursor = 0
if self._cursor > len(self):
self.cursor = len(self)
return self._cursor | python | def cursor(self):
"""The position of the cursor in the text."""
if self._cursor < 0:
self.cursor = 0
if self._cursor > len(self):
self.cursor = len(self)
return self._cursor | [
"def",
"cursor",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cursor",
"<",
"0",
":",
"self",
".",
"cursor",
"=",
"0",
"if",
"self",
".",
"_cursor",
">",
"len",
"(",
"self",
")",
":",
"self",
".",
"cursor",
"=",
"len",
"(",
"self",
")",
"return"... | The position of the cursor in the text. | [
"The",
"position",
"of",
"the",
"cursor",
"in",
"the",
"text",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L151-L159 |
ddorn/GUI | GUI/text.py | InLineTextBox.move_cursor_one_letter | def move_cursor_one_letter(self, letter=RIGHT):
"""Move the cursor of one letter to the right (1) or the the left."""
assert letter in (self.RIGHT, self.LEFT)
if letter == self.RIGHT:
self.cursor += 1
if self.cursor > len(self.text):
self.cursor -= 1
... | python | def move_cursor_one_letter(self, letter=RIGHT):
"""Move the cursor of one letter to the right (1) or the the left."""
assert letter in (self.RIGHT, self.LEFT)
if letter == self.RIGHT:
self.cursor += 1
if self.cursor > len(self.text):
self.cursor -= 1
... | [
"def",
"move_cursor_one_letter",
"(",
"self",
",",
"letter",
"=",
"RIGHT",
")",
":",
"assert",
"letter",
"in",
"(",
"self",
".",
"RIGHT",
",",
"self",
".",
"LEFT",
")",
"if",
"letter",
"==",
"self",
".",
"RIGHT",
":",
"self",
".",
"cursor",
"+=",
"1"... | Move the cursor of one letter to the right (1) or the the left. | [
"Move",
"the",
"cursor",
"of",
"one",
"letter",
"to",
"the",
"right",
"(",
"1",
")",
"or",
"the",
"the",
"left",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L184-L195 |
ddorn/GUI | GUI/text.py | InLineTextBox.move_cursor_one_word | def move_cursor_one_word(self, word=LEFT):
"""Move the cursor of one word to the right (1) or the the left (-1)."""
assert word in (self.RIGHT, self.LEFT)
if word == self.RIGHT:
papy = self.text.find(' ', self.cursor) + 1
if not papy:
papy = len(self)
... | python | def move_cursor_one_word(self, word=LEFT):
"""Move the cursor of one word to the right (1) or the the left (-1)."""
assert word in (self.RIGHT, self.LEFT)
if word == self.RIGHT:
papy = self.text.find(' ', self.cursor) + 1
if not papy:
papy = len(self)
... | [
"def",
"move_cursor_one_word",
"(",
"self",
",",
"word",
"=",
"LEFT",
")",
":",
"assert",
"word",
"in",
"(",
"self",
".",
"RIGHT",
",",
"self",
".",
"LEFT",
")",
"if",
"word",
"==",
"self",
".",
"RIGHT",
":",
"papy",
"=",
"self",
".",
"text",
".",
... | Move the cursor of one word to the right (1) or the the left (-1). | [
"Move",
"the",
"cursor",
"of",
"one",
"word",
"to",
"the",
"right",
"(",
"1",
")",
"or",
"the",
"the",
"left",
"(",
"-",
"1",
")",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L197-L211 |
ddorn/GUI | GUI/text.py | InLineTextBox.delete_one_letter | def delete_one_letter(self, letter=RIGHT):
"""Delete one letter the right or the the left of the cursor."""
assert letter in (self.RIGHT, self.LEFT)
if letter == self.LEFT:
papy = self.cursor
self.text = self.text[:self.cursor - 1] + self.text[self.cursor:]
... | python | def delete_one_letter(self, letter=RIGHT):
"""Delete one letter the right or the the left of the cursor."""
assert letter in (self.RIGHT, self.LEFT)
if letter == self.LEFT:
papy = self.cursor
self.text = self.text[:self.cursor - 1] + self.text[self.cursor:]
... | [
"def",
"delete_one_letter",
"(",
"self",
",",
"letter",
"=",
"RIGHT",
")",
":",
"assert",
"letter",
"in",
"(",
"self",
".",
"RIGHT",
",",
"self",
".",
"LEFT",
")",
"if",
"letter",
"==",
"self",
".",
"LEFT",
":",
"papy",
"=",
"self",
".",
"cursor",
... | Delete one letter the right or the the left of the cursor. | [
"Delete",
"one",
"letter",
"the",
"right",
"or",
"the",
"the",
"left",
"of",
"the",
"cursor",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L213-L224 |
ddorn/GUI | GUI/text.py | InLineTextBox.delete_one_word | def delete_one_word(self, word=RIGHT):
"""Delete one word the right or the the left of the cursor."""
assert word in (self.RIGHT, self.LEFT)
if word == self.RIGHT:
papy = self.text.find(' ', self.cursor) + 1
if not papy:
papy = len(self.text)
... | python | def delete_one_word(self, word=RIGHT):
"""Delete one word the right or the the left of the cursor."""
assert word in (self.RIGHT, self.LEFT)
if word == self.RIGHT:
papy = self.text.find(' ', self.cursor) + 1
if not papy:
papy = len(self.text)
... | [
"def",
"delete_one_word",
"(",
"self",
",",
"word",
"=",
"RIGHT",
")",
":",
"assert",
"word",
"in",
"(",
"self",
".",
"RIGHT",
",",
"self",
".",
"LEFT",
")",
"if",
"word",
"==",
"self",
".",
"RIGHT",
":",
"papy",
"=",
"self",
".",
"text",
".",
"f... | Delete one word the right or the the left of the cursor. | [
"Delete",
"one",
"word",
"the",
"right",
"or",
"the",
"the",
"left",
"of",
"the",
"cursor",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L226-L242 |
ddorn/GUI | GUI/text.py | InLineTextBox.add_letter | def add_letter(self, letter):
"""Add a letter at the cursor pos."""
assert isinstance(letter, str)
assert len(letter) == 1
self.text = self.text[:self.cursor] + letter + self.text[self.cursor:]
self.cursor += 1 | python | def add_letter(self, letter):
"""Add a letter at the cursor pos."""
assert isinstance(letter, str)
assert len(letter) == 1
self.text = self.text[:self.cursor] + letter + self.text[self.cursor:]
self.cursor += 1 | [
"def",
"add_letter",
"(",
"self",
",",
"letter",
")",
":",
"assert",
"isinstance",
"(",
"letter",
",",
"str",
")",
"assert",
"len",
"(",
"letter",
")",
"==",
"1",
"self",
".",
"text",
"=",
"self",
".",
"text",
"[",
":",
"self",
".",
"cursor",
"]",
... | Add a letter at the cursor pos. | [
"Add",
"a",
"letter",
"at",
"the",
"cursor",
"pos",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L244-L250 |
ddorn/GUI | GUI/text.py | InLineTextBox.update | def update(self, event_or_list):
"""Update the text and position of cursor according to the event passed."""
event_or_list = super().update(event_or_list)
for e in event_or_list:
if e.type == KEYDOWN:
if e.key == K_RIGHT:
if e.mod * KMOD_CTRL:
... | python | def update(self, event_or_list):
"""Update the text and position of cursor according to the event passed."""
event_or_list = super().update(event_or_list)
for e in event_or_list:
if e.type == KEYDOWN:
if e.key == K_RIGHT:
if e.mod * KMOD_CTRL:
... | [
"def",
"update",
"(",
"self",
",",
"event_or_list",
")",
":",
"event_or_list",
"=",
"super",
"(",
")",
".",
"update",
"(",
"event_or_list",
")",
"for",
"e",
"in",
"event_or_list",
":",
"if",
"e",
".",
"type",
"==",
"KEYDOWN",
":",
"if",
"e",
".",
"ke... | Update the text and position of cursor according to the event passed. | [
"Update",
"the",
"text",
"and",
"position",
"of",
"cursor",
"according",
"to",
"the",
"event",
"passed",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L256-L291 |
ddorn/GUI | GUI/text.py | InLineTextBox._render | def _render(self):
"""
Render the text.
Avoid using this fonction too many times as it is slow as it is slow to render text and blit it.
"""
self._last_text = self.text
self._surface = self.font.render(self.text, True, self.color, self.bg_color)
size = self.wid... | python | def _render(self):
"""
Render the text.
Avoid using this fonction too many times as it is slow as it is slow to render text and blit it.
"""
self._last_text = self.text
self._surface = self.font.render(self.text, True, self.color, self.bg_color)
size = self.wid... | [
"def",
"_render",
"(",
"self",
")",
":",
"self",
".",
"_last_text",
"=",
"self",
".",
"text",
"self",
".",
"_surface",
"=",
"self",
".",
"font",
".",
"render",
"(",
"self",
".",
"text",
",",
"True",
",",
"self",
".",
"color",
",",
"self",
".",
"b... | Render the text.
Avoid using this fonction too many times as it is slow as it is slow to render text and blit it. | [
"Render",
"the",
"text",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L293-L304 |
ddorn/GUI | GUI/text.py | InLinePassBox.shawn_text | def shawn_text(self):
"""The text displayed instead of the real one."""
if len(self._shawn_text) == len(self):
return self._shawn_text
if self.style == self.DOTS:
return chr(0x2022) * len(self)
ranges = [
(902, 1366),
(192, 683),
... | python | def shawn_text(self):
"""The text displayed instead of the real one."""
if len(self._shawn_text) == len(self):
return self._shawn_text
if self.style == self.DOTS:
return chr(0x2022) * len(self)
ranges = [
(902, 1366),
(192, 683),
... | [
"def",
"shawn_text",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"_shawn_text",
")",
"==",
"len",
"(",
"self",
")",
":",
"return",
"self",
".",
"_shawn_text",
"if",
"self",
".",
"style",
"==",
"self",
".",
"DOTS",
":",
"return",
"chr",
"(... | The text displayed instead of the real one. | [
"The",
"text",
"displayed",
"instead",
"of",
"the",
"real",
"one",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L348-L372 |
ddorn/GUI | GUI/text.py | InLinePassBox.cursor_pos | def cursor_pos(self):
"""The cursor position in pixels."""
if len(self) == 0:
return self.left + self.default_text.get_width()
papy = self._surface.get_width()
if papy > self.w:
shift = papy - self.width
else:
shift = 0
return self.le... | python | def cursor_pos(self):
"""The cursor position in pixels."""
if len(self) == 0:
return self.left + self.default_text.get_width()
papy = self._surface.get_width()
if papy > self.w:
shift = papy - self.width
else:
shift = 0
return self.le... | [
"def",
"cursor_pos",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
")",
"==",
"0",
":",
"return",
"self",
".",
"left",
"+",
"self",
".",
"default_text",
".",
"get_width",
"(",
")",
"papy",
"=",
"self",
".",
"_surface",
".",
"get_width",
"(",
")"... | The cursor position in pixels. | [
"The",
"cursor",
"position",
"in",
"pixels",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L374-L385 |
ddorn/GUI | GUI/text.py | InLinePassBox._render | def _render(self):
"""
Render the text.
Avoid using this fonction too many times as it is slow as it is slow to render text and blit it.
"""
self._last_text = self.shawn_text
self._surface = self.font.render(self.shawn_text, True, self.color, self.bg_color)
siz... | python | def _render(self):
"""
Render the text.
Avoid using this fonction too many times as it is slow as it is slow to render text and blit it.
"""
self._last_text = self.shawn_text
self._surface = self.font.render(self.shawn_text, True, self.color, self.bg_color)
siz... | [
"def",
"_render",
"(",
"self",
")",
":",
"self",
".",
"_last_text",
"=",
"self",
".",
"shawn_text",
"self",
".",
"_surface",
"=",
"self",
".",
"font",
".",
"render",
"(",
"self",
".",
"shawn_text",
",",
"True",
",",
"self",
".",
"color",
",",
"self",... | Render the text.
Avoid using this fonction too many times as it is slow as it is slow to render text and blit it. | [
"Render",
"the",
"text",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L387-L398 |
ddorn/GUI | GUI/text.py | InLinePassBox.render | def render(self, display):
"""Render basicly the text."""
# to handle changing objects / callable
if self.shawn_text != self._last_text:
self._render()
if self.text:
papy = self._surface.get_width()
if papy <= self.width:
display.blit... | python | def render(self, display):
"""Render basicly the text."""
# to handle changing objects / callable
if self.shawn_text != self._last_text:
self._render()
if self.text:
papy = self._surface.get_width()
if papy <= self.width:
display.blit... | [
"def",
"render",
"(",
"self",
",",
"display",
")",
":",
"# to handle changing objects / callable",
"if",
"self",
".",
"shawn_text",
"!=",
"self",
".",
"_last_text",
":",
"self",
".",
"_render",
"(",
")",
"if",
"self",
".",
"text",
":",
"papy",
"=",
"self",... | Render basicly the text. | [
"Render",
"basicly",
"the",
"text",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L400-L418 |
ddorn/GUI | GUI/text.py | LaText.latex_to_img | def latex_to_img(tex):
"""Return a pygame image from a latex template."""
with tempfile.TemporaryDirectory() as tmpdirname:
with open(tmpdirname + r'\tex.tex', 'w') as f:
f.write(tex)
os.system(r"latex {0}\tex.tex -halt-on-error -interaction=batchmode -disable-in... | python | def latex_to_img(tex):
"""Return a pygame image from a latex template."""
with tempfile.TemporaryDirectory() as tmpdirname:
with open(tmpdirname + r'\tex.tex', 'w') as f:
f.write(tex)
os.system(r"latex {0}\tex.tex -halt-on-error -interaction=batchmode -disable-in... | [
"def",
"latex_to_img",
"(",
"tex",
")",
":",
"with",
"tempfile",
".",
"TemporaryDirectory",
"(",
")",
"as",
"tmpdirname",
":",
"with",
"open",
"(",
"tmpdirname",
"+",
"r'\\tex.tex'",
",",
"'w'",
")",
"as",
"f",
":",
"f",
".",
"write",
"(",
"tex",
")",
... | Return a pygame image from a latex template. | [
"Return",
"a",
"pygame",
"image",
"from",
"a",
"latex",
"template",
"."
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/text.py#L443-L456 |
ddorn/GUI | GUI/colors.py | mix | def mix(color1, color2, pos=0.5):
"""
Return the mix of two colors at a state of :pos:
Retruns color1 * pos + color2 * (1 - pos)
"""
opp_pos = 1 - pos
red = color1[0] * pos + color2[0] * opp_pos
green = color1[1] * pos + color2[1] * opp_pos
blue = color1[2] * pos + color2[2] * opp_pos
... | python | def mix(color1, color2, pos=0.5):
"""
Return the mix of two colors at a state of :pos:
Retruns color1 * pos + color2 * (1 - pos)
"""
opp_pos = 1 - pos
red = color1[0] * pos + color2[0] * opp_pos
green = color1[1] * pos + color2[1] * opp_pos
blue = color1[2] * pos + color2[2] * opp_pos
... | [
"def",
"mix",
"(",
"color1",
",",
"color2",
",",
"pos",
"=",
"0.5",
")",
":",
"opp_pos",
"=",
"1",
"-",
"pos",
"red",
"=",
"color1",
"[",
"0",
"]",
"*",
"pos",
"+",
"color2",
"[",
"0",
"]",
"*",
"opp_pos",
"green",
"=",
"color1",
"[",
"1",
"]... | Return the mix of two colors at a state of :pos:
Retruns color1 * pos + color2 * (1 - pos) | [
"Return",
"the",
"mix",
"of",
"two",
"colors",
"at",
"a",
"state",
"of",
":",
"pos",
":"
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/colors.py#L13-L24 |
ddorn/GUI | GUI/colors.py | name2rgb | def name2rgb(name):
"""Convert the name of a color into its RGB value"""
try:
import colour
except ImportError:
raise ImportError('You need colour to be installed: pip install colour')
c = colour.Color(name)
color = int(c.red * 255), int(c.green * 255), int(c.blue * 255)
return ... | python | def name2rgb(name):
"""Convert the name of a color into its RGB value"""
try:
import colour
except ImportError:
raise ImportError('You need colour to be installed: pip install colour')
c = colour.Color(name)
color = int(c.red * 255), int(c.green * 255), int(c.blue * 255)
return ... | [
"def",
"name2rgb",
"(",
"name",
")",
":",
"try",
":",
"import",
"colour",
"except",
"ImportError",
":",
"raise",
"ImportError",
"(",
"'You need colour to be installed: pip install colour'",
")",
"c",
"=",
"colour",
".",
"Color",
"(",
"name",
")",
"color",
"=",
... | Convert the name of a color into its RGB value | [
"Convert",
"the",
"name",
"of",
"a",
"color",
"into",
"its",
"RGB",
"value"
] | train | https://github.com/ddorn/GUI/blob/e1fcb5286d24e0995f280d5180222e51895c368c/GUI/colors.py#L27-L36 |
lord63/tldr.py | tldr/parser.py | parse_page | def parse_page(page):
"""Parse the command man page."""
colors = get_config()['colors']
with io.open(page, encoding='utf-8') as f:
lines = f.readlines()
output_lines = []
for line in lines[1:]:
if is_headline(line):
continue
elif is_description(line):
... | python | def parse_page(page):
"""Parse the command man page."""
colors = get_config()['colors']
with io.open(page, encoding='utf-8') as f:
lines = f.readlines()
output_lines = []
for line in lines[1:]:
if is_headline(line):
continue
elif is_description(line):
... | [
"def",
"parse_page",
"(",
"page",
")",
":",
"colors",
"=",
"get_config",
"(",
")",
"[",
"'colors'",
"]",
"with",
"io",
".",
"open",
"(",
"page",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"f",
":",
"lines",
"=",
"f",
".",
"readlines",
"(",
")",
... | Parse the command man page. | [
"Parse",
"the",
"command",
"man",
"page",
"."
] | train | https://github.com/lord63/tldr.py/blob/73cf9f86254691b2476910ea6a743b6d8bd04963/tldr/parser.py#L12-L34 |
unbit/sftpclone | sftpclone/sftpclone.py | configure_logging | def configure_logging(level=logging.DEBUG):
"""Configure the module logging engine."""
if level == logging.DEBUG:
# For debugging purposes, log from everyone!
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s'
)
re... | python | def configure_logging(level=logging.DEBUG):
"""Configure the module logging engine."""
if level == logging.DEBUG:
# For debugging purposes, log from everyone!
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s'
)
re... | [
"def",
"configure_logging",
"(",
"level",
"=",
"logging",
".",
"DEBUG",
")",
":",
"if",
"level",
"==",
"logging",
".",
"DEBUG",
":",
"# For debugging purposes, log from everyone!",
"logging",
".",
"basicConfig",
"(",
"level",
"=",
"logging",
".",
"DEBUG",
",",
... | Configure the module logging engine. | [
"Configure",
"the",
"module",
"logging",
"engine",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L33-L50 |
unbit/sftpclone | sftpclone/sftpclone.py | path_join | def path_join(*args):
"""
Wrapper around `os.path.join`.
Makes sure to join paths of the same type (bytes).
"""
args = (paramiko.py3compat.u(arg) for arg in args)
return os.path.join(*args) | python | def path_join(*args):
"""
Wrapper around `os.path.join`.
Makes sure to join paths of the same type (bytes).
"""
args = (paramiko.py3compat.u(arg) for arg in args)
return os.path.join(*args) | [
"def",
"path_join",
"(",
"*",
"args",
")",
":",
"args",
"=",
"(",
"paramiko",
".",
"py3compat",
".",
"u",
"(",
"arg",
")",
"for",
"arg",
"in",
"args",
")",
"return",
"os",
".",
"path",
".",
"join",
"(",
"*",
"args",
")"
] | Wrapper around `os.path.join`.
Makes sure to join paths of the same type (bytes). | [
"Wrapper",
"around",
"os",
".",
"path",
".",
"join",
".",
"Makes",
"sure",
"to",
"join",
"paths",
"of",
"the",
"same",
"type",
"(",
"bytes",
")",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L53-L59 |
unbit/sftpclone | sftpclone/sftpclone.py | parse_username_password_hostname | def parse_username_password_hostname(remote_url):
"""
Parse a command line string and return username, password, remote hostname and remote path.
:param remote_url: A command line string.
:return: A tuple, containing username, password, remote hostname and remote path.
"""
assert remote_url
... | python | def parse_username_password_hostname(remote_url):
"""
Parse a command line string and return username, password, remote hostname and remote path.
:param remote_url: A command line string.
:return: A tuple, containing username, password, remote hostname and remote path.
"""
assert remote_url
... | [
"def",
"parse_username_password_hostname",
"(",
"remote_url",
")",
":",
"assert",
"remote_url",
"assert",
"':'",
"in",
"remote_url",
"if",
"'@'",
"in",
"remote_url",
":",
"username",
",",
"hostname",
"=",
"remote_url",
".",
"rsplit",
"(",
"'@'",
",",
"1",
")",... | Parse a command line string and return username, password, remote hostname and remote path.
:param remote_url: A command line string.
:return: A tuple, containing username, password, remote hostname and remote path. | [
"Parse",
"a",
"command",
"line",
"string",
"and",
"return",
"username",
"password",
"remote",
"hostname",
"and",
"remote",
"path",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L62-L85 |
unbit/sftpclone | sftpclone/sftpclone.py | get_ssh_agent_keys | def get_ssh_agent_keys(logger):
"""
Ask the SSH agent for a list of keys, and return it.
:return: A reference to the SSH agent and a list of keys.
"""
agent, agent_keys = None, None
try:
agent = paramiko.agent.Agent()
_agent_keys = agent.get_keys()
if not _agent_keys:
... | python | def get_ssh_agent_keys(logger):
"""
Ask the SSH agent for a list of keys, and return it.
:return: A reference to the SSH agent and a list of keys.
"""
agent, agent_keys = None, None
try:
agent = paramiko.agent.Agent()
_agent_keys = agent.get_keys()
if not _agent_keys:
... | [
"def",
"get_ssh_agent_keys",
"(",
"logger",
")",
":",
"agent",
",",
"agent_keys",
"=",
"None",
",",
"None",
"try",
":",
"agent",
"=",
"paramiko",
".",
"agent",
".",
"Agent",
"(",
")",
"_agent_keys",
"=",
"agent",
".",
"get_keys",
"(",
")",
"if",
"not",... | Ask the SSH agent for a list of keys, and return it.
:return: A reference to the SSH agent and a list of keys. | [
"Ask",
"the",
"SSH",
"agent",
"for",
"a",
"list",
"of",
"keys",
"and",
"return",
"it",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L88-L113 |
unbit/sftpclone | sftpclone/sftpclone.py | create_parser | def create_parser():
"""Create the CLI argument parser."""
parser = argparse.ArgumentParser(
description='Sync a local and a remote folder through SFTP.'
)
parser.add_argument(
"path",
type=str,
metavar="local-path",
help="the path of the local folder",
)
... | python | def create_parser():
"""Create the CLI argument parser."""
parser = argparse.ArgumentParser(
description='Sync a local and a remote folder through SFTP.'
)
parser.add_argument(
"path",
type=str,
metavar="local-path",
help="the path of the local folder",
)
... | [
"def",
"create_parser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Sync a local and a remote folder through SFTP.'",
")",
"parser",
".",
"add_argument",
"(",
"\"path\"",
",",
"type",
"=",
"str",
",",
"metavar",
"=",... | Create the CLI argument parser. | [
"Create",
"the",
"CLI",
"argument",
"parser",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L628-L747 |
unbit/sftpclone | sftpclone/sftpclone.py | main | def main(args=None):
"""The main."""
parser = create_parser()
args = vars(parser.parse_args(args))
log_mapping = {
'CRITICAL': logging.CRITICAL,
'ERROR': logging.ERROR,
'WARNING': logging.WARNING,
'INFO': logging.INFO,
'DEBUG': logging.DEBUG,
'NOTSET': lo... | python | def main(args=None):
"""The main."""
parser = create_parser()
args = vars(parser.parse_args(args))
log_mapping = {
'CRITICAL': logging.CRITICAL,
'ERROR': logging.ERROR,
'WARNING': logging.WARNING,
'INFO': logging.INFO,
'DEBUG': logging.DEBUG,
'NOTSET': lo... | [
"def",
"main",
"(",
"args",
"=",
"None",
")",
":",
"parser",
"=",
"create_parser",
"(",
")",
"args",
"=",
"vars",
"(",
"parser",
".",
"parse_args",
"(",
"args",
")",
")",
"log_mapping",
"=",
"{",
"'CRITICAL'",
":",
"logging",
".",
"CRITICAL",
",",
"'... | The main. | [
"The",
"main",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L750-L806 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone._must_be_deleted | def _must_be_deleted(local_path, r_st):
"""Return True if the remote correspondent of local_path has to be deleted.
i.e. if it doesn't exists locally or if it has a different type from the remote one."""
# if the file doesn't exists
if not os.path.lexists(local_path):
return... | python | def _must_be_deleted(local_path, r_st):
"""Return True if the remote correspondent of local_path has to be deleted.
i.e. if it doesn't exists locally or if it has a different type from the remote one."""
# if the file doesn't exists
if not os.path.lexists(local_path):
return... | [
"def",
"_must_be_deleted",
"(",
"local_path",
",",
"r_st",
")",
":",
"# if the file doesn't exists",
"if",
"not",
"os",
".",
"path",
".",
"lexists",
"(",
"local_path",
")",
":",
"return",
"True",
"# or if the file type is different",
"l_st",
"=",
"os",
".",
"lst... | Return True if the remote correspondent of local_path has to be deleted.
i.e. if it doesn't exists locally or if it has a different type from the remote one. | [
"Return",
"True",
"if",
"the",
"remote",
"correspondent",
"of",
"local_path",
"has",
"to",
"be",
"deleted",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L369-L382 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone._match_modes | def _match_modes(self, remote_path, l_st):
"""Match mod, utime and uid/gid with locals one."""
self.sftp.chmod(remote_path, S_IMODE(l_st.st_mode))
self.sftp.utime(remote_path, (l_st.st_atime, l_st.st_mtime))
if self.chown:
self.sftp.chown(remote_path, l_st.st_uid, l_st.st_gi... | python | def _match_modes(self, remote_path, l_st):
"""Match mod, utime and uid/gid with locals one."""
self.sftp.chmod(remote_path, S_IMODE(l_st.st_mode))
self.sftp.utime(remote_path, (l_st.st_atime, l_st.st_mtime))
if self.chown:
self.sftp.chown(remote_path, l_st.st_uid, l_st.st_gi... | [
"def",
"_match_modes",
"(",
"self",
",",
"remote_path",
",",
"l_st",
")",
":",
"self",
".",
"sftp",
".",
"chmod",
"(",
"remote_path",
",",
"S_IMODE",
"(",
"l_st",
".",
"st_mode",
")",
")",
"self",
".",
"sftp",
".",
"utime",
"(",
"remote_path",
",",
"... | Match mod, utime and uid/gid with locals one. | [
"Match",
"mod",
"utime",
"and",
"uid",
"/",
"gid",
"with",
"locals",
"one",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L384-L390 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone.file_upload | def file_upload(self, local_path, remote_path, l_st):
"""Upload local_path to remote_path and set permission and mtime."""
self.sftp.put(local_path, remote_path)
self._match_modes(remote_path, l_st) | python | def file_upload(self, local_path, remote_path, l_st):
"""Upload local_path to remote_path and set permission and mtime."""
self.sftp.put(local_path, remote_path)
self._match_modes(remote_path, l_st) | [
"def",
"file_upload",
"(",
"self",
",",
"local_path",
",",
"remote_path",
",",
"l_st",
")",
":",
"self",
".",
"sftp",
".",
"put",
"(",
"local_path",
",",
"remote_path",
")",
"self",
".",
"_match_modes",
"(",
"remote_path",
",",
"l_st",
")"
] | Upload local_path to remote_path and set permission and mtime. | [
"Upload",
"local_path",
"to",
"remote_path",
"and",
"set",
"permission",
"and",
"mtime",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L392-L395 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone.remote_delete | def remote_delete(self, remote_path, r_st):
"""Remove the remote directory node."""
# If it's a directory, then delete content and directory
if S_ISDIR(r_st.st_mode):
for item in self.sftp.listdir_attr(remote_path):
full_path = path_join(remote_path, item.filename)
... | python | def remote_delete(self, remote_path, r_st):
"""Remove the remote directory node."""
# If it's a directory, then delete content and directory
if S_ISDIR(r_st.st_mode):
for item in self.sftp.listdir_attr(remote_path):
full_path = path_join(remote_path, item.filename)
... | [
"def",
"remote_delete",
"(",
"self",
",",
"remote_path",
",",
"r_st",
")",
":",
"# If it's a directory, then delete content and directory",
"if",
"S_ISDIR",
"(",
"r_st",
".",
"st_mode",
")",
":",
"for",
"item",
"in",
"self",
".",
"sftp",
".",
"listdir_attr",
"("... | Remove the remote directory node. | [
"Remove",
"the",
"remote",
"directory",
"node",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L397-L413 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone.check_for_deletion | def check_for_deletion(self, relative_path=None):
"""Traverse the entire remote_path tree.
Find files/directories that need to be deleted,
not being present in the local folder.
"""
if not relative_path:
relative_path = str() # root of shared directory tree
... | python | def check_for_deletion(self, relative_path=None):
"""Traverse the entire remote_path tree.
Find files/directories that need to be deleted,
not being present in the local folder.
"""
if not relative_path:
relative_path = str() # root of shared directory tree
... | [
"def",
"check_for_deletion",
"(",
"self",
",",
"relative_path",
"=",
"None",
")",
":",
"if",
"not",
"relative_path",
":",
"relative_path",
"=",
"str",
"(",
")",
"# root of shared directory tree",
"remote_path",
"=",
"path_join",
"(",
"self",
".",
"remote_path",
... | Traverse the entire remote_path tree.
Find files/directories that need to be deleted,
not being present in the local folder. | [
"Traverse",
"the",
"entire",
"remote_path",
"tree",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L415-L445 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone.create_update_symlink | def create_update_symlink(self, link_destination, remote_path):
"""Create a new link pointing to link_destination in remote_path position."""
try: # if there's anything, delete it
self.sftp.remove(remote_path)
except IOError: # that's fine, nothing exists there!
pass
... | python | def create_update_symlink(self, link_destination, remote_path):
"""Create a new link pointing to link_destination in remote_path position."""
try: # if there's anything, delete it
self.sftp.remove(remote_path)
except IOError: # that's fine, nothing exists there!
pass
... | [
"def",
"create_update_symlink",
"(",
"self",
",",
"link_destination",
",",
"remote_path",
")",
":",
"try",
":",
"# if there's anything, delete it",
"self",
".",
"sftp",
".",
"remove",
"(",
"remote_path",
")",
"except",
"IOError",
":",
"# that's fine, nothing exists th... | Create a new link pointing to link_destination in remote_path position. | [
"Create",
"a",
"new",
"link",
"pointing",
"to",
"link_destination",
"in",
"remote_path",
"position",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L447-L460 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone.node_check_for_upload_create | def node_check_for_upload_create(self, relative_path, f):
"""Check if the given directory tree node has to be uploaded/created on the remote folder."""
if not relative_path:
# we're at the root of the shared directory tree
relative_path = str()
# the (absolute) local add... | python | def node_check_for_upload_create(self, relative_path, f):
"""Check if the given directory tree node has to be uploaded/created on the remote folder."""
if not relative_path:
# we're at the root of the shared directory tree
relative_path = str()
# the (absolute) local add... | [
"def",
"node_check_for_upload_create",
"(",
"self",
",",
"relative_path",
",",
"f",
")",
":",
"if",
"not",
"relative_path",
":",
"# we're at the root of the shared directory tree",
"relative_path",
"=",
"str",
"(",
")",
"# the (absolute) local address of f.",
"local_path",
... | Check if the given directory tree node has to be uploaded/created on the remote folder. | [
"Check",
"if",
"the",
"given",
"directory",
"tree",
"node",
"has",
"to",
"be",
"uploaded",
"/",
"created",
"on",
"the",
"remote",
"folder",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L462-L583 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone.check_for_upload_create | def check_for_upload_create(self, relative_path=None):
"""Traverse the relative_path tree and check for files that need to be uploaded/created.
Relativity here refers to the shared directory tree."""
for f in os.listdir(
path_join(
self.local_path, relative_path) if ... | python | def check_for_upload_create(self, relative_path=None):
"""Traverse the relative_path tree and check for files that need to be uploaded/created.
Relativity here refers to the shared directory tree."""
for f in os.listdir(
path_join(
self.local_path, relative_path) if ... | [
"def",
"check_for_upload_create",
"(",
"self",
",",
"relative_path",
"=",
"None",
")",
":",
"for",
"f",
"in",
"os",
".",
"listdir",
"(",
"path_join",
"(",
"self",
".",
"local_path",
",",
"relative_path",
")",
"if",
"relative_path",
"else",
"self",
".",
"lo... | Traverse the relative_path tree and check for files that need to be uploaded/created.
Relativity here refers to the shared directory tree. | [
"Traverse",
"the",
"relative_path",
"tree",
"and",
"check",
"for",
"files",
"that",
"need",
"to",
"be",
"uploaded",
"/",
"created",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L585-L593 |
unbit/sftpclone | sftpclone/sftpclone.py | SFTPClone.run | def run(self):
"""Run the sync.
Confront the local and the remote directories and perform the needed changes."""
# Check if remote path is present
try:
self.sftp.stat(self.remote_path)
except FileNotFoundError as e:
if self.create_remote_directory:
... | python | def run(self):
"""Run the sync.
Confront the local and the remote directories and perform the needed changes."""
# Check if remote path is present
try:
self.sftp.stat(self.remote_path)
except FileNotFoundError as e:
if self.create_remote_directory:
... | [
"def",
"run",
"(",
"self",
")",
":",
"# Check if remote path is present",
"try",
":",
"self",
".",
"sftp",
".",
"stat",
"(",
"self",
".",
"remote_path",
")",
"except",
"FileNotFoundError",
"as",
"e",
":",
"if",
"self",
".",
"create_remote_directory",
":",
"s... | Run the sync.
Confront the local and the remote directories and perform the needed changes. | [
"Run",
"the",
"sync",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/sftpclone.py#L595-L625 |
unbit/sftpclone | sftpclone/t/utils.py | list_files | def list_files(start_path):
"""tree unix command replacement."""
s = u'\n'
for root, dirs, files in os.walk(start_path):
level = root.replace(start_path, '').count(os.sep)
indent = ' ' * 4 * level
s += u'{}{}/\n'.format(indent, os.path.basename(root))
sub_indent = ' ' * 4 * (... | python | def list_files(start_path):
"""tree unix command replacement."""
s = u'\n'
for root, dirs, files in os.walk(start_path):
level = root.replace(start_path, '').count(os.sep)
indent = ' ' * 4 * level
s += u'{}{}/\n'.format(indent, os.path.basename(root))
sub_indent = ' ' * 4 * (... | [
"def",
"list_files",
"(",
"start_path",
")",
":",
"s",
"=",
"u'\\n'",
"for",
"root",
",",
"dirs",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"start_path",
")",
":",
"level",
"=",
"root",
".",
"replace",
"(",
"start_path",
",",
"''",
")",
".",
"cou... | tree unix command replacement. | [
"tree",
"unix",
"command",
"replacement",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/t/utils.py#L26-L36 |
unbit/sftpclone | sftpclone/t/utils.py | file_tree | def file_tree(start_path):
"""
Create a nested dictionary that represents the folder structure of `start_path`.
Liberally adapted from
http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/
"""
nested_dirs = {}
root_dir = start_path.rstrip(os.sep)
start = roo... | python | def file_tree(start_path):
"""
Create a nested dictionary that represents the folder structure of `start_path`.
Liberally adapted from
http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/
"""
nested_dirs = {}
root_dir = start_path.rstrip(os.sep)
start = roo... | [
"def",
"file_tree",
"(",
"start_path",
")",
":",
"nested_dirs",
"=",
"{",
"}",
"root_dir",
"=",
"start_path",
".",
"rstrip",
"(",
"os",
".",
"sep",
")",
"start",
"=",
"root_dir",
".",
"rfind",
"(",
"os",
".",
"sep",
")",
"+",
"1",
"for",
"path",
",... | Create a nested dictionary that represents the folder structure of `start_path`.
Liberally adapted from
http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/ | [
"Create",
"a",
"nested",
"dictionary",
"that",
"represents",
"the",
"folder",
"structure",
"of",
"start_path",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/t/utils.py#L39-L54 |
unbit/sftpclone | sftpclone/t/utils.py | capture_sys_output | def capture_sys_output():
"""Capture standard output and error."""
capture_out, capture_err = StringIO(), StringIO()
current_out, current_err = sys.stdout, sys.stderr
try:
sys.stdout, sys.stderr = capture_out, capture_err
yield capture_out, capture_err
finally:
sys.stdout, sy... | python | def capture_sys_output():
"""Capture standard output and error."""
capture_out, capture_err = StringIO(), StringIO()
current_out, current_err = sys.stdout, sys.stderr
try:
sys.stdout, sys.stderr = capture_out, capture_err
yield capture_out, capture_err
finally:
sys.stdout, sy... | [
"def",
"capture_sys_output",
"(",
")",
":",
"capture_out",
",",
"capture_err",
"=",
"StringIO",
"(",
")",
",",
"StringIO",
"(",
")",
"current_out",
",",
"current_err",
"=",
"sys",
".",
"stdout",
",",
"sys",
".",
"stderr",
"try",
":",
"sys",
".",
"stdout"... | Capture standard output and error. | [
"Capture",
"standard",
"output",
"and",
"error",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/t/utils.py#L58-L66 |
unbit/sftpclone | sftpclone/t/utils.py | suppress_logging | def suppress_logging(log_level=logging.CRITICAL):
"""Suppress logging."""
logging.disable(log_level)
yield
logging.disable(logging.NOTSET) | python | def suppress_logging(log_level=logging.CRITICAL):
"""Suppress logging."""
logging.disable(log_level)
yield
logging.disable(logging.NOTSET) | [
"def",
"suppress_logging",
"(",
"log_level",
"=",
"logging",
".",
"CRITICAL",
")",
":",
"logging",
".",
"disable",
"(",
"log_level",
")",
"yield",
"logging",
".",
"disable",
"(",
"logging",
".",
"NOTSET",
")"
] | Suppress logging. | [
"Suppress",
"logging",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/t/utils.py#L70-L74 |
unbit/sftpclone | sftpclone/t/utils.py | override_env_variables | def override_env_variables():
"""Override user environmental variables with custom one."""
env_vars = ("LOGNAME", "USER", "LNAME", "USERNAME")
old = [os.environ[v] if v in os.environ else None for v in env_vars]
for v in env_vars:
os.environ[v] = "test"
yield
for i, v in enumerate(env_... | python | def override_env_variables():
"""Override user environmental variables with custom one."""
env_vars = ("LOGNAME", "USER", "LNAME", "USERNAME")
old = [os.environ[v] if v in os.environ else None for v in env_vars]
for v in env_vars:
os.environ[v] = "test"
yield
for i, v in enumerate(env_... | [
"def",
"override_env_variables",
"(",
")",
":",
"env_vars",
"=",
"(",
"\"LOGNAME\"",
",",
"\"USER\"",
",",
"\"LNAME\"",
",",
"\"USERNAME\"",
")",
"old",
"=",
"[",
"os",
".",
"environ",
"[",
"v",
"]",
"if",
"v",
"in",
"os",
".",
"environ",
"else",
"None... | Override user environmental variables with custom one. | [
"Override",
"user",
"environmental",
"variables",
"with",
"custom",
"one",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/t/utils.py#L78-L89 |
unbit/sftpclone | sftpclone/t/utils.py | override_ssh_auth_env | def override_ssh_auth_env():
"""Override the `$SSH_AUTH_SOCK `env variable to mock the absence of an SSH agent."""
ssh_auth_sock = "SSH_AUTH_SOCK"
old_ssh_auth_sock = os.environ.get(ssh_auth_sock)
del os.environ[ssh_auth_sock]
yield
if old_ssh_auth_sock:
os.environ[ssh_auth_sock] = ol... | python | def override_ssh_auth_env():
"""Override the `$SSH_AUTH_SOCK `env variable to mock the absence of an SSH agent."""
ssh_auth_sock = "SSH_AUTH_SOCK"
old_ssh_auth_sock = os.environ.get(ssh_auth_sock)
del os.environ[ssh_auth_sock]
yield
if old_ssh_auth_sock:
os.environ[ssh_auth_sock] = ol... | [
"def",
"override_ssh_auth_env",
"(",
")",
":",
"ssh_auth_sock",
"=",
"\"SSH_AUTH_SOCK\"",
"old_ssh_auth_sock",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"ssh_auth_sock",
")",
"del",
"os",
".",
"environ",
"[",
"ssh_auth_sock",
"]",
"yield",
"if",
"old_ssh_auth_... | Override the `$SSH_AUTH_SOCK `env variable to mock the absence of an SSH agent. | [
"Override",
"the",
"$SSH_AUTH_SOCK",
"env",
"variable",
"to",
"mock",
"the",
"absence",
"of",
"an",
"SSH",
"agent",
"."
] | train | https://github.com/unbit/sftpclone/blob/1cc89478e680fc4e0d12b1a15b5bafd0390d05da/sftpclone/t/utils.py#L93-L103 |
lord63/tldr.py | tldr/config.py | get_config | def get_config():
"""Get the configurations from .tldrrc and return it as a dict."""
config_path = path.join(
(os.environ.get('TLDR_CONFIG_DIR') or path.expanduser('~')),
'.tldrrc')
if not path.exists(config_path):
sys.exit("Can't find config file at: {0}. You may use `tldr init` "
... | python | def get_config():
"""Get the configurations from .tldrrc and return it as a dict."""
config_path = path.join(
(os.environ.get('TLDR_CONFIG_DIR') or path.expanduser('~')),
'.tldrrc')
if not path.exists(config_path):
sys.exit("Can't find config file at: {0}. You may use `tldr init` "
... | [
"def",
"get_config",
"(",
")",
":",
"config_path",
"=",
"path",
".",
"join",
"(",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'TLDR_CONFIG_DIR'",
")",
"or",
"path",
".",
"expanduser",
"(",
"'~'",
")",
")",
",",
"'.tldrrc'",
")",
"if",
"not",
"path",... | Get the configurations from .tldrrc and return it as a dict. | [
"Get",
"the",
"configurations",
"from",
".",
"tldrrc",
"and",
"return",
"it",
"as",
"a",
"dict",
"."
] | train | https://github.com/lord63/tldr.py/blob/73cf9f86254691b2476910ea6a743b6d8bd04963/tldr/config.py#L14-L38 |
lord63/tldr.py | tldr/cli.py | parse_man_page | def parse_man_page(command, platform):
"""Parse the man page and return the parsed lines."""
page_path = find_page_location(command, platform)
output_lines = parse_page(page_path)
return output_lines | python | def parse_man_page(command, platform):
"""Parse the man page and return the parsed lines."""
page_path = find_page_location(command, platform)
output_lines = parse_page(page_path)
return output_lines | [
"def",
"parse_man_page",
"(",
"command",
",",
"platform",
")",
":",
"page_path",
"=",
"find_page_location",
"(",
"command",
",",
"platform",
")",
"output_lines",
"=",
"parse_page",
"(",
"page_path",
")",
"return",
"output_lines"
] | Parse the man page and return the parsed lines. | [
"Parse",
"the",
"man",
"page",
"and",
"return",
"the",
"parsed",
"lines",
"."
] | train | https://github.com/lord63/tldr.py/blob/73cf9f86254691b2476910ea6a743b6d8bd04963/tldr/cli.py#L22-L26 |
lord63/tldr.py | tldr/cli.py | find_page_location | def find_page_location(command, specified_platform):
"""Find the command man page in the pages directory."""
repo_directory = get_config()['repo_directory']
default_platform = get_config()['platform']
command_platform = (
specified_platform if specified_platform else default_platform)
with ... | python | def find_page_location(command, specified_platform):
"""Find the command man page in the pages directory."""
repo_directory = get_config()['repo_directory']
default_platform = get_config()['platform']
command_platform = (
specified_platform if specified_platform else default_platform)
with ... | [
"def",
"find_page_location",
"(",
"command",
",",
"specified_platform",
")",
":",
"repo_directory",
"=",
"get_config",
"(",
")",
"[",
"'repo_directory'",
"]",
"default_platform",
"=",
"get_config",
"(",
")",
"[",
"'platform'",
"]",
"command_platform",
"=",
"(",
... | Find the command man page in the pages directory. | [
"Find",
"the",
"command",
"man",
"page",
"in",
"the",
"pages",
"directory",
"."
] | train | https://github.com/lord63/tldr.py/blob/73cf9f86254691b2476910ea6a743b6d8bd04963/tldr/cli.py#L29-L62 |
lord63/tldr.py | tldr/cli.py | find | def find(command, on):
"""Find the command usage."""
output_lines = parse_man_page(command, on)
click.echo(''.join(output_lines)) | python | def find(command, on):
"""Find the command usage."""
output_lines = parse_man_page(command, on)
click.echo(''.join(output_lines)) | [
"def",
"find",
"(",
"command",
",",
"on",
")",
":",
"output_lines",
"=",
"parse_man_page",
"(",
"command",
",",
"on",
")",
"click",
".",
"echo",
"(",
"''",
".",
"join",
"(",
"output_lines",
")",
")"
] | Find the command usage. | [
"Find",
"the",
"command",
"usage",
"."
] | train | https://github.com/lord63/tldr.py/blob/73cf9f86254691b2476910ea6a743b6d8bd04963/tldr/cli.py#L101-L104 |
lord63/tldr.py | tldr/cli.py | update | def update():
"""Update to the latest pages."""
repo_directory = get_config()['repo_directory']
os.chdir(repo_directory)
click.echo("Check for updates...")
local = subprocess.check_output('git rev-parse master'.split()).strip()
remote = subprocess.check_output(
'git ls-remote https://gi... | python | def update():
"""Update to the latest pages."""
repo_directory = get_config()['repo_directory']
os.chdir(repo_directory)
click.echo("Check for updates...")
local = subprocess.check_output('git rev-parse master'.split()).strip()
remote = subprocess.check_output(
'git ls-remote https://gi... | [
"def",
"update",
"(",
")",
":",
"repo_directory",
"=",
"get_config",
"(",
")",
"[",
"'repo_directory'",
"]",
"os",
".",
"chdir",
"(",
"repo_directory",
")",
"click",
".",
"echo",
"(",
"\"Check for updates...\"",
")",
"local",
"=",
"subprocess",
".",
"check_o... | Update to the latest pages. | [
"Update",
"to",
"the",
"latest",
"pages",
"."
] | train | https://github.com/lord63/tldr.py/blob/73cf9f86254691b2476910ea6a743b6d8bd04963/tldr/cli.py#L108-L125 |
lord63/tldr.py | tldr/cli.py | init | def init():
"""Init config file."""
default_config_path = path.join(
(os.environ.get('TLDR_CONFIG_DIR') or path.expanduser('~')),
'.tldrrc')
if path.exists(default_config_path):
click.echo("There is already a config file exists, "
"skip initializing it.")
else:... | python | def init():
"""Init config file."""
default_config_path = path.join(
(os.environ.get('TLDR_CONFIG_DIR') or path.expanduser('~')),
'.tldrrc')
if path.exists(default_config_path):
click.echo("There is already a config file exists, "
"skip initializing it.")
else:... | [
"def",
"init",
"(",
")",
":",
"default_config_path",
"=",
"path",
".",
"join",
"(",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'TLDR_CONFIG_DIR'",
")",
"or",
"path",
".",
"expanduser",
"(",
"'~'",
")",
")",
",",
"'.tldrrc'",
")",
"if",
"path",
".",... | Init config file. | [
"Init",
"config",
"file",
"."
] | train | https://github.com/lord63/tldr.py/blob/73cf9f86254691b2476910ea6a743b6d8bd04963/tldr/cli.py#L129-L161 |
lord63/tldr.py | tldr/cli.py | locate | def locate(command, on):
"""Locate the command's man page."""
location = find_page_location(command, on)
click.echo(location) | python | def locate(command, on):
"""Locate the command's man page."""
location = find_page_location(command, on)
click.echo(location) | [
"def",
"locate",
"(",
"command",
",",
"on",
")",
":",
"location",
"=",
"find_page_location",
"(",
"command",
",",
"on",
")",
"click",
".",
"echo",
"(",
"location",
")"
] | Locate the command's man page. | [
"Locate",
"the",
"command",
"s",
"man",
"page",
"."
] | train | https://github.com/lord63/tldr.py/blob/73cf9f86254691b2476910ea6a743b6d8bd04963/tldr/cli.py#L175-L178 |
brentp/cruzdb | cruzdb/sqlsoup.py | TableClassType.relate | def relate(cls, propname, *args, **kwargs):
"""Produce a relationship between this mapped table and another
one.
This makes usage of SQLAlchemy's :func:`sqlalchemy.orm.relationship`
construct.
"""
class_mapper(cls)._configure_property(propname, relation... | python | def relate(cls, propname, *args, **kwargs):
"""Produce a relationship between this mapped table and another
one.
This makes usage of SQLAlchemy's :func:`sqlalchemy.orm.relationship`
construct.
"""
class_mapper(cls)._configure_property(propname, relation... | [
"def",
"relate",
"(",
"cls",
",",
"propname",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"class_mapper",
"(",
"cls",
")",
".",
"_configure_property",
"(",
"propname",
",",
"relationship",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
")"
... | Produce a relationship between this mapped table and another
one.
This makes usage of SQLAlchemy's :func:`sqlalchemy.orm.relationship`
construct. | [
"Produce",
"a",
"relationship",
"between",
"this",
"mapped",
"table",
"and",
"another",
"one",
".",
"This",
"makes",
"usage",
"of",
"SQLAlchemy",
"s",
":",
"func",
":",
"sqlalchemy",
".",
"orm",
".",
"relationship",
"construct",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/sqlsoup.py#L93-L101 |
brentp/cruzdb | cruzdb/sqlsoup.py | SQLSoup.execute | def execute(self, stmt, **params):
"""Execute a SQL statement.
The statement may be a string SQL string,
an :func:`sqlalchemy.sql.expression.select` construct, or a
:func:`sqlalchemy.sql.expression.text`
construct.
"""
return self.session.execute(sql.text(stmt... | python | def execute(self, stmt, **params):
"""Execute a SQL statement.
The statement may be a string SQL string,
an :func:`sqlalchemy.sql.expression.select` construct, or a
:func:`sqlalchemy.sql.expression.text`
construct.
"""
return self.session.execute(sql.text(stmt... | [
"def",
"execute",
"(",
"self",
",",
"stmt",
",",
"*",
"*",
"params",
")",
":",
"return",
"self",
".",
"session",
".",
"execute",
"(",
"sql",
".",
"text",
"(",
"stmt",
",",
"bind",
"=",
"self",
".",
"bind",
")",
",",
"*",
"*",
"params",
")"
] | Execute a SQL statement.
The statement may be a string SQL string,
an :func:`sqlalchemy.sql.expression.select` construct, or a
:func:`sqlalchemy.sql.expression.text`
construct. | [
"Execute",
"a",
"SQL",
"statement",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/sqlsoup.py#L229-L238 |
brentp/cruzdb | cruzdb/sqlsoup.py | SQLSoup.map_to | def map_to(self, attrname, tablename=None, selectable=None,
schema=None, base=None, mapper_args=util.immutabledict()):
"""Configure a mapping to the given attrname.
This is the "master" method that can be used to create any
configuration.
:param attrname: String a... | python | def map_to(self, attrname, tablename=None, selectable=None,
schema=None, base=None, mapper_args=util.immutabledict()):
"""Configure a mapping to the given attrname.
This is the "master" method that can be used to create any
configuration.
:param attrname: String a... | [
"def",
"map_to",
"(",
"self",
",",
"attrname",
",",
"tablename",
"=",
"None",
",",
"selectable",
"=",
"None",
",",
"schema",
"=",
"None",
",",
"base",
"=",
"None",
",",
"mapper_args",
"=",
"util",
".",
"immutabledict",
"(",
")",
")",
":",
"if",
"attr... | Configure a mapping to the given attrname.
This is the "master" method that can be used to create any
configuration.
:param attrname: String attribute name which will be
established as an attribute on this :class:.`.SQLSoup`
instance.
:param base: a Python class wh... | [
"Configure",
"a",
"mapping",
"to",
"the",
"given",
"attrname",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/sqlsoup.py#L292-L373 |
brentp/cruzdb | cruzdb/sqlsoup.py | SQLSoup.map | def map(self, selectable, base=None, **mapper_args):
"""Map a selectable directly.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param selectable: an :func:`.expression.select` construct.
:param base: a Python class which will ... | python | def map(self, selectable, base=None, **mapper_args):
"""Map a selectable directly.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param selectable: an :func:`.expression.select` construct.
:param base: a Python class which will ... | [
"def",
"map",
"(",
"self",
",",
"selectable",
",",
"base",
"=",
"None",
",",
"*",
"*",
"mapper_args",
")",
":",
"return",
"_class_for_table",
"(",
"self",
".",
"session",
",",
"self",
".",
"engine",
",",
"selectable",
",",
"base",
"or",
"self",
".",
... | Map a selectable directly.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param selectable: an :func:`.expression.select` construct.
:param base: a Python class which will be used as the
base for the mapped class. If ``None``,... | [
"Map",
"a",
"selectable",
"directly",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/sqlsoup.py#L376-L399 |
brentp/cruzdb | cruzdb/sqlsoup.py | SQLSoup.with_labels | def with_labels(self, selectable, base=None, **mapper_args):
"""Map a selectable directly, wrapping the
selectable in a subquery with labels.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param selectable: an :func:`.expressio... | python | def with_labels(self, selectable, base=None, **mapper_args):
"""Map a selectable directly, wrapping the
selectable in a subquery with labels.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param selectable: an :func:`.expressio... | [
"def",
"with_labels",
"(",
"self",
",",
"selectable",
",",
"base",
"=",
"None",
",",
"*",
"*",
"mapper_args",
")",
":",
"# TODO give meaningful aliases",
"return",
"self",
".",
"map",
"(",
"expression",
".",
"_clause_element_as_expr",
"(",
"selectable",
")",
"... | Map a selectable directly, wrapping the
selectable in a subquery with labels.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param selectable: an :func:`.expression.select` construct.
:param base: a Python class which will be u... | [
"Map",
"a",
"selectable",
"directly",
"wrapping",
"the",
"selectable",
"in",
"a",
"subquery",
"with",
"labels",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/sqlsoup.py#L401-L423 |
brentp/cruzdb | cruzdb/sqlsoup.py | SQLSoup.join | def join(self, left, right, onclause=None, isouter=False,
base=None, **mapper_args):
"""Create an :func:`.expression.join` and map to it.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param left: a mapped class or tabl... | python | def join(self, left, right, onclause=None, isouter=False,
base=None, **mapper_args):
"""Create an :func:`.expression.join` and map to it.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param left: a mapped class or tabl... | [
"def",
"join",
"(",
"self",
",",
"left",
",",
"right",
",",
"onclause",
"=",
"None",
",",
"isouter",
"=",
"False",
",",
"base",
"=",
"None",
",",
"*",
"*",
"mapper_args",
")",
":",
"j",
"=",
"join",
"(",
"left",
",",
"right",
",",
"onclause",
"="... | Create an :func:`.expression.join` and map to it.
The class and its mapping are not cached and will
be discarded once dereferenced (as of 0.6.6).
:param left: a mapped class or table object.
:param right: a mapped class or table object.
:param onclause: optional "ON" clause con... | [
"Create",
"an",
":",
"func",
":",
".",
"expression",
".",
"join",
"and",
"map",
"to",
"it",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/sqlsoup.py#L425-L447 |
brentp/cruzdb | cruzdb/sqlsoup.py | SQLSoup.entity | def entity(self, attr, schema=None):
"""Return the named entity from this :class:`.SQLSoup`, or
create if not present.
For more generalized mapping, see :meth:`.map_to`.
"""
try:
return self._cache[attr]
except KeyError, ke:
return self.map_to(a... | python | def entity(self, attr, schema=None):
"""Return the named entity from this :class:`.SQLSoup`, or
create if not present.
For more generalized mapping, see :meth:`.map_to`.
"""
try:
return self._cache[attr]
except KeyError, ke:
return self.map_to(a... | [
"def",
"entity",
"(",
"self",
",",
"attr",
",",
"schema",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"_cache",
"[",
"attr",
"]",
"except",
"KeyError",
",",
"ke",
":",
"return",
"self",
".",
"map_to",
"(",
"attr",
",",
"tablename",
"=... | Return the named entity from this :class:`.SQLSoup`, or
create if not present.
For more generalized mapping, see :meth:`.map_to`. | [
"Return",
"the",
"named",
"entity",
"from",
"this",
":",
"class",
":",
".",
"SQLSoup",
"or",
"create",
"if",
"not",
"present",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/sqlsoup.py#L449-L459 |
brentp/cruzdb | cruzdb/intersecter.py | distance | def distance(f1, f2):
"""\
Distance between 2 features. The integer result is always positive or zero.
If the features overlap or touch, it is zero.
>>> from intersecter import Feature, distance
>>> distance(Feature(1, 2), Feature(12, 13))
10
>>> distance(Feature(1, 2), Feature(2, 3))
0
... | python | def distance(f1, f2):
"""\
Distance between 2 features. The integer result is always positive or zero.
If the features overlap or touch, it is zero.
>>> from intersecter import Feature, distance
>>> distance(Feature(1, 2), Feature(12, 13))
10
>>> distance(Feature(1, 2), Feature(2, 3))
0
... | [
"def",
"distance",
"(",
"f1",
",",
"f2",
")",
":",
"if",
"f1",
".",
"end",
"<",
"f2",
".",
"start",
":",
"return",
"f2",
".",
"start",
"-",
"f1",
".",
"end",
"if",
"f2",
".",
"end",
"<",
"f1",
".",
"start",
":",
"return",
"f1",
".",
"start",
... | \
Distance between 2 features. The integer result is always positive or zero.
If the features overlap or touch, it is zero.
>>> from intersecter import Feature, distance
>>> distance(Feature(1, 2), Feature(12, 13))
10
>>> distance(Feature(1, 2), Feature(2, 3))
0
>>> distance(Feature(1, 1... | [
"\\",
"Distance",
"between",
"2",
"features",
".",
"The",
"integer",
"result",
"is",
"always",
"positive",
"or",
"zero",
".",
"If",
"the",
"features",
"overlap",
"or",
"touch",
"it",
"is",
"zero",
".",
">>>",
"from",
"intersecter",
"import",
"Feature",
"di... | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/intersecter.py#L269-L284 |
brentp/cruzdb | cruzdb/intersecter.py | Intersecter.find | def find(self, start, end, chrom=None):
"""Return a object of all stored intervals intersecting between (start, end) inclusive."""
intervals = self.intervals[chrom]
ilen = len(intervals)
# NOTE: we only search for starts, since any feature that starts within max_len of
# the quer... | python | def find(self, start, end, chrom=None):
"""Return a object of all stored intervals intersecting between (start, end) inclusive."""
intervals = self.intervals[chrom]
ilen = len(intervals)
# NOTE: we only search for starts, since any feature that starts within max_len of
# the quer... | [
"def",
"find",
"(",
"self",
",",
"start",
",",
"end",
",",
"chrom",
"=",
"None",
")",
":",
"intervals",
"=",
"self",
".",
"intervals",
"[",
"chrom",
"]",
"ilen",
"=",
"len",
"(",
"intervals",
")",
"# NOTE: we only search for starts, since any feature that star... | Return a object of all stored intervals intersecting between (start, end) inclusive. | [
"Return",
"a",
"object",
"of",
"all",
"stored",
"intervals",
"intersecting",
"between",
"(",
"start",
"end",
")",
"inclusive",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/intersecter.py#L147-L161 |
brentp/cruzdb | cruzdb/intersecter.py | Intersecter.left | def left(self, f, n=1):
"""return the nearest n features strictly to the left of a Feature f.
Overlapping features are not considered as to the left.
f: a Feature object
n: the number of features to return
"""
intervals = self.intervals[f.chrom]
if intervals == [... | python | def left(self, f, n=1):
"""return the nearest n features strictly to the left of a Feature f.
Overlapping features are not considered as to the left.
f: a Feature object
n: the number of features to return
"""
intervals = self.intervals[f.chrom]
if intervals == [... | [
"def",
"left",
"(",
"self",
",",
"f",
",",
"n",
"=",
"1",
")",
":",
"intervals",
"=",
"self",
".",
"intervals",
"[",
"f",
".",
"chrom",
"]",
"if",
"intervals",
"==",
"[",
"]",
":",
"return",
"[",
"]",
"iright",
"=",
"binsearch_left_start",
"(",
"... | return the nearest n features strictly to the left of a Feature f.
Overlapping features are not considered as to the left.
f: a Feature object
n: the number of features to return | [
"return",
"the",
"nearest",
"n",
"features",
"strictly",
"to",
"the",
"left",
"of",
"a",
"Feature",
"f",
".",
"Overlapping",
"features",
"are",
"not",
"considered",
"as",
"to",
"the",
"left",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/intersecter.py#L163-L192 |
brentp/cruzdb | cruzdb/intersecter.py | Intersecter.right | def right(self, f, n=1):
"""return the nearest n features strictly to the right of a Feature f.
Overlapping features are not considered as to the right.
f: a Feature object
n: the number of features to return
"""
intervals = self.intervals[f.chrom]
ilen = len(int... | python | def right(self, f, n=1):
"""return the nearest n features strictly to the right of a Feature f.
Overlapping features are not considered as to the right.
f: a Feature object
n: the number of features to return
"""
intervals = self.intervals[f.chrom]
ilen = len(int... | [
"def",
"right",
"(",
"self",
",",
"f",
",",
"n",
"=",
"1",
")",
":",
"intervals",
"=",
"self",
".",
"intervals",
"[",
"f",
".",
"chrom",
"]",
"ilen",
"=",
"len",
"(",
"intervals",
")",
"iright",
"=",
"binsearch_right_end",
"(",
"intervals",
",",
"f... | return the nearest n features strictly to the right of a Feature f.
Overlapping features are not considered as to the right.
f: a Feature object
n: the number of features to return | [
"return",
"the",
"nearest",
"n",
"features",
"strictly",
"to",
"the",
"right",
"of",
"a",
"Feature",
"f",
".",
"Overlapping",
"features",
"are",
"not",
"considered",
"as",
"to",
"the",
"right",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/intersecter.py#L194-L215 |
brentp/cruzdb | cruzdb/intersecter.py | Intersecter.upstream | def upstream(self, f, n=1):
"""find n upstream features where upstream is determined by
the strand of the query Feature f
Overlapping features are not considered.
f: a Feature object
n: the number of features to return
"""
if f.strand == -1:
return se... | python | def upstream(self, f, n=1):
"""find n upstream features where upstream is determined by
the strand of the query Feature f
Overlapping features are not considered.
f: a Feature object
n: the number of features to return
"""
if f.strand == -1:
return se... | [
"def",
"upstream",
"(",
"self",
",",
"f",
",",
"n",
"=",
"1",
")",
":",
"if",
"f",
".",
"strand",
"==",
"-",
"1",
":",
"return",
"self",
".",
"right",
"(",
"f",
",",
"n",
")",
"return",
"self",
".",
"left",
"(",
"f",
",",
"n",
")"
] | find n upstream features where upstream is determined by
the strand of the query Feature f
Overlapping features are not considered.
f: a Feature object
n: the number of features to return | [
"find",
"n",
"upstream",
"features",
"where",
"upstream",
"is",
"determined",
"by",
"the",
"strand",
"of",
"the",
"query",
"Feature",
"f",
"Overlapping",
"features",
"are",
"not",
"considered",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/intersecter.py#L218-L228 |
brentp/cruzdb | cruzdb/intersecter.py | Intersecter.downstream | def downstream(self, f, n=1):
"""find n downstream features where downstream is determined by
the strand of the query Feature f
Overlapping features are not considered.
f: a Feature object
n: the number of features to return
"""
if f.strand == -1:
ret... | python | def downstream(self, f, n=1):
"""find n downstream features where downstream is determined by
the strand of the query Feature f
Overlapping features are not considered.
f: a Feature object
n: the number of features to return
"""
if f.strand == -1:
ret... | [
"def",
"downstream",
"(",
"self",
",",
"f",
",",
"n",
"=",
"1",
")",
":",
"if",
"f",
".",
"strand",
"==",
"-",
"1",
":",
"return",
"self",
".",
"left",
"(",
"f",
",",
"n",
")",
"return",
"self",
".",
"right",
"(",
"f",
",",
"n",
")"
] | find n downstream features where downstream is determined by
the strand of the query Feature f
Overlapping features are not considered.
f: a Feature object
n: the number of features to return | [
"find",
"n",
"downstream",
"features",
"where",
"downstream",
"is",
"determined",
"by",
"the",
"strand",
"of",
"the",
"query",
"Feature",
"f",
"Overlapping",
"features",
"are",
"not",
"considered",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/intersecter.py#L231-L241 |
brentp/cruzdb | cruzdb/intersecter.py | Intersecter.knearest | def knearest(self, f_or_start, end=None, chrom=None, k=1):
"""return the n nearest neighbors to the given feature
f: a Feature object
k: the number of features to return
"""
if end is not None:
f = Feature(f_or_start, end, chrom=chrom)
else:
f = ... | python | def knearest(self, f_or_start, end=None, chrom=None, k=1):
"""return the n nearest neighbors to the given feature
f: a Feature object
k: the number of features to return
"""
if end is not None:
f = Feature(f_or_start, end, chrom=chrom)
else:
f = ... | [
"def",
"knearest",
"(",
"self",
",",
"f_or_start",
",",
"end",
"=",
"None",
",",
"chrom",
"=",
"None",
",",
"k",
"=",
"1",
")",
":",
"if",
"end",
"is",
"not",
"None",
":",
"f",
"=",
"Feature",
"(",
"f_or_start",
",",
"end",
",",
"chrom",
"=",
"... | return the n nearest neighbors to the given feature
f: a Feature object
k: the number of features to return | [
"return",
"the",
"n",
"nearest",
"neighbors",
"to",
"the",
"given",
"feature",
"f",
":",
"a",
"Feature",
"object",
"k",
":",
"the",
"number",
"of",
"features",
"to",
"return"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/intersecter.py#L243-L266 |
brentp/cruzdb | scripts/interval_tree.py | IntervalTree.find | def find(self, start, end):
"""find all elements between (or overlapping) start and end"""
if self.intervals and not end < self.intervals[0].start:
overlapping = [i for i in self.intervals if i.end >= start
and i.start <= end]
else:... | python | def find(self, start, end):
"""find all elements between (or overlapping) start and end"""
if self.intervals and not end < self.intervals[0].start:
overlapping = [i for i in self.intervals if i.end >= start
and i.start <= end]
else:... | [
"def",
"find",
"(",
"self",
",",
"start",
",",
"end",
")",
":",
"if",
"self",
".",
"intervals",
"and",
"not",
"end",
"<",
"self",
".",
"intervals",
"[",
"0",
"]",
".",
"start",
":",
"overlapping",
"=",
"[",
"i",
"for",
"i",
"in",
"self",
".",
"... | find all elements between (or overlapping) start and end | [
"find",
"all",
"elements",
"between",
"(",
"or",
"overlapping",
")",
"start",
"and",
"end"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/scripts/interval_tree.py#L77-L91 |
brentp/cruzdb | cruzdb/sequence.py | sequence | def sequence(db, chrom, start, end):
"""
return the sequence for a region using the UCSC DAS
server. note the start is 1-based
each feature will have it's own .sequence method which sends
the correct start and end to this function.
>>> sequence('hg18', 'chr2', 2223, 2230)
'caacttag'
"""... | python | def sequence(db, chrom, start, end):
"""
return the sequence for a region using the UCSC DAS
server. note the start is 1-based
each feature will have it's own .sequence method which sends
the correct start and end to this function.
>>> sequence('hg18', 'chr2', 2223, 2230)
'caacttag'
"""... | [
"def",
"sequence",
"(",
"db",
",",
"chrom",
",",
"start",
",",
"end",
")",
":",
"url",
"=",
"\"http://genome.ucsc.edu/cgi-bin/das/%s\"",
"%",
"db",
"url",
"+=",
"\"/dna?segment=%s:%i,%i\"",
"xml",
"=",
"U",
".",
"urlopen",
"(",
"url",
"%",
"(",
"chrom",
",... | return the sequence for a region using the UCSC DAS
server. note the start is 1-based
each feature will have it's own .sequence method which sends
the correct start and end to this function.
>>> sequence('hg18', 'chr2', 2223, 2230)
'caacttag' | [
"return",
"the",
"sequence",
"for",
"a",
"region",
"using",
"the",
"UCSC",
"DAS",
"server",
".",
"note",
"the",
"start",
"is",
"1",
"-",
"based",
"each",
"feature",
"will",
"have",
"it",
"s",
"own",
".",
"sequence",
"method",
"which",
"sends",
"the",
"... | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/sequence.py#L10-L23 |
brentp/cruzdb | cruzdb/mirror.py | set_table | def set_table(genome, table, table_name, connection_string, metadata):
"""
alter the table to work between different
dialects
"""
table = Table(table_name, genome._metadata, autoload=True,
autoload_with=genome.bind, extend_existing=True)
#print "\t".join([c.name for c in tab... | python | def set_table(genome, table, table_name, connection_string, metadata):
"""
alter the table to work between different
dialects
"""
table = Table(table_name, genome._metadata, autoload=True,
autoload_with=genome.bind, extend_existing=True)
#print "\t".join([c.name for c in tab... | [
"def",
"set_table",
"(",
"genome",
",",
"table",
",",
"table_name",
",",
"connection_string",
",",
"metadata",
")",
":",
"table",
"=",
"Table",
"(",
"table_name",
",",
"genome",
".",
"_metadata",
",",
"autoload",
"=",
"True",
",",
"autoload_with",
"=",
"ge... | alter the table to work between different
dialects | [
"alter",
"the",
"table",
"to",
"work",
"between",
"different",
"dialects"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/mirror.py#L39-L80 |
brentp/cruzdb | cruzdb/__init__.py | Genome.create_url | def create_url(self, db="", user="genome", host="genome-mysql.cse.ucsc.edu",
password="", dialect="mysqldb"):
"""
internal: create a dburl from a set of parameters or the defaults on
this object
"""
if os.path.exists(db):
db = "sqlite:///" + db
# Is t... | python | def create_url(self, db="", user="genome", host="genome-mysql.cse.ucsc.edu",
password="", dialect="mysqldb"):
"""
internal: create a dburl from a set of parameters or the defaults on
this object
"""
if os.path.exists(db):
db = "sqlite:///" + db
# Is t... | [
"def",
"create_url",
"(",
"self",
",",
"db",
"=",
"\"\"",
",",
"user",
"=",
"\"genome\"",
",",
"host",
"=",
"\"genome-mysql.cse.ucsc.edu\"",
",",
"password",
"=",
"\"\"",
",",
"dialect",
"=",
"\"mysqldb\"",
")",
":",
"if",
"os",
".",
"path",
".",
"exists... | internal: create a dburl from a set of parameters or the defaults on
this object | [
"internal",
":",
"create",
"a",
"dburl",
"from",
"a",
"set",
"of",
"parameters",
"or",
"the",
"defaults",
"on",
"this",
"object"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L69-L92 |
brentp/cruzdb | cruzdb/__init__.py | Genome.mirror | def mirror(self, tables, dest_url):
"""
miror a set of `tables` from `dest_url`
Returns a new Genome object
Parameters
----------
tables : list
an iterable of tables
dest_url: str
a dburl string, e.g. 'sqlite:///local.db'
"""
... | python | def mirror(self, tables, dest_url):
"""
miror a set of `tables` from `dest_url`
Returns a new Genome object
Parameters
----------
tables : list
an iterable of tables
dest_url: str
a dburl string, e.g. 'sqlite:///local.db'
"""
... | [
"def",
"mirror",
"(",
"self",
",",
"tables",
",",
"dest_url",
")",
":",
"from",
"mirror",
"import",
"mirror",
"return",
"mirror",
"(",
"self",
",",
"tables",
",",
"dest_url",
")"
] | miror a set of `tables` from `dest_url`
Returns a new Genome object
Parameters
----------
tables : list
an iterable of tables
dest_url: str
a dburl string, e.g. 'sqlite:///local.db' | [
"miror",
"a",
"set",
"of",
"tables",
"from",
"dest_url"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L94-L110 |
brentp/cruzdb | cruzdb/__init__.py | Genome.dataframe | def dataframe(self, table):
"""
create a pandas dataframe from a table or query
Parameters
----------
table : table
a table in this database or a query
limit: integer
an integer limit on the query
offset: integer
an offset f... | python | def dataframe(self, table):
"""
create a pandas dataframe from a table or query
Parameters
----------
table : table
a table in this database or a query
limit: integer
an integer limit on the query
offset: integer
an offset f... | [
"def",
"dataframe",
"(",
"self",
",",
"table",
")",
":",
"from",
"pandas",
"import",
"DataFrame",
"if",
"isinstance",
"(",
"table",
",",
"six",
".",
"string_types",
")",
":",
"table",
"=",
"getattr",
"(",
"self",
",",
"table",
")",
"try",
":",
"rec",
... | create a pandas dataframe from a table or query
Parameters
----------
table : table
a table in this database or a query
limit: integer
an integer limit on the query
offset: integer
an offset for the query | [
"create",
"a",
"pandas",
"dataframe",
"from",
"a",
"table",
"or",
"query"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L112-L140 |
brentp/cruzdb | cruzdb/__init__.py | Genome.load_file | def load_file(self, fname, table=None, sep="\t", bins=False, indexes=None):
"""
use some of the machinery in pandas to load a file into a table
Parameters
----------
fname : str
filename or filehandle to load
table : str
table to load the file t... | python | def load_file(self, fname, table=None, sep="\t", bins=False, indexes=None):
"""
use some of the machinery in pandas to load a file into a table
Parameters
----------
fname : str
filename or filehandle to load
table : str
table to load the file t... | [
"def",
"load_file",
"(",
"self",
",",
"fname",
",",
"table",
"=",
"None",
",",
"sep",
"=",
"\"\\t\"",
",",
"bins",
"=",
"False",
",",
"indexes",
"=",
"None",
")",
":",
"convs",
"=",
"{",
"\"#chr\"",
":",
"\"chrom\"",
",",
"\"start\"",
":",
"\"txStart... | use some of the machinery in pandas to load a file into a table
Parameters
----------
fname : str
filename or filehandle to load
table : str
table to load the file to
sep : str
CSV separator
bins : bool
add a "bin" colu... | [
"use",
"some",
"of",
"the",
"machinery",
"in",
"pandas",
"to",
"load",
"a",
"file",
"into",
"a",
"table"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L146-L228 |
brentp/cruzdb | cruzdb/__init__.py | Genome.david_go | def david_go(refseq_list, annot=('SP_PIR_KEYWORDS', 'GOTERM_BP_FAT',
'GOTERM_CC_FAT', 'GOTERM_MF_FAT')):
"""
open a web-browser to the DAVID online enrichment tool
Parameters
----------
refseq_list : list
list of refseq names ... | python | def david_go(refseq_list, annot=('SP_PIR_KEYWORDS', 'GOTERM_BP_FAT',
'GOTERM_CC_FAT', 'GOTERM_MF_FAT')):
"""
open a web-browser to the DAVID online enrichment tool
Parameters
----------
refseq_list : list
list of refseq names ... | [
"def",
"david_go",
"(",
"refseq_list",
",",
"annot",
"=",
"(",
"'SP_PIR_KEYWORDS'",
",",
"'GOTERM_BP_FAT'",
",",
"'GOTERM_CC_FAT'",
",",
"'GOTERM_MF_FAT'",
")",
")",
":",
"URL",
"=",
"\"http://david.abcc.ncifcrf.gov/api.jsp?type=REFSEQ_MRNA&ids=%s&tool=term2term&annot=\"",
... | open a web-browser to the DAVID online enrichment tool
Parameters
----------
refseq_list : list
list of refseq names to check for enrichment
annot : list
iterable of DAVID annotations to check for enrichment | [
"open",
"a",
"web",
"-",
"browser",
"to",
"the",
"DAVID",
"online",
"enrichment",
"tool"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L231-L248 |
brentp/cruzdb | cruzdb/__init__.py | Genome.bin_query | def bin_query(self, table, chrom, start, end):
"""
perform an efficient spatial query using the bin column if available.
The possible bins are calculated from the `start` and `end` sent to
this function.
Parameters
----------
table : str or table
tabl... | python | def bin_query(self, table, chrom, start, end):
"""
perform an efficient spatial query using the bin column if available.
The possible bins are calculated from the `start` and `end` sent to
this function.
Parameters
----------
table : str or table
tabl... | [
"def",
"bin_query",
"(",
"self",
",",
"table",
",",
"chrom",
",",
"start",
",",
"end",
")",
":",
"if",
"isinstance",
"(",
"table",
",",
"six",
".",
"string_types",
")",
":",
"table",
"=",
"getattr",
"(",
"self",
",",
"table",
")",
"try",
":",
"tbl"... | perform an efficient spatial query using the bin column if available.
The possible bins are calculated from the `start` and `end` sent to
this function.
Parameters
----------
table : str or table
table to query
chrom : str
chromosome for the query... | [
"perform",
"an",
"efficient",
"spatial",
"query",
"using",
"the",
"bin",
"column",
"if",
"available",
".",
"The",
"possible",
"bins",
"are",
"calculated",
"from",
"the",
"start",
"and",
"end",
"sent",
"to",
"this",
"function",
"."
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L250-L289 |
brentp/cruzdb | cruzdb/__init__.py | Genome.upstream | def upstream(self, table, chrom_or_feat, start=None, end=None, k=1):
"""
Return k-nearest upstream features
Parameters
----------
table : str or table
table against which to query
chrom_or_feat : str or feat
either a chromosome, e.g. 'chr3' or a... | python | def upstream(self, table, chrom_or_feat, start=None, end=None, k=1):
"""
Return k-nearest upstream features
Parameters
----------
table : str or table
table against which to query
chrom_or_feat : str or feat
either a chromosome, e.g. 'chr3' or a... | [
"def",
"upstream",
"(",
"self",
",",
"table",
",",
"chrom_or_feat",
",",
"start",
"=",
"None",
",",
"end",
"=",
"None",
",",
"k",
"=",
"1",
")",
":",
"res",
"=",
"self",
".",
"knearest",
"(",
"table",
",",
"chrom_or_feat",
",",
"start",
",",
"end",... | Return k-nearest upstream features
Parameters
----------
table : str or table
table against which to query
chrom_or_feat : str or feat
either a chromosome, e.g. 'chr3' or a feature with .chrom, .start,
.end attributes
start : int
... | [
"Return",
"k",
"-",
"nearest",
"upstream",
"features"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L291-L321 |
brentp/cruzdb | cruzdb/__init__.py | Genome.knearest | def knearest(self, table, chrom_or_feat, start=None, end=None, k=1,
_direction=None):
"""
Return k-nearest features
Parameters
----------
table : str or table
table against which to query
chrom_or_feat : str or feat
either a chromoso... | python | def knearest(self, table, chrom_or_feat, start=None, end=None, k=1,
_direction=None):
"""
Return k-nearest features
Parameters
----------
table : str or table
table against which to query
chrom_or_feat : str or feat
either a chromoso... | [
"def",
"knearest",
"(",
"self",
",",
"table",
",",
"chrom_or_feat",
",",
"start",
"=",
"None",
",",
"end",
"=",
"None",
",",
"k",
"=",
"1",
",",
"_direction",
"=",
"None",
")",
":",
"assert",
"_direction",
"in",
"(",
"None",
",",
"\"up\"",
",",
"\"... | Return k-nearest features
Parameters
----------
table : str or table
table against which to query
chrom_or_feat : str or feat
either a chromosome, e.g. 'chr3' or a feature with .chrom, .start,
.end attributes
start : int
if `chr... | [
"Return",
"k",
"-",
"nearest",
"features"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L355-L441 |
brentp/cruzdb | cruzdb/__init__.py | Genome.annotate | def annotate(self, fname, tables, feature_strand=False, in_memory=False,
header=None, out=sys.stdout, parallel=False):
"""
annotate a file with a number of tables
Parameters
----------
fname : str or file
file name or file-handle
tables : list
... | python | def annotate(self, fname, tables, feature_strand=False, in_memory=False,
header=None, out=sys.stdout, parallel=False):
"""
annotate a file with a number of tables
Parameters
----------
fname : str or file
file name or file-handle
tables : list
... | [
"def",
"annotate",
"(",
"self",
",",
"fname",
",",
"tables",
",",
"feature_strand",
"=",
"False",
",",
"in_memory",
"=",
"False",
",",
"header",
"=",
"None",
",",
"out",
"=",
"sys",
".",
"stdout",
",",
"parallel",
"=",
"False",
")",
":",
"from",
".",... | annotate a file with a number of tables
Parameters
----------
fname : str or file
file name or file-handle
tables : list
list of tables with which to annotate `fname`
feature_strand : bool
if this is True, then the up/downstream designations... | [
"annotate",
"a",
"file",
"with",
"a",
"number",
"of",
"tables"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L449-L484 |
brentp/cruzdb | cruzdb/__init__.py | Genome.bins | def bins(start, end):
"""
Get all the bin numbers for a particular interval defined by
(start, end]
"""
if end - start < 536870912:
offsets = [585, 73, 9, 1]
else:
raise BigException
offsets = [4681, 585, 73, 9, 1]
binFirstShift... | python | def bins(start, end):
"""
Get all the bin numbers for a particular interval defined by
(start, end]
"""
if end - start < 536870912:
offsets = [585, 73, 9, 1]
else:
raise BigException
offsets = [4681, 585, 73, 9, 1]
binFirstShift... | [
"def",
"bins",
"(",
"start",
",",
"end",
")",
":",
"if",
"end",
"-",
"start",
"<",
"536870912",
":",
"offsets",
"=",
"[",
"585",
",",
"73",
",",
"9",
",",
"1",
"]",
"else",
":",
"raise",
"BigException",
"offsets",
"=",
"[",
"4681",
",",
"585",
... | Get all the bin numbers for a particular interval defined by
(start, end] | [
"Get",
"all",
"the",
"bin",
"numbers",
"for",
"a",
"particular",
"interval",
"defined",
"by",
"(",
"start",
"end",
"]"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L487-L508 |
brentp/cruzdb | cruzdb/__init__.py | Genome.save_bed | def save_bed(cls, query, filename=sys.stdout):
"""
write a bed12 file of the query.
Parameters
----------
query : query
a table or query to save to file
filename : file
string or filehandle to write output
"""
out = _open(filename... | python | def save_bed(cls, query, filename=sys.stdout):
"""
write a bed12 file of the query.
Parameters
----------
query : query
a table or query to save to file
filename : file
string or filehandle to write output
"""
out = _open(filename... | [
"def",
"save_bed",
"(",
"cls",
",",
"query",
",",
"filename",
"=",
"sys",
".",
"stdout",
")",
":",
"out",
"=",
"_open",
"(",
"filename",
",",
"'w'",
")",
"for",
"o",
"in",
"query",
":",
"out",
".",
"write",
"(",
"o",
".",
"bed",
"(",
")",
"+",
... | write a bed12 file of the query.
Parameters
----------
query : query
a table or query to save to file
filename : file
string or filehandle to write output | [
"write",
"a",
"bed12",
"file",
"of",
"the",
"query",
".",
"Parameters",
"----------"
] | train | https://github.com/brentp/cruzdb/blob/9068d46e25952f4a929dde0242beb31fa4c7e89a/cruzdb/__init__.py#L514-L528 |
peterbe/django-static | django_static/templatetags/django_static.py | staticfile_node | def staticfile_node(parser, token, optimize_if_possible=False):
"""For example:
{% staticfile "/js/foo.js" %}
or
{% staticfile "/js/foo.js" as variable_name %}
Or for multiples:
{% staticfile "/foo.js; /bar.js" %}
or
{% staticfile "/foo.js; /bar.js" as varia... | python | def staticfile_node(parser, token, optimize_if_possible=False):
"""For example:
{% staticfile "/js/foo.js" %}
or
{% staticfile "/js/foo.js" as variable_name %}
Or for multiples:
{% staticfile "/foo.js; /bar.js" %}
or
{% staticfile "/foo.js; /bar.js" as varia... | [
"def",
"staticfile_node",
"(",
"parser",
",",
"token",
",",
"optimize_if_possible",
"=",
"False",
")",
":",
"args",
"=",
"token",
".",
"split_contents",
"(",
")",
"tag",
"=",
"args",
"[",
"0",
"]",
"if",
"len",
"(",
"args",
")",
"==",
"4",
"and",
"ar... | For example:
{% staticfile "/js/foo.js" %}
or
{% staticfile "/js/foo.js" as variable_name %}
Or for multiples:
{% staticfile "/foo.js; /bar.js" %}
or
{% staticfile "/foo.js; /bar.js" as variable_name %} | [
"For",
"example",
":",
"{",
"%",
"staticfile",
"/",
"js",
"/",
"foo",
".",
"js",
"%",
"}",
"or",
"{",
"%",
"staticfile",
"/",
"js",
"/",
"foo",
".",
"js",
"as",
"variable_name",
"%",
"}",
"Or",
"for",
"multiples",
":",
"{",
"%",
"staticfile",
"/"... | train | https://github.com/peterbe/django-static/blob/05c0d2f302274b9d3f7df6ad92bd861889316ebd/django_static/templatetags/django_static.py#L185-L209 |
peterbe/django-static | django_static/templatetags/django_static.py | _mkdir | def _mkdir(newdir):
"""works the way a good mkdir should :)
- already exists, silently complete
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well
"""
if os.path.isdir(newdir):
pass
elif os.path.isfile(newdir):
... | python | def _mkdir(newdir):
"""works the way a good mkdir should :)
- already exists, silently complete
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well
"""
if os.path.isdir(newdir):
pass
elif os.path.isfile(newdir):
... | [
"def",
"_mkdir",
"(",
"newdir",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"newdir",
")",
":",
"pass",
"elif",
"os",
".",
"path",
".",
"isfile",
"(",
"newdir",
")",
":",
"raise",
"OSError",
"(",
"\"a file with the same name as the desired \"",
... | works the way a good mkdir should :)
- already exists, silently complete
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well | [
"works",
"the",
"way",
"a",
"good",
"mkdir",
"should",
":",
")",
"-",
"already",
"exists",
"silently",
"complete",
"-",
"regular",
"file",
"in",
"the",
"way",
"raise",
"an",
"exception",
"-",
"parent",
"directory",
"(",
"ies",
")",
"does",
"not",
"exist"... | train | https://github.com/peterbe/django-static/blob/05c0d2f302274b9d3f7df6ad92bd861889316ebd/django_static/templatetags/django_static.py#L641-L657 |
peterbe/django-static | django_static/templatetags/django_static.py | _find_filepath_in_roots | def _find_filepath_in_roots(filename):
"""Look for filename in all MEDIA_ROOTS, and return the first one found."""
for root in settings.DJANGO_STATIC_MEDIA_ROOTS:
filepath = _filename2filepath(filename, root)
if os.path.isfile(filepath):
return filepath, root
# havent found it in... | python | def _find_filepath_in_roots(filename):
"""Look for filename in all MEDIA_ROOTS, and return the first one found."""
for root in settings.DJANGO_STATIC_MEDIA_ROOTS:
filepath = _filename2filepath(filename, root)
if os.path.isfile(filepath):
return filepath, root
# havent found it in... | [
"def",
"_find_filepath_in_roots",
"(",
"filename",
")",
":",
"for",
"root",
"in",
"settings",
".",
"DJANGO_STATIC_MEDIA_ROOTS",
":",
"filepath",
"=",
"_filename2filepath",
"(",
"filename",
",",
"root",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"filepat... | Look for filename in all MEDIA_ROOTS, and return the first one found. | [
"Look",
"for",
"filename",
"in",
"all",
"MEDIA_ROOTS",
"and",
"return",
"the",
"first",
"one",
"found",
"."
] | train | https://github.com/peterbe/django-static/blob/05c0d2f302274b9d3f7df6ad92bd861889316ebd/django_static/templatetags/django_static.py#L660-L677 |
peterbe/django-static | django_static/templatetags/django_static.py | default_combine_filenames_generator | def default_combine_filenames_generator(filenames, max_length=40):
"""Return a new filename to use as the combined file name for a
bunch of files.
A precondition is that they all have the same file extension
Given that the list of files can have different paths, we aim to use the
most common path.
... | python | def default_combine_filenames_generator(filenames, max_length=40):
"""Return a new filename to use as the combined file name for a
bunch of files.
A precondition is that they all have the same file extension
Given that the list of files can have different paths, we aim to use the
most common path.
... | [
"def",
"default_combine_filenames_generator",
"(",
"filenames",
",",
"max_length",
"=",
"40",
")",
":",
"path",
"=",
"None",
"names",
"=",
"[",
"]",
"extension",
"=",
"None",
"timestamps",
"=",
"[",
"]",
"for",
"filename",
"in",
"filenames",
":",
"name",
"... | Return a new filename to use as the combined file name for a
bunch of files.
A precondition is that they all have the same file extension
Given that the list of files can have different paths, we aim to use the
most common path.
Example:
/somewhere/else/foo.js
/somewhere/bar.js
/... | [
"Return",
"a",
"new",
"filename",
"to",
"use",
"as",
"the",
"combined",
"file",
"name",
"for",
"a",
"bunch",
"of",
"files",
".",
"A",
"precondition",
"is",
"that",
"they",
"all",
"have",
"the",
"same",
"file",
"extension"
] | train | https://github.com/peterbe/django-static/blob/05c0d2f302274b9d3f7df6ad92bd861889316ebd/django_static/templatetags/django_static.py#L695-L745 |
peterbe/django-static | django_static/templatetags/django_static.py | StaticFilesNode.render | def render(self, context):
"""inspect the code and look for files that can be turned into combos.
Basically, the developer could type this:
{% slimall %}
<link href="/one.css"/>
<link href="/two.css"/>
{% endslimall %}
And it should be reconsidered like this:
... | python | def render(self, context):
"""inspect the code and look for files that can be turned into combos.
Basically, the developer could type this:
{% slimall %}
<link href="/one.css"/>
<link href="/two.css"/>
{% endslimall %}
And it should be reconsidered like this:
... | [
"def",
"render",
"(",
"self",
",",
"context",
")",
":",
"code",
"=",
"self",
".",
"nodelist",
".",
"render",
"(",
"context",
")",
"if",
"not",
"settings",
".",
"DJANGO_STATIC",
":",
"# Append MEDIA_URL if set",
"# quick and dirty",
"if",
"settings",
".",
"DJ... | inspect the code and look for files that can be turned into combos.
Basically, the developer could type this:
{% slimall %}
<link href="/one.css"/>
<link href="/two.css"/>
{% endslimall %}
And it should be reconsidered like this:
<link href="{% slimfile "/on... | [
"inspect",
"the",
"code",
"and",
"look",
"for",
"files",
"that",
"can",
"be",
"turned",
"into",
"combos",
".",
"Basically",
"the",
"developer",
"could",
"type",
"this",
":",
"{",
"%",
"slimall",
"%",
"}",
"<link",
"href",
"=",
"/",
"one",
".",
"css",
... | train | https://github.com/peterbe/django-static/blob/05c0d2f302274b9d3f7df6ad92bd861889316ebd/django_static/templatetags/django_static.py#L276-L385 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.