partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
valid | SimpleDomainController.require_authentication | Return True if this realm requires authentication (grant anonymous access otherwise). | wsgidav/dc/simple_dc.py | def require_authentication(self, realm, environ):
"""Return True if this realm requires authentication (grant anonymous access otherwise)."""
realm_entry = self._get_realm_entry(realm)
if realm_entry is None:
_logger.error(
'Missing configuration simple_dc.user_mappin... | def require_authentication(self, realm, environ):
"""Return True if this realm requires authentication (grant anonymous access otherwise)."""
realm_entry = self._get_realm_entry(realm)
if realm_entry is None:
_logger.error(
'Missing configuration simple_dc.user_mappin... | [
"Return",
"True",
"if",
"this",
"realm",
"requires",
"authentication",
"(",
"grant",
"anonymous",
"access",
"otherwise",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/dc/simple_dc.py#L109-L117 | [
"def",
"require_authentication",
"(",
"self",
",",
"realm",
",",
"environ",
")",
":",
"realm_entry",
"=",
"self",
".",
"_get_realm_entry",
"(",
"realm",
")",
"if",
"realm_entry",
"is",
"None",
":",
"_logger",
".",
"error",
"(",
"'Missing configuration simple_dc.... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | SimpleDomainController.basic_auth_user | Returns True if this user_name/password pair is valid for the realm,
False otherwise. Used for basic authentication. | wsgidav/dc/simple_dc.py | def basic_auth_user(self, realm, user_name, password, environ):
"""Returns True if this user_name/password pair is valid for the realm,
False otherwise. Used for basic authentication."""
user = self._get_realm_entry(realm, user_name)
if user is not None and password == user.get("passwor... | def basic_auth_user(self, realm, user_name, password, environ):
"""Returns True if this user_name/password pair is valid for the realm,
False otherwise. Used for basic authentication."""
user = self._get_realm_entry(realm, user_name)
if user is not None and password == user.get("passwor... | [
"Returns",
"True",
"if",
"this",
"user_name",
"/",
"password",
"pair",
"is",
"valid",
"for",
"the",
"realm",
"False",
"otherwise",
".",
"Used",
"for",
"basic",
"authentication",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/dc/simple_dc.py#L119-L127 | [
"def",
"basic_auth_user",
"(",
"self",
",",
"realm",
",",
"user_name",
",",
"password",
",",
"environ",
")",
":",
"user",
"=",
"self",
".",
"_get_realm_entry",
"(",
"realm",
",",
"user_name",
")",
"if",
"user",
"is",
"not",
"None",
"and",
"password",
"==... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | SimpleDomainController.digest_auth_user | Computes digest hash A1 part. | wsgidav/dc/simple_dc.py | def digest_auth_user(self, realm, user_name, environ):
"""Computes digest hash A1 part."""
user = self._get_realm_entry(realm, user_name)
if user is None:
return False
password = user.get("password")
environ["wsgidav.auth.roles"] = user.get("roles", [])
return... | def digest_auth_user(self, realm, user_name, environ):
"""Computes digest hash A1 part."""
user = self._get_realm_entry(realm, user_name)
if user is None:
return False
password = user.get("password")
environ["wsgidav.auth.roles"] = user.get("roles", [])
return... | [
"Computes",
"digest",
"hash",
"A1",
"part",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/dc/simple_dc.py#L133-L140 | [
"def",
"digest_auth_user",
"(",
"self",
",",
"realm",
",",
"user_name",
",",
"environ",
")",
":",
"user",
"=",
"self",
".",
"_get_realm_entry",
"(",
"realm",
",",
"user_name",
")",
"if",
"user",
"is",
"None",
":",
"return",
"False",
"password",
"=",
"use... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockStorageDict.get | Return a lock dictionary for a token.
If the lock does not exist or is expired, None is returned.
token:
lock token
Returns:
Lock dictionary or <None>
Side effect: if lock is expired, it will be purged and None is returned. | wsgidav/lock_storage.py | def get(self, token):
"""Return a lock dictionary for a token.
If the lock does not exist or is expired, None is returned.
token:
lock token
Returns:
Lock dictionary or <None>
Side effect: if lock is expired, it will be purged and None is returned.
... | def get(self, token):
"""Return a lock dictionary for a token.
If the lock does not exist or is expired, None is returned.
token:
lock token
Returns:
Lock dictionary or <None>
Side effect: if lock is expired, it will be purged and None is returned.
... | [
"Return",
"a",
"lock",
"dictionary",
"for",
"a",
"token",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_storage.py#L131-L160 | [
"def",
"get",
"(",
"self",
",",
"token",
")",
":",
"self",
".",
"_lock",
".",
"acquire_read",
"(",
")",
"try",
":",
"lock",
"=",
"self",
".",
"_dict",
".",
"get",
"(",
"token",
")",
"if",
"lock",
"is",
"None",
":",
"# Lock not found: purge dangling URL... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockStorageDict.create | Create a direct lock for a resource path.
path:
Normalized path (utf8 encoded string, no trailing '/')
lock:
lock dictionary, without a token entry
Returns:
New unique lock token.: <lock
**Note:** the lock dictionary may be modified on return:
... | wsgidav/lock_storage.py | def create(self, path, lock):
"""Create a direct lock for a resource path.
path:
Normalized path (utf8 encoded string, no trailing '/')
lock:
lock dictionary, without a token entry
Returns:
New unique lock token.: <lock
**Note:** the lock dic... | def create(self, path, lock):
"""Create a direct lock for a resource path.
path:
Normalized path (utf8 encoded string, no trailing '/')
lock:
lock dictionary, without a token entry
Returns:
New unique lock token.: <lock
**Note:** the lock dic... | [
"Create",
"a",
"direct",
"lock",
"for",
"a",
"resource",
"path",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_storage.py#L162-L224 | [
"def",
"create",
"(",
"self",
",",
"path",
",",
"lock",
")",
":",
"self",
".",
"_lock",
".",
"acquire_write",
"(",
")",
"try",
":",
"# We expect only a lock definition, not an existing lock",
"assert",
"lock",
".",
"get",
"(",
"\"token\"",
")",
"is",
"None",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockStorageDict.refresh | Modify an existing lock's timeout.
token:
Valid lock token.
timeout:
Suggested lifetime in seconds (-1 for infinite).
The real expiration time may be shorter than requested!
Returns:
Lock dictionary.
Raises ValueError, if token is inva... | wsgidav/lock_storage.py | def refresh(self, token, timeout):
"""Modify an existing lock's timeout.
token:
Valid lock token.
timeout:
Suggested lifetime in seconds (-1 for infinite).
The real expiration time may be shorter than requested!
Returns:
Lock dictionary.
... | def refresh(self, token, timeout):
"""Modify an existing lock's timeout.
token:
Valid lock token.
timeout:
Suggested lifetime in seconds (-1 for infinite).
The real expiration time may be shorter than requested!
Returns:
Lock dictionary.
... | [
"Modify",
"an",
"existing",
"lock",
"s",
"timeout",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_storage.py#L226-L254 | [
"def",
"refresh",
"(",
"self",
",",
"token",
",",
"timeout",
")",
":",
"assert",
"token",
"in",
"self",
".",
"_dict",
",",
"\"Lock must exist\"",
"assert",
"timeout",
"==",
"-",
"1",
"or",
"timeout",
">",
"0",
"if",
"timeout",
"<",
"0",
"or",
"timeout"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockStorageDict.delete | Delete lock.
Returns True on success. False, if token does not exist, or is expired. | wsgidav/lock_storage.py | def delete(self, token):
"""Delete lock.
Returns True on success. False, if token does not exist, or is expired.
"""
self._lock.acquire_write()
try:
lock = self._dict.get(token)
_logger.debug("delete {}".format(lock_string(lock)))
if lock is N... | def delete(self, token):
"""Delete lock.
Returns True on success. False, if token does not exist, or is expired.
"""
self._lock.acquire_write()
try:
lock = self._dict.get(token)
_logger.debug("delete {}".format(lock_string(lock)))
if lock is N... | [
"Delete",
"lock",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_storage.py#L256-L285 | [
"def",
"delete",
"(",
"self",
",",
"token",
")",
":",
"self",
".",
"_lock",
".",
"acquire_write",
"(",
")",
"try",
":",
"lock",
"=",
"self",
".",
"_dict",
".",
"get",
"(",
"token",
")",
"_logger",
".",
"debug",
"(",
"\"delete {}\"",
".",
"format",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockStorageDict.get_lock_list | Return a list of direct locks for <path>.
Expired locks are *not* returned (but may be purged).
path:
Normalized path (utf8 encoded string, no trailing '/')
include_root:
False: don't add <path> lock (only makes sense, when include_children
is True).
... | wsgidav/lock_storage.py | def get_lock_list(self, path, include_root, include_children, token_only):
"""Return a list of direct locks for <path>.
Expired locks are *not* returned (but may be purged).
path:
Normalized path (utf8 encoded string, no trailing '/')
include_root:
False: don't ... | def get_lock_list(self, path, include_root, include_children, token_only):
"""Return a list of direct locks for <path>.
Expired locks are *not* returned (but may be purged).
path:
Normalized path (utf8 encoded string, no trailing '/')
include_root:
False: don't ... | [
"Return",
"a",
"list",
"of",
"direct",
"locks",
"for",
"<path",
">",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_storage.py#L287-L336 | [
"def",
"get_lock_list",
"(",
"self",
",",
"path",
",",
"include_root",
",",
"include_children",
",",
"token_only",
")",
":",
"assert",
"compat",
".",
"is_native",
"(",
"path",
")",
"assert",
"path",
"and",
"path",
".",
"startswith",
"(",
"\"/\"",
")",
"ass... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockStorageShelve._flush | Write persistent dictionary to disc. | wsgidav/lock_storage.py | def _flush(self):
"""Write persistent dictionary to disc."""
_logger.debug("_flush()")
self._lock.acquire_write() # TODO: read access is enough?
try:
self._dict.sync()
finally:
self._lock.release() | def _flush(self):
"""Write persistent dictionary to disc."""
_logger.debug("_flush()")
self._lock.acquire_write() # TODO: read access is enough?
try:
self._dict.sync()
finally:
self._lock.release() | [
"Write",
"persistent",
"dictionary",
"to",
"disc",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_storage.py#L356-L363 | [
"def",
"_flush",
"(",
"self",
")",
":",
"_logger",
".",
"debug",
"(",
"\"_flush()\"",
")",
"self",
".",
"_lock",
".",
"acquire_write",
"(",
")",
"# TODO: read access is enough?",
"try",
":",
"self",
".",
"_dict",
".",
"sync",
"(",
")",
"finally",
":",
"s... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockStorageShelve.clear | Delete all entries. | wsgidav/lock_storage.py | def clear(self):
"""Delete all entries."""
self._lock.acquire_write() # TODO: read access is enough?
try:
was_closed = self._dict is None
if was_closed:
self.open()
if len(self._dict):
self._dict.clear()
self._d... | def clear(self):
"""Delete all entries."""
self._lock.acquire_write() # TODO: read access is enough?
try:
was_closed = self._dict is None
if was_closed:
self.open()
if len(self._dict):
self._dict.clear()
self._d... | [
"Delete",
"all",
"entries",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_storage.py#L365-L378 | [
"def",
"clear",
"(",
"self",
")",
":",
"self",
".",
"_lock",
".",
"acquire_write",
"(",
")",
"# TODO: read access is enough?",
"try",
":",
"was_closed",
"=",
"self",
".",
"_dict",
"is",
"None",
"if",
"was_closed",
":",
"self",
".",
"open",
"(",
")",
"if"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | WsgiDavDirBrowser._fail | Wrapper to raise (and log) DAVError. | wsgidav/dir_browser/_dir_browser.py | def _fail(self, value, context_info=None, src_exception=None, err_condition=None):
"""Wrapper to raise (and log) DAVError."""
e = DAVError(value, context_info, src_exception, err_condition)
if self.verbose >= 4:
_logger.warning(
"Raising DAVError {}".format(
... | def _fail(self, value, context_info=None, src_exception=None, err_condition=None):
"""Wrapper to raise (and log) DAVError."""
e = DAVError(value, context_info, src_exception, err_condition)
if self.verbose >= 4:
_logger.warning(
"Raising DAVError {}".format(
... | [
"Wrapper",
"to",
"raise",
"(",
"and",
"log",
")",
"DAVError",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/dir_browser/_dir_browser.py#L123-L132 | [
"def",
"_fail",
"(",
"self",
",",
"value",
",",
"context_info",
"=",
"None",
",",
"src_exception",
"=",
"None",
",",
"err_condition",
"=",
"None",
")",
":",
"e",
"=",
"DAVError",
"(",
"value",
",",
"context_info",
",",
"src_exception",
",",
"err_condition"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FileResource.begin_write | Open content as a stream for writing.
See DAVResource.begin_write() | wsgidav/fs_dav_provider.py | def begin_write(self, content_type=None):
"""Open content as a stream for writing.
See DAVResource.begin_write()
"""
assert not self.is_collection
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
# _logger.debug("begin_write: {}, {}".format(self._fil... | def begin_write(self, content_type=None):
"""Open content as a stream for writing.
See DAVResource.begin_write()
"""
assert not self.is_collection
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
# _logger.debug("begin_write: {}, {}".format(self._fil... | [
"Open",
"content",
"as",
"a",
"stream",
"for",
"writing",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L88-L98 | [
"def",
"begin_write",
"(",
"self",
",",
"content_type",
"=",
"None",
")",
":",
"assert",
"not",
"self",
".",
"is_collection",
"if",
"self",
".",
"provider",
".",
"readonly",
":",
"raise",
"DAVError",
"(",
"HTTP_FORBIDDEN",
")",
"# _logger.debug(\"begin_write: {}... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FileResource.delete | Remove this resource or collection (recursive).
See DAVResource.delete() | wsgidav/fs_dav_provider.py | def delete(self):
"""Remove this resource or collection (recursive).
See DAVResource.delete()
"""
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
os.unlink(self._file_path)
self.remove_all_properties(True)
self.remove_all_locks(True) | def delete(self):
"""Remove this resource or collection (recursive).
See DAVResource.delete()
"""
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
os.unlink(self._file_path)
self.remove_all_properties(True)
self.remove_all_locks(True) | [
"Remove",
"this",
"resource",
"or",
"collection",
"(",
"recursive",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L100-L109 | [
"def",
"delete",
"(",
"self",
")",
":",
"if",
"self",
".",
"provider",
".",
"readonly",
":",
"raise",
"DAVError",
"(",
"HTTP_FORBIDDEN",
")",
"os",
".",
"unlink",
"(",
"self",
".",
"_file_path",
")",
"self",
".",
"remove_all_properties",
"(",
"True",
")"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FileResource.copy_move_single | See DAVResource.copy_move_single() | wsgidav/fs_dav_provider.py | def copy_move_single(self, dest_path, is_move):
"""See DAVResource.copy_move_single() """
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
assert not util.is_equal_or_child_uri(self.path, dest_path)
... | def copy_move_single(self, dest_path, is_move):
"""See DAVResource.copy_move_single() """
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
assert not util.is_equal_or_child_uri(self.path, dest_path)
... | [
"See",
"DAVResource",
".",
"copy_move_single",
"()"
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L111-L134 | [
"def",
"copy_move_single",
"(",
"self",
",",
"dest_path",
",",
"is_move",
")",
":",
"if",
"self",
".",
"provider",
".",
"readonly",
":",
"raise",
"DAVError",
"(",
"HTTP_FORBIDDEN",
")",
"fpDest",
"=",
"self",
".",
"provider",
".",
"_loc_to_file_path",
"(",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FileResource.move_recursive | See DAVResource.move_recursive() | wsgidav/fs_dav_provider.py | def move_recursive(self, dest_path):
"""See DAVResource.move_recursive() """
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
assert not util.is_equal_or_child_uri(self.path, dest_path)
assert ... | def move_recursive(self, dest_path):
"""See DAVResource.move_recursive() """
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
assert not util.is_equal_or_child_uri(self.path, dest_path)
assert ... | [
"See",
"DAVResource",
".",
"move_recursive",
"()"
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L140-L158 | [
"def",
"move_recursive",
"(",
"self",
",",
"dest_path",
")",
":",
"if",
"self",
".",
"provider",
".",
"readonly",
":",
"raise",
"DAVError",
"(",
"HTTP_FORBIDDEN",
")",
"fpDest",
"=",
"self",
".",
"provider",
".",
"_loc_to_file_path",
"(",
"dest_path",
",",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FileResource.set_last_modified | Set last modified time for destPath to timeStamp on epoch-format | wsgidav/fs_dav_provider.py | def set_last_modified(self, dest_path, time_stamp, dry_run):
"""Set last modified time for destPath to timeStamp on epoch-format"""
# Translate time from RFC 1123 to seconds since epoch format
secs = util.parse_time_string(time_stamp)
if not dry_run:
os.utime(self._file_path,... | def set_last_modified(self, dest_path, time_stamp, dry_run):
"""Set last modified time for destPath to timeStamp on epoch-format"""
# Translate time from RFC 1123 to seconds since epoch format
secs = util.parse_time_string(time_stamp)
if not dry_run:
os.utime(self._file_path,... | [
"Set",
"last",
"modified",
"time",
"for",
"destPath",
"to",
"timeStamp",
"on",
"epoch",
"-",
"format"
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L160-L166 | [
"def",
"set_last_modified",
"(",
"self",
",",
"dest_path",
",",
"time_stamp",
",",
"dry_run",
")",
":",
"# Translate time from RFC 1123 to seconds since epoch format",
"secs",
"=",
"util",
".",
"parse_time_string",
"(",
"time_stamp",
")",
"if",
"not",
"dry_run",
":",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FolderResource.get_member_names | Return list of direct collection member names (utf-8 encoded).
See DAVCollection.get_member_names() | wsgidav/fs_dav_provider.py | def get_member_names(self):
"""Return list of direct collection member names (utf-8 encoded).
See DAVCollection.get_member_names()
"""
# On Windows NT/2k/XP and Unix, if path is a Unicode object, the result
# will be a list of Unicode objects.
# Undecodable filenames wil... | def get_member_names(self):
"""Return list of direct collection member names (utf-8 encoded).
See DAVCollection.get_member_names()
"""
# On Windows NT/2k/XP and Unix, if path is a Unicode object, the result
# will be a list of Unicode objects.
# Undecodable filenames wil... | [
"Return",
"list",
"of",
"direct",
"collection",
"member",
"names",
"(",
"utf",
"-",
"8",
"encoded",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L203-L230 | [
"def",
"get_member_names",
"(",
"self",
")",
":",
"# On Windows NT/2k/XP and Unix, if path is a Unicode object, the result",
"# will be a list of Unicode objects.",
"# Undecodable filenames will still be returned as string objects",
"# If we don't request unicode, for example Vista may return a '?... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FolderResource.get_member | Return direct collection member (DAVResource or derived).
See DAVCollection.get_member() | wsgidav/fs_dav_provider.py | def get_member(self, name):
"""Return direct collection member (DAVResource or derived).
See DAVCollection.get_member()
"""
assert compat.is_native(name), "{!r}".format(name)
fp = os.path.join(self._file_path, compat.to_unicode(name))
# name = name.encode("utf8")
... | def get_member(self, name):
"""Return direct collection member (DAVResource or derived).
See DAVCollection.get_member()
"""
assert compat.is_native(name), "{!r}".format(name)
fp = os.path.join(self._file_path, compat.to_unicode(name))
# name = name.encode("utf8")
... | [
"Return",
"direct",
"collection",
"member",
"(",
"DAVResource",
"or",
"derived",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L232-L248 | [
"def",
"get_member",
"(",
"self",
",",
"name",
")",
":",
"assert",
"compat",
".",
"is_native",
"(",
"name",
")",
",",
"\"{!r}\"",
".",
"format",
"(",
"name",
")",
"fp",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"_file_path",
",",
"comp... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FolderResource.create_empty_resource | Create an empty (length-0) resource.
See DAVResource.create_empty_resource() | wsgidav/fs_dav_provider.py | def create_empty_resource(self, name):
"""Create an empty (length-0) resource.
See DAVResource.create_empty_resource()
"""
assert "/" not in name
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
path = util.join_uri(self.path, name)
fp = self... | def create_empty_resource(self, name):
"""Create an empty (length-0) resource.
See DAVResource.create_empty_resource()
"""
assert "/" not in name
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
path = util.join_uri(self.path, name)
fp = self... | [
"Create",
"an",
"empty",
"(",
"length",
"-",
"0",
")",
"resource",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L252-L264 | [
"def",
"create_empty_resource",
"(",
"self",
",",
"name",
")",
":",
"assert",
"\"/\"",
"not",
"in",
"name",
"if",
"self",
".",
"provider",
".",
"readonly",
":",
"raise",
"DAVError",
"(",
"HTTP_FORBIDDEN",
")",
"path",
"=",
"util",
".",
"join_uri",
"(",
"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FolderResource.create_collection | Create a new collection as member of self.
See DAVResource.create_collection() | wsgidav/fs_dav_provider.py | def create_collection(self, name):
"""Create a new collection as member of self.
See DAVResource.create_collection()
"""
assert "/" not in name
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
path = util.join_uri(self.path, name)
fp = self.p... | def create_collection(self, name):
"""Create a new collection as member of self.
See DAVResource.create_collection()
"""
assert "/" not in name
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
path = util.join_uri(self.path, name)
fp = self.p... | [
"Create",
"a",
"new",
"collection",
"as",
"member",
"of",
"self",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L266-L276 | [
"def",
"create_collection",
"(",
"self",
",",
"name",
")",
":",
"assert",
"\"/\"",
"not",
"in",
"name",
"if",
"self",
".",
"provider",
".",
"readonly",
":",
"raise",
"DAVError",
"(",
"HTTP_FORBIDDEN",
")",
"path",
"=",
"util",
".",
"join_uri",
"(",
"self... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FolderResource.delete | Remove this resource or collection (recursive).
See DAVResource.delete() | wsgidav/fs_dav_provider.py | def delete(self):
"""Remove this resource or collection (recursive).
See DAVResource.delete()
"""
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
shutil.rmtree(self._file_path, ignore_errors=False)
self.remove_all_properties(True)
self.remov... | def delete(self):
"""Remove this resource or collection (recursive).
See DAVResource.delete()
"""
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
shutil.rmtree(self._file_path, ignore_errors=False)
self.remove_all_properties(True)
self.remov... | [
"Remove",
"this",
"resource",
"or",
"collection",
"(",
"recursive",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L278-L287 | [
"def",
"delete",
"(",
"self",
")",
":",
"if",
"self",
".",
"provider",
".",
"readonly",
":",
"raise",
"DAVError",
"(",
"HTTP_FORBIDDEN",
")",
"shutil",
".",
"rmtree",
"(",
"self",
".",
"_file_path",
",",
"ignore_errors",
"=",
"False",
")",
"self",
".",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FolderResource.copy_move_single | See DAVResource.copy_move_single() | wsgidav/fs_dav_provider.py | def copy_move_single(self, dest_path, is_move):
"""See DAVResource.copy_move_single() """
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
assert not util.is_equal_or_child_uri(self.path, dest_path)
... | def copy_move_single(self, dest_path, is_move):
"""See DAVResource.copy_move_single() """
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
fpDest = self.provider._loc_to_file_path(dest_path, self.environ)
assert not util.is_equal_or_child_uri(self.path, dest_path)
... | [
"See",
"DAVResource",
".",
"copy_move_single",
"()"
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L289-L319 | [
"def",
"copy_move_single",
"(",
"self",
",",
"dest_path",
",",
"is_move",
")",
":",
"if",
"self",
".",
"provider",
".",
"readonly",
":",
"raise",
"DAVError",
"(",
"HTTP_FORBIDDEN",
")",
"fpDest",
"=",
"self",
".",
"provider",
".",
"_loc_to_file_path",
"(",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FilesystemProvider._loc_to_file_path | Convert resource path to a unicode absolute file path.
Optional environ argument may be useful e.g. in relation to per-user
sub-folder chrooting inside root_folder_path. | wsgidav/fs_dav_provider.py | def _loc_to_file_path(self, path, environ=None):
"""Convert resource path to a unicode absolute file path.
Optional environ argument may be useful e.g. in relation to per-user
sub-folder chrooting inside root_folder_path.
"""
root_path = self.root_folder_path
assert root_... | def _loc_to_file_path(self, path, environ=None):
"""Convert resource path to a unicode absolute file path.
Optional environ argument may be useful e.g. in relation to per-user
sub-folder chrooting inside root_folder_path.
"""
root_path = self.root_folder_path
assert root_... | [
"Convert",
"resource",
"path",
"to",
"a",
"unicode",
"absolute",
"file",
"path",
".",
"Optional",
"environ",
"argument",
"may",
"be",
"useful",
"e",
".",
"g",
".",
"in",
"relation",
"to",
"per",
"-",
"user",
"sub",
"-",
"folder",
"chrooting",
"inside",
"... | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L378-L399 | [
"def",
"_loc_to_file_path",
"(",
"self",
",",
"path",
",",
"environ",
"=",
"None",
")",
":",
"root_path",
"=",
"self",
".",
"root_folder_path",
"assert",
"root_path",
"is",
"not",
"None",
"assert",
"compat",
".",
"is_native",
"(",
"root_path",
")",
"assert",... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | FilesystemProvider.get_resource_inst | Return info dictionary for path.
See DAVProvider.get_resource_inst() | wsgidav/fs_dav_provider.py | def get_resource_inst(self, path, environ):
"""Return info dictionary for path.
See DAVProvider.get_resource_inst()
"""
self._count_get_resource_inst += 1
fp = self._loc_to_file_path(path, environ)
if not os.path.exists(fp):
return None
if os.path.is... | def get_resource_inst(self, path, environ):
"""Return info dictionary for path.
See DAVProvider.get_resource_inst()
"""
self._count_get_resource_inst += 1
fp = self._loc_to_file_path(path, environ)
if not os.path.exists(fp):
return None
if os.path.is... | [
"Return",
"info",
"dictionary",
"for",
"path",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/fs_dav_provider.py#L404-L416 | [
"def",
"get_resource_inst",
"(",
"self",
",",
"path",
",",
"environ",
")",
":",
"self",
".",
"_count_get_resource_inst",
"+=",
"1",
"fp",
"=",
"self",
".",
"_loc_to_file_path",
"(",
"path",
",",
"environ",
")",
"if",
"not",
"os",
".",
"path",
".",
"exist... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | lock_string | Return readable rep. | wsgidav/lock_manager.py | def lock_string(lock_dict):
"""Return readable rep."""
if not lock_dict:
return "Lock: None"
if lock_dict["expire"] < 0:
expire = "Infinite ({})".format(lock_dict["expire"])
else:
expire = "{} (in {} seconds)".format(
util.get_log_time(lock_dict["expire"]), lock_dict... | def lock_string(lock_dict):
"""Return readable rep."""
if not lock_dict:
return "Lock: None"
if lock_dict["expire"] < 0:
expire = "Infinite ({})".format(lock_dict["expire"])
else:
expire = "{} (in {} seconds)".format(
util.get_log_time(lock_dict["expire"]), lock_dict... | [
"Return",
"readable",
"rep",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L80-L100 | [
"def",
"lock_string",
"(",
"lock_dict",
")",
":",
"if",
"not",
"lock_dict",
":",
"return",
"\"Lock: None\"",
"if",
"lock_dict",
"[",
"\"expire\"",
"]",
"<",
"0",
":",
"expire",
"=",
"\"Infinite ({})\"",
".",
"format",
"(",
"lock_dict",
"[",
"\"expire\"",
"]"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockManager._generate_lock | Acquire lock and return lock_dict.
principal
Name of the principal.
lock_type
Must be 'write'.
lock_scope
Must be 'shared' or 'exclusive'.
lock_depth
Must be '0' or 'infinity'.
lock_owner
String identifying the owner.
... | wsgidav/lock_manager.py | def _generate_lock(
self, principal, lock_type, lock_scope, lock_depth, lock_owner, path, timeout
):
"""Acquire lock and return lock_dict.
principal
Name of the principal.
lock_type
Must be 'write'.
lock_scope
Must be 'shared' or 'exclusiv... | def _generate_lock(
self, principal, lock_type, lock_scope, lock_depth, lock_owner, path, timeout
):
"""Acquire lock and return lock_dict.
principal
Name of the principal.
lock_type
Must be 'write'.
lock_scope
Must be 'shared' or 'exclusiv... | [
"Acquire",
"lock",
"and",
"return",
"lock_dict",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L179-L217 | [
"def",
"_generate_lock",
"(",
"self",
",",
"principal",
",",
"lock_type",
",",
"lock_scope",
",",
"lock_depth",
",",
"lock_owner",
",",
"path",
",",
"timeout",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"=",
"LockManager",
".",
"LOCK_TIME_OUT_D... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockManager.acquire | Check for permissions and acquire a lock.
On success return new lock dictionary.
On error raise a DAVError with an embedded DAVErrorCondition. | wsgidav/lock_manager.py | def acquire(
self,
url,
lock_type,
lock_scope,
lock_depth,
lock_owner,
timeout,
principal,
token_list,
):
"""Check for permissions and acquire a lock.
On success return new lock dictionary.
On error raise a DAVError wit... | def acquire(
self,
url,
lock_type,
lock_scope,
lock_depth,
lock_owner,
timeout,
principal,
token_list,
):
"""Check for permissions and acquire a lock.
On success return new lock dictionary.
On error raise a DAVError wit... | [
"Check",
"for",
"permissions",
"and",
"acquire",
"a",
"lock",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L219-L246 | [
"def",
"acquire",
"(",
"self",
",",
"url",
",",
"lock_type",
",",
"lock_scope",
",",
"lock_depth",
",",
"lock_owner",
",",
"timeout",
",",
"principal",
",",
"token_list",
",",
")",
":",
"url",
"=",
"normalize_lock_root",
"(",
"url",
")",
"self",
".",
"_l... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockManager.refresh | Set new timeout for lock, if existing and valid. | wsgidav/lock_manager.py | def refresh(self, token, timeout=None):
"""Set new timeout for lock, if existing and valid."""
if timeout is None:
timeout = LockManager.LOCK_TIME_OUT_DEFAULT
return self.storage.refresh(token, timeout) | def refresh(self, token, timeout=None):
"""Set new timeout for lock, if existing and valid."""
if timeout is None:
timeout = LockManager.LOCK_TIME_OUT_DEFAULT
return self.storage.refresh(token, timeout) | [
"Set",
"new",
"timeout",
"for",
"lock",
"if",
"existing",
"and",
"valid",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L248-L252 | [
"def",
"refresh",
"(",
"self",
",",
"token",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"=",
"LockManager",
".",
"LOCK_TIME_OUT_DEFAULT",
"return",
"self",
".",
"storage",
".",
"refresh",
"(",
"token",
",",
"tim... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockManager.get_lock | Return lock_dict, or None, if not found or invalid.
Side effect: if lock is expired, it will be purged and None is returned.
key:
name of lock attribute that will be returned instead of a dictionary. | wsgidav/lock_manager.py | def get_lock(self, token, key=None):
"""Return lock_dict, or None, if not found or invalid.
Side effect: if lock is expired, it will be purged and None is returned.
key:
name of lock attribute that will be returned instead of a dictionary.
"""
assert key in (
... | def get_lock(self, token, key=None):
"""Return lock_dict, or None, if not found or invalid.
Side effect: if lock is expired, it will be purged and None is returned.
key:
name of lock attribute that will be returned instead of a dictionary.
"""
assert key in (
... | [
"Return",
"lock_dict",
"or",
"None",
"if",
"not",
"found",
"or",
"invalid",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L254-L276 | [
"def",
"get_lock",
"(",
"self",
",",
"token",
",",
"key",
"=",
"None",
")",
":",
"assert",
"key",
"in",
"(",
"None",
",",
"\"type\"",
",",
"\"scope\"",
",",
"\"depth\"",
",",
"\"owner\"",
",",
"\"root\"",
",",
"\"timeout\"",
",",
"\"principal\"",
",",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockManager.get_url_lock_list | Return list of lock_dict, if <url> is protected by at least one direct, valid lock.
Side effect: expired locks for this url are purged. | wsgidav/lock_manager.py | def get_url_lock_list(self, url):
"""Return list of lock_dict, if <url> is protected by at least one direct, valid lock.
Side effect: expired locks for this url are purged.
"""
url = normalize_lock_root(url)
lockList = self.storage.get_lock_list(
url, include_root=Tr... | def get_url_lock_list(self, url):
"""Return list of lock_dict, if <url> is protected by at least one direct, valid lock.
Side effect: expired locks for this url are purged.
"""
url = normalize_lock_root(url)
lockList = self.storage.get_lock_list(
url, include_root=Tr... | [
"Return",
"list",
"of",
"lock_dict",
"if",
"<url",
">",
"is",
"protected",
"by",
"at",
"least",
"one",
"direct",
"valid",
"lock",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L286-L295 | [
"def",
"get_url_lock_list",
"(",
"self",
",",
"url",
")",
":",
"url",
"=",
"normalize_lock_root",
"(",
"url",
")",
"lockList",
"=",
"self",
".",
"storage",
".",
"get_lock_list",
"(",
"url",
",",
"include_root",
"=",
"True",
",",
"include_children",
"=",
"F... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockManager.get_indirect_url_lock_list | Return a list of valid lockDicts, that protect <path> directly or indirectly.
If a principal is given, only locks owned by this principal are returned.
Side effect: expired locks for this path and all parents are purged. | wsgidav/lock_manager.py | def get_indirect_url_lock_list(self, url, principal=None):
"""Return a list of valid lockDicts, that protect <path> directly or indirectly.
If a principal is given, only locks owned by this principal are returned.
Side effect: expired locks for this path and all parents are purged.
"""
... | def get_indirect_url_lock_list(self, url, principal=None):
"""Return a list of valid lockDicts, that protect <path> directly or indirectly.
If a principal is given, only locks owned by this principal are returned.
Side effect: expired locks for this path and all parents are purged.
"""
... | [
"Return",
"a",
"list",
"of",
"valid",
"lockDicts",
"that",
"protect",
"<path",
">",
"directly",
"or",
"indirectly",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L297-L320 | [
"def",
"get_indirect_url_lock_list",
"(",
"self",
",",
"url",
",",
"principal",
"=",
"None",
")",
":",
"url",
"=",
"normalize_lock_root",
"(",
"url",
")",
"lockList",
"=",
"[",
"]",
"u",
"=",
"url",
"while",
"u",
":",
"ll",
"=",
"self",
".",
"storage",... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockManager.is_url_locked_by_token | Check, if url (or any of it's parents) is locked by lock_token. | wsgidav/lock_manager.py | def is_url_locked_by_token(self, url, lock_token):
"""Check, if url (or any of it's parents) is locked by lock_token."""
lockUrl = self.get_lock(lock_token, "root")
return lockUrl and util.is_equal_or_child_uri(lockUrl, url) | def is_url_locked_by_token(self, url, lock_token):
"""Check, if url (or any of it's parents) is locked by lock_token."""
lockUrl = self.get_lock(lock_token, "root")
return lockUrl and util.is_equal_or_child_uri(lockUrl, url) | [
"Check",
"if",
"url",
"(",
"or",
"any",
"of",
"it",
"s",
"parents",
")",
"is",
"locked",
"by",
"lock_token",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L327-L330 | [
"def",
"is_url_locked_by_token",
"(",
"self",
",",
"url",
",",
"lock_token",
")",
":",
"lockUrl",
"=",
"self",
".",
"get_lock",
"(",
"lock_token",
",",
"\"root\"",
")",
"return",
"lockUrl",
"and",
"util",
".",
"is_equal_or_child_uri",
"(",
"lockUrl",
",",
"u... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | LockManager._check_lock_permission | Check, if <principal> can lock <url>, otherwise raise an error.
If locking <url> would create a conflict, DAVError(HTTP_LOCKED) is
raised. An embedded DAVErrorCondition contains the conflicting resource.
@see http://www.webdav.org/specs/rfc4918.html#lock-model
- Parent locks WILL NOT ... | wsgidav/lock_manager.py | def _check_lock_permission(
self, url, lock_type, lock_scope, lock_depth, token_list, principal
):
"""Check, if <principal> can lock <url>, otherwise raise an error.
If locking <url> would create a conflict, DAVError(HTTP_LOCKED) is
raised. An embedded DAVErrorCondition contains the... | def _check_lock_permission(
self, url, lock_type, lock_scope, lock_depth, token_list, principal
):
"""Check, if <principal> can lock <url>, otherwise raise an error.
If locking <url> would create a conflict, DAVError(HTTP_LOCKED) is
raised. An embedded DAVErrorCondition contains the... | [
"Check",
"if",
"<principal",
">",
"can",
"lock",
"<url",
">",
"otherwise",
"raise",
"an",
"error",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/lock_manager.py#L341-L431 | [
"def",
"_check_lock_permission",
"(",
"self",
",",
"url",
",",
"lock_type",
",",
"lock_scope",
",",
"lock_depth",
",",
"token_list",
",",
"principal",
")",
":",
"assert",
"lock_type",
"==",
"\"write\"",
"assert",
"lock_scope",
"in",
"(",
"\"shared\"",
",",
"\"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | ShelvePropertyManager._sync | Write persistent dictionary to disc. | wsgidav/prop_man/property_manager.py | def _sync(self):
"""Write persistent dictionary to disc."""
_logger.debug("_sync()")
self._lock.acquire_write() # TODO: read access is enough?
try:
if self._loaded:
self._dict.sync()
finally:
self._lock.release() | def _sync(self):
"""Write persistent dictionary to disc."""
_logger.debug("_sync()")
self._lock.acquire_write() # TODO: read access is enough?
try:
if self._loaded:
self._dict.sync()
finally:
self._lock.release() | [
"Write",
"persistent",
"dictionary",
"to",
"disc",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/prop_man/property_manager.py#L307-L315 | [
"def",
"_sync",
"(",
"self",
")",
":",
"_logger",
".",
"debug",
"(",
"\"_sync()\"",
")",
"self",
".",
"_lock",
".",
"acquire_write",
"(",
")",
"# TODO: read access is enough?",
"try",
":",
"if",
"self",
".",
"_loaded",
":",
"self",
".",
"_dict",
".",
"sy... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | ReadWriteLock.acquire_read | Acquire a read lock for the current thread, waiting at most
timeout seconds or doing a non-blocking check in case timeout is <= 0.
In case timeout is None, the call to acquire_read blocks until the
lock request can be serviced.
In case the timeout expires before the lock could be servi... | wsgidav/rw_lock.py | def acquire_read(self, timeout=None):
"""Acquire a read lock for the current thread, waiting at most
timeout seconds or doing a non-blocking check in case timeout is <= 0.
In case timeout is None, the call to acquire_read blocks until the
lock request can be serviced.
In case t... | def acquire_read(self, timeout=None):
"""Acquire a read lock for the current thread, waiting at most
timeout seconds or doing a non-blocking check in case timeout is <= 0.
In case timeout is None, the call to acquire_read blocks until the
lock request can be serviced.
In case t... | [
"Acquire",
"a",
"read",
"lock",
"for",
"the",
"current",
"thread",
"waiting",
"at",
"most",
"timeout",
"seconds",
"or",
"doing",
"a",
"non",
"-",
"blocking",
"check",
"in",
"case",
"timeout",
"is",
"<",
"=",
"0",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/rw_lock.py#L67-L112 | [
"def",
"acquire_read",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"not",
"None",
":",
"endtime",
"=",
"time",
"(",
")",
"+",
"timeout",
"me",
"=",
"currentThread",
"(",
")",
"self",
".",
"__condition",
".",
"acquire",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | ReadWriteLock.acquire_write | Acquire a write lock for the current thread, waiting at most
timeout seconds or doing a non-blocking check in case timeout is <= 0.
In case the write lock cannot be serviced due to the deadlock
condition mentioned above, a ValueError is raised.
In case timeout is None, the call to acqu... | wsgidav/rw_lock.py | def acquire_write(self, timeout=None):
"""Acquire a write lock for the current thread, waiting at most
timeout seconds or doing a non-blocking check in case timeout is <= 0.
In case the write lock cannot be serviced due to the deadlock
condition mentioned above, a ValueError is raised.
... | def acquire_write(self, timeout=None):
"""Acquire a write lock for the current thread, waiting at most
timeout seconds or doing a non-blocking check in case timeout is <= 0.
In case the write lock cannot be serviced due to the deadlock
condition mentioned above, a ValueError is raised.
... | [
"Acquire",
"a",
"write",
"lock",
"for",
"the",
"current",
"thread",
"waiting",
"at",
"most",
"timeout",
"seconds",
"or",
"doing",
"a",
"non",
"-",
"blocking",
"check",
"in",
"case",
"timeout",
"is",
"<",
"=",
"0",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/rw_lock.py#L114-L197 | [
"def",
"acquire_write",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"not",
"None",
":",
"endtime",
"=",
"time",
"(",
")",
"+",
"timeout",
"me",
",",
"upgradewriter",
"=",
"currentThread",
"(",
")",
",",
"False",
"self",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | ReadWriteLock.release | Release the currently held lock.
In case the current thread holds no lock, a ValueError is thrown. | wsgidav/rw_lock.py | def release(self):
"""Release the currently held lock.
In case the current thread holds no lock, a ValueError is thrown."""
me = currentThread()
self.__condition.acquire()
try:
if self.__writer is me:
# We are the writer, take one nesting depth away.... | def release(self):
"""Release the currently held lock.
In case the current thread holds no lock, a ValueError is thrown."""
me = currentThread()
self.__condition.acquire()
try:
if self.__writer is me:
# We are the writer, take one nesting depth away.... | [
"Release",
"the",
"currently",
"held",
"lock",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/rw_lock.py#L199-L228 | [
"def",
"release",
"(",
"self",
")",
":",
"me",
"=",
"currentThread",
"(",
")",
"self",
".",
"__condition",
".",
"acquire",
"(",
")",
"try",
":",
"if",
"self",
".",
"__writer",
"is",
"me",
":",
"# We are the writer, take one nesting depth away.",
"self",
".",... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | _parse_gmt_time | Return a standard time tuple (see time and calendar), for a date/time string. | wsgidav/util.py | def _parse_gmt_time(timestring):
"""Return a standard time tuple (see time and calendar), for a date/time string."""
# Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
try:
return time.strptime(timestring, "%a, %d %b %Y %H:%M:%S GMT")
except Exception:
pass
# Sunday, 06... | def _parse_gmt_time(timestring):
"""Return a standard time tuple (see time and calendar), for a date/time string."""
# Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
try:
return time.strptime(timestring, "%a, %d %b %Y %H:%M:%S GMT")
except Exception:
pass
# Sunday, 06... | [
"Return",
"a",
"standard",
"time",
"tuple",
"(",
"see",
"time",
"and",
"calendar",
")",
"for",
"a",
"date",
"/",
"time",
"string",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L91-L118 | [
"def",
"_parse_gmt_time",
"(",
"timestring",
")",
":",
"# Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123",
"try",
":",
"return",
"time",
".",
"strptime",
"(",
"timestring",
",",
"\"%a, %d %b %Y %H:%M:%S GMT\"",
")",
"except",
"Exception",
":",
"pass",
"# Su... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | init_logging | Initialize base logger named 'wsgidav'.
The base logger is filtered by the `verbose` configuration option.
Log entries will have a time stamp and thread id.
:Parameters:
verbose : int
Verbosity configuration (0..5)
enable_loggers : string list
List of module logger ... | wsgidav/util.py | def init_logging(config):
"""Initialize base logger named 'wsgidav'.
The base logger is filtered by the `verbose` configuration option.
Log entries will have a time stamp and thread id.
:Parameters:
verbose : int
Verbosity configuration (0..5)
enable_loggers : string list
... | def init_logging(config):
"""Initialize base logger named 'wsgidav'.
The base logger is filtered by the `verbose` configuration option.
Log entries will have a time stamp and thread id.
:Parameters:
verbose : int
Verbosity configuration (0..5)
enable_loggers : string list
... | [
"Initialize",
"base",
"logger",
"named",
"wsgidav",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L126-L243 | [
"def",
"init_logging",
"(",
"config",
")",
":",
"verbose",
"=",
"config",
".",
"get",
"(",
"\"verbose\"",
",",
"3",
")",
"enable_loggers",
"=",
"config",
".",
"get",
"(",
"\"enable_loggers\"",
",",
"[",
"]",
")",
"if",
"enable_loggers",
"is",
"None",
":"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | get_module_logger | Create a module logger, that can be en/disabled by configuration.
@see: unit.init_logging | wsgidav/util.py | def get_module_logger(moduleName, defaultToVerbose=False):
"""Create a module logger, that can be en/disabled by configuration.
@see: unit.init_logging
"""
# moduleName = moduleName.split(".")[-1]
if not moduleName.startswith(BASE_LOGGER_NAME + "."):
moduleName = BASE_LOGGER_NAME + "." + mo... | def get_module_logger(moduleName, defaultToVerbose=False):
"""Create a module logger, that can be en/disabled by configuration.
@see: unit.init_logging
"""
# moduleName = moduleName.split(".")[-1]
if not moduleName.startswith(BASE_LOGGER_NAME + "."):
moduleName = BASE_LOGGER_NAME + "." + mo... | [
"Create",
"a",
"module",
"logger",
"that",
"can",
"be",
"en",
"/",
"disabled",
"by",
"configuration",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L246-L257 | [
"def",
"get_module_logger",
"(",
"moduleName",
",",
"defaultToVerbose",
"=",
"False",
")",
":",
"# moduleName = moduleName.split(\".\")[-1]",
"if",
"not",
"moduleName",
".",
"startswith",
"(",
"BASE_LOGGER_NAME",
"+",
"\".\"",
")",
":",
"moduleName",
"=",
"BASE_LOGGER... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | dynamic_import_class | Import a class from a module string, e.g. ``my.module.ClassName``. | wsgidav/util.py | def dynamic_import_class(name):
"""Import a class from a module string, e.g. ``my.module.ClassName``."""
import importlib
module_name, class_name = name.rsplit(".", 1)
try:
module = importlib.import_module(module_name)
except Exception as e:
_logger.exception("Dynamic import of {!r}... | def dynamic_import_class(name):
"""Import a class from a module string, e.g. ``my.module.ClassName``."""
import importlib
module_name, class_name = name.rsplit(".", 1)
try:
module = importlib.import_module(module_name)
except Exception as e:
_logger.exception("Dynamic import of {!r}... | [
"Import",
"a",
"class",
"from",
"a",
"module",
"string",
"e",
".",
"g",
".",
"my",
".",
"module",
".",
"ClassName",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L274-L285 | [
"def",
"dynamic_import_class",
"(",
"name",
")",
":",
"import",
"importlib",
"module_name",
",",
"class_name",
"=",
"name",
".",
"rsplit",
"(",
"\".\"",
",",
"1",
")",
"try",
":",
"module",
"=",
"importlib",
".",
"import_module",
"(",
"module_name",
")",
"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | dynamic_instantiate_middleware | Import a class and instantiate with custom args.
Example:
name = "my.module.Foo"
args_dict = {
"bar": 42,
"baz": "qux"
}
=>
from my.module import Foo
return Foo(bar=42, baz="qux") | wsgidav/util.py | def dynamic_instantiate_middleware(name, args, expand=None):
"""Import a class and instantiate with custom args.
Example:
name = "my.module.Foo"
args_dict = {
"bar": 42,
"baz": "qux"
}
=>
from my.module import Foo
return Foo(bar=42, ba... | def dynamic_instantiate_middleware(name, args, expand=None):
"""Import a class and instantiate with custom args.
Example:
name = "my.module.Foo"
args_dict = {
"bar": 42,
"baz": "qux"
}
=>
from my.module import Foo
return Foo(bar=42, ba... | [
"Import",
"a",
"class",
"and",
"instantiate",
"with",
"custom",
"args",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L288-L323 | [
"def",
"dynamic_instantiate_middleware",
"(",
"name",
",",
"args",
",",
"expand",
"=",
"None",
")",
":",
"def",
"_expand",
"(",
"v",
")",
":",
"\"\"\"Replace some string templates with defined values.\"\"\"",
"if",
"expand",
"and",
"compat",
".",
"is_basestring",
"(... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | save_split | Split string, always returning n-tuple (filled with None if necessary). | wsgidav/util.py | def save_split(s, sep, maxsplit):
"""Split string, always returning n-tuple (filled with None if necessary)."""
tok = s.split(sep, maxsplit)
while len(tok) <= maxsplit:
tok.append(None)
return tok | def save_split(s, sep, maxsplit):
"""Split string, always returning n-tuple (filled with None if necessary)."""
tok = s.split(sep, maxsplit)
while len(tok) <= maxsplit:
tok.append(None)
return tok | [
"Split",
"string",
"always",
"returning",
"n",
"-",
"tuple",
"(",
"filled",
"with",
"None",
"if",
"necessary",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L341-L346 | [
"def",
"save_split",
"(",
"s",
",",
"sep",
",",
"maxsplit",
")",
":",
"tok",
"=",
"s",
".",
"split",
"(",
"sep",
",",
"maxsplit",
")",
"while",
"len",
"(",
"tok",
")",
"<=",
"maxsplit",
":",
"tok",
".",
"append",
"(",
"None",
")",
"return",
"tok"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | pop_path | Return '/a/b/c' -> ('a', '/b/c'). | wsgidav/util.py | def pop_path(path):
"""Return '/a/b/c' -> ('a', '/b/c')."""
if path in ("", "/"):
return ("", "")
assert path.startswith("/")
first, _sep, rest = path.lstrip("/").partition("/")
return (first, "/" + rest) | def pop_path(path):
"""Return '/a/b/c' -> ('a', '/b/c')."""
if path in ("", "/"):
return ("", "")
assert path.startswith("/")
first, _sep, rest = path.lstrip("/").partition("/")
return (first, "/" + rest) | [
"Return",
"/",
"a",
"/",
"b",
"/",
"c",
"-",
">",
"(",
"a",
"/",
"b",
"/",
"c",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L349-L355 | [
"def",
"pop_path",
"(",
"path",
")",
":",
"if",
"path",
"in",
"(",
"\"\"",
",",
"\"/\"",
")",
":",
"return",
"(",
"\"\"",
",",
"\"\"",
")",
"assert",
"path",
".",
"startswith",
"(",
"\"/\"",
")",
"first",
",",
"_sep",
",",
"rest",
"=",
"path",
".... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | pop_path2 | Return '/a/b/c' -> ('a', 'b', '/c'). | wsgidav/util.py | def pop_path2(path):
"""Return '/a/b/c' -> ('a', 'b', '/c')."""
if path in ("", "/"):
return ("", "", "")
first, rest = pop_path(path)
second, rest = pop_path(rest)
return (first, second, "/" + rest) | def pop_path2(path):
"""Return '/a/b/c' -> ('a', 'b', '/c')."""
if path in ("", "/"):
return ("", "", "")
first, rest = pop_path(path)
second, rest = pop_path(rest)
return (first, second, "/" + rest) | [
"Return",
"/",
"a",
"/",
"b",
"/",
"c",
"-",
">",
"(",
"a",
"b",
"/",
"c",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L358-L364 | [
"def",
"pop_path2",
"(",
"path",
")",
":",
"if",
"path",
"in",
"(",
"\"\"",
",",
"\"/\"",
")",
":",
"return",
"(",
"\"\"",
",",
"\"\"",
",",
"\"\"",
")",
"first",
",",
"rest",
"=",
"pop_path",
"(",
"path",
")",
"second",
",",
"rest",
"=",
"pop_pa... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | shift_path | Return ('/a', '/b/c') -> ('b', '/a/b', 'c'). | wsgidav/util.py | def shift_path(script_name, path_info):
"""Return ('/a', '/b/c') -> ('b', '/a/b', 'c')."""
segment, rest = pop_path(path_info)
return (segment, join_uri(script_name.rstrip("/"), segment), rest.rstrip("/")) | def shift_path(script_name, path_info):
"""Return ('/a', '/b/c') -> ('b', '/a/b', 'c')."""
segment, rest = pop_path(path_info)
return (segment, join_uri(script_name.rstrip("/"), segment), rest.rstrip("/")) | [
"Return",
"(",
"/",
"a",
"/",
"b",
"/",
"c",
")",
"-",
">",
"(",
"b",
"/",
"a",
"/",
"b",
"c",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L367-L370 | [
"def",
"shift_path",
"(",
"script_name",
",",
"path_info",
")",
":",
"segment",
",",
"rest",
"=",
"pop_path",
"(",
"path_info",
")",
"return",
"(",
"segment",
",",
"join_uri",
"(",
"script_name",
".",
"rstrip",
"(",
"\"/\"",
")",
",",
"segment",
")",
","... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | split_namespace | Return (namespace, localname) tuple for a property name in Clark Notation.
Namespace defaults to ''.
Example:
'{DAV:}foo' -> ('DAV:', 'foo')
'bar' -> ('', 'bar') | wsgidav/util.py | def split_namespace(clarkName):
"""Return (namespace, localname) tuple for a property name in Clark Notation.
Namespace defaults to ''.
Example:
'{DAV:}foo' -> ('DAV:', 'foo')
'bar' -> ('', 'bar')
"""
if clarkName.startswith("{") and "}" in clarkName:
ns, localname = clarkName.spl... | def split_namespace(clarkName):
"""Return (namespace, localname) tuple for a property name in Clark Notation.
Namespace defaults to ''.
Example:
'{DAV:}foo' -> ('DAV:', 'foo')
'bar' -> ('', 'bar')
"""
if clarkName.startswith("{") and "}" in clarkName:
ns, localname = clarkName.spl... | [
"Return",
"(",
"namespace",
"localname",
")",
"tuple",
"for",
"a",
"property",
"name",
"in",
"Clark",
"Notation",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L373-L384 | [
"def",
"split_namespace",
"(",
"clarkName",
")",
":",
"if",
"clarkName",
".",
"startswith",
"(",
"\"{\"",
")",
"and",
"\"}\"",
"in",
"clarkName",
":",
"ns",
",",
"localname",
"=",
"clarkName",
".",
"split",
"(",
"\"}\"",
",",
"1",
")",
"return",
"(",
"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | to_unicode_safe | Convert a binary string to Unicode using UTF-8 (fallback to ISO-8859-1). | wsgidav/util.py | def to_unicode_safe(s):
"""Convert a binary string to Unicode using UTF-8 (fallback to ISO-8859-1)."""
try:
u = compat.to_unicode(s, "utf8")
except ValueError:
_logger.error(
"to_unicode_safe({!r}) *** UTF-8 failed. Trying ISO-8859-1".format(s)
)
u = compat.to_uni... | def to_unicode_safe(s):
"""Convert a binary string to Unicode using UTF-8 (fallback to ISO-8859-1)."""
try:
u = compat.to_unicode(s, "utf8")
except ValueError:
_logger.error(
"to_unicode_safe({!r}) *** UTF-8 failed. Trying ISO-8859-1".format(s)
)
u = compat.to_uni... | [
"Convert",
"a",
"binary",
"string",
"to",
"Unicode",
"using",
"UTF",
"-",
"8",
"(",
"fallback",
"to",
"ISO",
"-",
"8859",
"-",
"1",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L387-L396 | [
"def",
"to_unicode_safe",
"(",
"s",
")",
":",
"try",
":",
"u",
"=",
"compat",
".",
"to_unicode",
"(",
"s",
",",
"\"utf8\"",
")",
"except",
"ValueError",
":",
"_logger",
".",
"error",
"(",
"\"to_unicode_safe({!r}) *** UTF-8 failed. Trying ISO-8859-1\"",
".",
"for... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | safe_re_encode | Re-encode str or binary so that is compatible with a given encoding (replacing
unsupported chars).
We use ASCII as default, which gives us some output that contains \x99 and \u9999
for every character > 127, for easier debugging.
(e.g. if we don't know the encoding, see #87, #96) | wsgidav/util.py | def safe_re_encode(s, encoding_to, errors="backslashreplace"):
"""Re-encode str or binary so that is compatible with a given encoding (replacing
unsupported chars).
We use ASCII as default, which gives us some output that contains \x99 and \u9999
for every character > 127, for easier debugging.
(e.... | def safe_re_encode(s, encoding_to, errors="backslashreplace"):
"""Re-encode str or binary so that is compatible with a given encoding (replacing
unsupported chars).
We use ASCII as default, which gives us some output that contains \x99 and \u9999
for every character > 127, for easier debugging.
(e.... | [
"Re",
"-",
"encode",
"str",
"or",
"binary",
"so",
"that",
"is",
"compatible",
"with",
"a",
"given",
"encoding",
"(",
"replacing",
"unsupported",
"chars",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L399-L415 | [
"def",
"safe_re_encode",
"(",
"s",
",",
"encoding_to",
",",
"errors",
"=",
"\"backslashreplace\"",
")",
":",
"# prev = s",
"if",
"not",
"encoding_to",
":",
"encoding_to",
"=",
"\"ASCII\"",
"if",
"compat",
".",
"is_bytes",
"(",
"s",
")",
":",
"s",
"=",
"s",... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | string_repr | Return a string as hex dump. | wsgidav/util.py | def string_repr(s):
"""Return a string as hex dump."""
if compat.is_bytes(s):
res = "{!r}: ".format(s)
for b in s:
if type(b) is str: # Py2
b = ord(b)
res += "%02x " % b
return res
return "{}".format(s) | def string_repr(s):
"""Return a string as hex dump."""
if compat.is_bytes(s):
res = "{!r}: ".format(s)
for b in s:
if type(b) is str: # Py2
b = ord(b)
res += "%02x " % b
return res
return "{}".format(s) | [
"Return",
"a",
"string",
"as",
"hex",
"dump",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L418-L427 | [
"def",
"string_repr",
"(",
"s",
")",
":",
"if",
"compat",
".",
"is_bytes",
"(",
"s",
")",
":",
"res",
"=",
"\"{!r}: \"",
".",
"format",
"(",
"s",
")",
"for",
"b",
"in",
"s",
":",
"if",
"type",
"(",
"b",
")",
"is",
"str",
":",
"# Py2",
"b",
"=... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | byte_number_string | Convert bytes into human-readable representation. | wsgidav/util.py | def byte_number_string(
number, thousandsSep=True, partition=False, base1024=True, appendBytes=True
):
"""Convert bytes into human-readable representation."""
magsuffix = ""
bytesuffix = ""
if partition:
magnitude = 0
if base1024:
while number >= 1024:
ma... | def byte_number_string(
number, thousandsSep=True, partition=False, base1024=True, appendBytes=True
):
"""Convert bytes into human-readable representation."""
magsuffix = ""
bytesuffix = ""
if partition:
magnitude = 0
if base1024:
while number >= 1024:
ma... | [
"Convert",
"bytes",
"into",
"human",
"-",
"readable",
"representation",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L435-L471 | [
"def",
"byte_number_string",
"(",
"number",
",",
"thousandsSep",
"=",
"True",
",",
"partition",
"=",
"False",
",",
"base1024",
"=",
"True",
",",
"appendBytes",
"=",
"True",
")",
":",
"magsuffix",
"=",
"\"\"",
"bytesuffix",
"=",
"\"\"",
"if",
"partition",
"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | read_and_discard_input | Read 1 byte from wsgi.input, if this has not been done yet.
Returning a response without reading from a request body might confuse the
WebDAV client.
This may happen, if an exception like '401 Not authorized', or
'500 Internal error' was raised BEFORE anything was read from the request
stream.
... | wsgidav/util.py | def read_and_discard_input(environ):
"""Read 1 byte from wsgi.input, if this has not been done yet.
Returning a response without reading from a request body might confuse the
WebDAV client.
This may happen, if an exception like '401 Not authorized', or
'500 Internal error' was raised BEFORE anythin... | def read_and_discard_input(environ):
"""Read 1 byte from wsgi.input, if this has not been done yet.
Returning a response without reading from a request body might confuse the
WebDAV client.
This may happen, if an exception like '401 Not authorized', or
'500 Internal error' was raised BEFORE anythin... | [
"Read",
"1",
"byte",
"from",
"wsgi",
".",
"input",
"if",
"this",
"has",
"not",
"been",
"done",
"yet",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L497-L572 | [
"def",
"read_and_discard_input",
"(",
"environ",
")",
":",
"if",
"environ",
".",
"get",
"(",
"\"wsgidav.some_input_read\"",
")",
"or",
"environ",
".",
"get",
"(",
"\"wsgidav.all_input_read\"",
")",
":",
"return",
"cl",
"=",
"get_content_length",
"(",
"environ",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | fail | Wrapper to raise (and log) DAVError. | wsgidav/util.py | def fail(value, context_info=None, src_exception=None, err_condition=None):
"""Wrapper to raise (and log) DAVError."""
if isinstance(value, Exception):
e = as_DAVError(value)
else:
e = DAVError(value, context_info, src_exception, err_condition)
_logger.error("Raising DAVError {}".format(... | def fail(value, context_info=None, src_exception=None, err_condition=None):
"""Wrapper to raise (and log) DAVError."""
if isinstance(value, Exception):
e = as_DAVError(value)
else:
e = DAVError(value, context_info, src_exception, err_condition)
_logger.error("Raising DAVError {}".format(... | [
"Wrapper",
"to",
"raise",
"(",
"and",
"log",
")",
"DAVError",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L575-L582 | [
"def",
"fail",
"(",
"value",
",",
"context_info",
"=",
"None",
",",
"src_exception",
"=",
"None",
",",
"err_condition",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"Exception",
")",
":",
"e",
"=",
"as_DAVError",
"(",
"value",
")",
"el... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | join_uri | Append segments to URI.
Example: join_uri("/a/b", "c", "d") | wsgidav/util.py | def join_uri(uri, *segments):
"""Append segments to URI.
Example: join_uri("/a/b", "c", "d")
"""
sub = "/".join(segments)
if not sub:
return uri
return uri.rstrip("/") + "/" + sub | def join_uri(uri, *segments):
"""Append segments to URI.
Example: join_uri("/a/b", "c", "d")
"""
sub = "/".join(segments)
if not sub:
return uri
return uri.rstrip("/") + "/" + sub | [
"Append",
"segments",
"to",
"URI",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L619-L627 | [
"def",
"join_uri",
"(",
"uri",
",",
"*",
"segments",
")",
":",
"sub",
"=",
"\"/\"",
".",
"join",
"(",
"segments",
")",
"if",
"not",
"sub",
":",
"return",
"uri",
"return",
"uri",
".",
"rstrip",
"(",
"\"/\"",
")",
"+",
"\"/\"",
"+",
"sub"
] | cec0d84222fc24bea01be1cea91729001963f172 |
valid | is_child_uri | Return True, if childUri is a child of parentUri.
This function accounts for the fact that '/a/b/c' and 'a/b/c/' are
children of '/a/b' (and also of '/a/b/').
Note that '/a/b/cd' is NOT a child of 'a/b/c'. | wsgidav/util.py | def is_child_uri(parentUri, childUri):
"""Return True, if childUri is a child of parentUri.
This function accounts for the fact that '/a/b/c' and 'a/b/c/' are
children of '/a/b' (and also of '/a/b/').
Note that '/a/b/cd' is NOT a child of 'a/b/c'.
"""
return (
parentUri
and chil... | def is_child_uri(parentUri, childUri):
"""Return True, if childUri is a child of parentUri.
This function accounts for the fact that '/a/b/c' and 'a/b/c/' are
children of '/a/b' (and also of '/a/b/').
Note that '/a/b/cd' is NOT a child of 'a/b/c'.
"""
return (
parentUri
and chil... | [
"Return",
"True",
"if",
"childUri",
"is",
"a",
"child",
"of",
"parentUri",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L646-L657 | [
"def",
"is_child_uri",
"(",
"parentUri",
",",
"childUri",
")",
":",
"return",
"(",
"parentUri",
"and",
"childUri",
"and",
"childUri",
".",
"rstrip",
"(",
"\"/\"",
")",
".",
"startswith",
"(",
"parentUri",
".",
"rstrip",
"(",
"\"/\"",
")",
"+",
"\"/\"",
"... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | is_equal_or_child_uri | Return True, if childUri is a child of parentUri or maps to the same resource.
Similar to <util.is_child_uri>_ , but this method also returns True, if parent
equals child. ('/a/b' is considered identical with '/a/b/'). | wsgidav/util.py | def is_equal_or_child_uri(parentUri, childUri):
"""Return True, if childUri is a child of parentUri or maps to the same resource.
Similar to <util.is_child_uri>_ , but this method also returns True, if parent
equals child. ('/a/b' is considered identical with '/a/b/').
"""
return (
parentU... | def is_equal_or_child_uri(parentUri, childUri):
"""Return True, if childUri is a child of parentUri or maps to the same resource.
Similar to <util.is_child_uri>_ , but this method also returns True, if parent
equals child. ('/a/b' is considered identical with '/a/b/').
"""
return (
parentU... | [
"Return",
"True",
"if",
"childUri",
"is",
"a",
"child",
"of",
"parentUri",
"or",
"maps",
"to",
"the",
"same",
"resource",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L660-L670 | [
"def",
"is_equal_or_child_uri",
"(",
"parentUri",
",",
"childUri",
")",
":",
"return",
"(",
"parentUri",
"and",
"childUri",
"and",
"(",
"childUri",
".",
"rstrip",
"(",
"\"/\"",
")",
"+",
"\"/\"",
")",
".",
"startswith",
"(",
"parentUri",
".",
"rstrip",
"("... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | make_complete_url | URL reconstruction according to PEP 333.
@see https://www.python.org/dev/peps/pep-3333/#url-reconstruction | wsgidav/util.py | def make_complete_url(environ, localUri=None):
"""URL reconstruction according to PEP 333.
@see https://www.python.org/dev/peps/pep-3333/#url-reconstruction
"""
url = environ["wsgi.url_scheme"] + "://"
if environ.get("HTTP_HOST"):
url += environ["HTTP_HOST"]
else:
url += environ... | def make_complete_url(environ, localUri=None):
"""URL reconstruction according to PEP 333.
@see https://www.python.org/dev/peps/pep-3333/#url-reconstruction
"""
url = environ["wsgi.url_scheme"] + "://"
if environ.get("HTTP_HOST"):
url += environ["HTTP_HOST"]
else:
url += environ... | [
"URL",
"reconstruction",
"according",
"to",
"PEP",
"333",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L673-L699 | [
"def",
"make_complete_url",
"(",
"environ",
",",
"localUri",
"=",
"None",
")",
":",
"url",
"=",
"environ",
"[",
"\"wsgi.url_scheme\"",
"]",
"+",
"\"://\"",
"if",
"environ",
".",
"get",
"(",
"\"HTTP_HOST\"",
")",
":",
"url",
"+=",
"environ",
"[",
"\"HTTP_HO... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | parse_xml_body | Read request body XML into an etree.Element.
Return None, if no request body was sent.
Raise HTTP_BAD_REQUEST, if something else went wrong.
TODO: this is a very relaxed interpretation: should we raise HTTP_BAD_REQUEST
instead, if CONTENT_LENGTH is missing, invalid, or 0?
RFC: For compatibility w... | wsgidav/util.py | def parse_xml_body(environ, allow_empty=False):
"""Read request body XML into an etree.Element.
Return None, if no request body was sent.
Raise HTTP_BAD_REQUEST, if something else went wrong.
TODO: this is a very relaxed interpretation: should we raise HTTP_BAD_REQUEST
instead, if CONTENT_LENGTH i... | def parse_xml_body(environ, allow_empty=False):
"""Read request body XML into an etree.Element.
Return None, if no request body was sent.
Raise HTTP_BAD_REQUEST, if something else went wrong.
TODO: this is a very relaxed interpretation: should we raise HTTP_BAD_REQUEST
instead, if CONTENT_LENGTH i... | [
"Read",
"request",
"body",
"XML",
"into",
"an",
"etree",
".",
"Element",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L707-L789 | [
"def",
"parse_xml_body",
"(",
"environ",
",",
"allow_empty",
"=",
"False",
")",
":",
"#",
"clHeader",
"=",
"environ",
".",
"get",
"(",
"\"CONTENT_LENGTH\"",
",",
"\"\"",
")",
".",
"strip",
"(",
")",
"# content_length = -1 # read all of stream",
"if",
"clHeade... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | send_status_response | Start a WSGI response for a DAVError or status code. | wsgidav/util.py | def send_status_response(environ, start_response, e, add_headers=None, is_head=False):
"""Start a WSGI response for a DAVError or status code."""
status = get_http_status_string(e)
headers = []
if add_headers:
headers.extend(add_headers)
# if 'keep-alive' in environ.get('HTTP_CONNECTION',... | def send_status_response(environ, start_response, e, add_headers=None, is_head=False):
"""Start a WSGI response for a DAVError or status code."""
status = get_http_status_string(e)
headers = []
if add_headers:
headers.extend(add_headers)
# if 'keep-alive' in environ.get('HTTP_CONNECTION',... | [
"Start",
"a",
"WSGI",
"response",
"for",
"a",
"DAVError",
"or",
"status",
"code",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L803-L839 | [
"def",
"send_status_response",
"(",
"environ",
",",
"start_response",
",",
"e",
",",
"add_headers",
"=",
"None",
",",
"is_head",
"=",
"False",
")",
":",
"status",
"=",
"get_http_status_string",
"(",
"e",
")",
"headers",
"=",
"[",
"]",
"if",
"add_headers",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | add_property_response | Append <response> element to <multistatus> element.
<prop> node depends on the value type:
- str or unicode: add element with this content
- None: add an empty element
- etree.Element: add XML element as child
- DAVError: add an empty element to an own <propstatus> for this status code
... | wsgidav/util.py | def add_property_response(multistatusEL, href, propList):
"""Append <response> element to <multistatus> element.
<prop> node depends on the value type:
- str or unicode: add element with this content
- None: add an empty element
- etree.Element: add XML element as child
- DAVError: add ... | def add_property_response(multistatusEL, href, propList):
"""Append <response> element to <multistatus> element.
<prop> node depends on the value type:
- str or unicode: add element with this content
- None: add an empty element
- etree.Element: add XML element as child
- DAVError: add ... | [
"Append",
"<response",
">",
"element",
"to",
"<multistatus",
">",
"element",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L874-L935 | [
"def",
"add_property_response",
"(",
"multistatusEL",
",",
"href",
",",
"propList",
")",
":",
"# Split propList by status code and build a unique list of namespaces",
"nsCount",
"=",
"1",
"nsDict",
"=",
"{",
"}",
"nsMap",
"=",
"{",
"}",
"propDict",
"=",
"{",
"}",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | calc_base64 | Return base64 encoded binarystring. | wsgidav/util.py | def calc_base64(s):
"""Return base64 encoded binarystring."""
s = compat.to_bytes(s)
s = compat.base64_encodebytes(s).strip() # return bytestring
return compat.to_native(s) | def calc_base64(s):
"""Return base64 encoded binarystring."""
s = compat.to_bytes(s)
s = compat.base64_encodebytes(s).strip() # return bytestring
return compat.to_native(s) | [
"Return",
"base64",
"encoded",
"binarystring",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L949-L953 | [
"def",
"calc_base64",
"(",
"s",
")",
":",
"s",
"=",
"compat",
".",
"to_bytes",
"(",
"s",
")",
"s",
"=",
"compat",
".",
"base64_encodebytes",
"(",
"s",
")",
".",
"strip",
"(",
")",
"# return bytestring",
"return",
"compat",
".",
"to_native",
"(",
"s",
... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | get_etag | Return a strong Entity Tag for a (file)path.
http://www.webdav.org/specs/rfc4918.html#etag
Returns the following as entity tags::
Non-file - md5(pathname)
Win32 - md5(pathname)-lastmodifiedtime-filesize
Others - inode-lastmodifiedtime-filesize | wsgidav/util.py | def get_etag(file_path):
"""Return a strong Entity Tag for a (file)path.
http://www.webdav.org/specs/rfc4918.html#etag
Returns the following as entity tags::
Non-file - md5(pathname)
Win32 - md5(pathname)-lastmodifiedtime-filesize
Others - inode-lastmodifiedtime-filesize
"""
... | def get_etag(file_path):
"""Return a strong Entity Tag for a (file)path.
http://www.webdav.org/specs/rfc4918.html#etag
Returns the following as entity tags::
Non-file - md5(pathname)
Win32 - md5(pathname)-lastmodifiedtime-filesize
Others - inode-lastmodifiedtime-filesize
"""
... | [
"Return",
"a",
"strong",
"Entity",
"Tag",
"for",
"a",
"(",
"file",
")",
"path",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L956-L996 | [
"def",
"get_etag",
"(",
"file_path",
")",
":",
"# (At least on Vista) os.path.exists returns False, if a file name contains",
"# special characters, even if it is correctly UTF-8 encoded.",
"# So we convert to unicode. On the other hand, md5() needs a byte string.",
"if",
"compat",
".",
"is_... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | obtain_content_ranges | returns tuple (list, value)
list
content ranges as values to their parsed components in the tuple
(seek_position/abs position of first byte, abs position of last byte, num_of_bytes_to_read)
value
total length for Content-Length | wsgidav/util.py | def obtain_content_ranges(rangetext, filesize):
"""
returns tuple (list, value)
list
content ranges as values to their parsed components in the tuple
(seek_position/abs position of first byte, abs position of last byte, num_of_bytes_to_read)
value
total length for Content-Length
""... | def obtain_content_ranges(rangetext, filesize):
"""
returns tuple (list, value)
list
content ranges as values to their parsed components in the tuple
(seek_position/abs position of first byte, abs position of last byte, num_of_bytes_to_read)
value
total length for Content-Length
""... | [
"returns",
"tuple",
"(",
"list",
"value",
")"
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L1010-L1067 | [
"def",
"obtain_content_ranges",
"(",
"rangetext",
",",
"filesize",
")",
":",
"listReturn",
"=",
"[",
"]",
"seqRanges",
"=",
"rangetext",
".",
"split",
"(",
"\",\"",
")",
"for",
"subrange",
"in",
"seqRanges",
":",
"matched",
"=",
"False",
"if",
"not",
"matc... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | read_timeout_value_header | Return -1 if infinite, else return numofsecs. | wsgidav/util.py | def read_timeout_value_header(timeoutvalue):
"""Return -1 if infinite, else return numofsecs."""
timeoutsecs = 0
timeoutvaluelist = timeoutvalue.split(",")
for timeoutspec in timeoutvaluelist:
timeoutspec = timeoutspec.strip()
if timeoutspec.lower() == "infinite":
return -1
... | def read_timeout_value_header(timeoutvalue):
"""Return -1 if infinite, else return numofsecs."""
timeoutsecs = 0
timeoutvaluelist = timeoutvalue.split(",")
for timeoutspec in timeoutvaluelist:
timeoutspec = timeoutspec.strip()
if timeoutspec.lower() == "infinite":
return -1
... | [
"Return",
"-",
"1",
"if",
"infinite",
"else",
"return",
"numofsecs",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L1079-L1095 | [
"def",
"read_timeout_value_header",
"(",
"timeoutvalue",
")",
":",
"timeoutsecs",
"=",
"0",
"timeoutvaluelist",
"=",
"timeoutvalue",
".",
"split",
"(",
"\",\"",
")",
"for",
"timeoutspec",
"in",
"timeoutvaluelist",
":",
"timeoutspec",
"=",
"timeoutspec",
".",
"stri... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | evaluate_http_conditionals | Handle 'If-...:' headers (but not 'If:' header).
If-Match
@see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.24
Only perform the action if the client supplied entity matches the
same entity on the server. This is mainly for methods like
PUT to only update a resource ... | wsgidav/util.py | def evaluate_http_conditionals(dav_res, last_modified, entitytag, environ):
"""Handle 'If-...:' headers (but not 'If:' header).
If-Match
@see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.24
Only perform the action if the client supplied entity matches the
same entity on... | def evaluate_http_conditionals(dav_res, last_modified, entitytag, environ):
"""Handle 'If-...:' headers (but not 'If:' header).
If-Match
@see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.24
Only perform the action if the client supplied entity matches the
same entity on... | [
"Handle",
"If",
"-",
"...",
":",
"headers",
"(",
"but",
"not",
"If",
":",
"header",
")",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L1103-L1185 | [
"def",
"evaluate_http_conditionals",
"(",
"dav_res",
",",
"last_modified",
",",
"entitytag",
",",
"environ",
")",
":",
"if",
"not",
"dav_res",
":",
"return",
"# Conditions",
"# An HTTP/1.1 origin server, upon receiving a conditional request that includes both a",
"# Last-Modifi... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | parse_if_header_dict | Parse HTTP_IF header into a dictionary and lists, and cache the result.
@see http://www.webdav.org/specs/rfc4918.html#HEADER_If | wsgidav/util.py | def parse_if_header_dict(environ):
"""Parse HTTP_IF header into a dictionary and lists, and cache the result.
@see http://www.webdav.org/specs/rfc4918.html#HEADER_If
"""
if "wsgidav.conditions.if" in environ:
return
if "HTTP_IF" not in environ:
environ["wsgidav.conditions.if"] = No... | def parse_if_header_dict(environ):
"""Parse HTTP_IF header into a dictionary and lists, and cache the result.
@see http://www.webdav.org/specs/rfc4918.html#HEADER_If
"""
if "wsgidav.conditions.if" in environ:
return
if "HTTP_IF" not in environ:
environ["wsgidav.conditions.if"] = No... | [
"Parse",
"HTTP_IF",
"header",
"into",
"a",
"dictionary",
"and",
"lists",
"and",
"cache",
"the",
"result",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L1194-L1246 | [
"def",
"parse_if_header_dict",
"(",
"environ",
")",
":",
"if",
"\"wsgidav.conditions.if\"",
"in",
"environ",
":",
"return",
"if",
"\"HTTP_IF\"",
"not",
"in",
"environ",
":",
"environ",
"[",
"\"wsgidav.conditions.if\"",
"]",
"=",
"None",
"environ",
"[",
"\"wsgidav.... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | guess_mime_type | Use the mimetypes module to lookup the type for an extension.
This function also adds some extensions required for HTML5 | wsgidav/util.py | def guess_mime_type(url):
"""Use the mimetypes module to lookup the type for an extension.
This function also adds some extensions required for HTML5
"""
(mimetype, _mimeencoding) = mimetypes.guess_type(url)
if not mimetype:
ext = os.path.splitext(url)[1]
mimetype = _MIME_TYPES.get(... | def guess_mime_type(url):
"""Use the mimetypes module to lookup the type for an extension.
This function also adds some extensions required for HTML5
"""
(mimetype, _mimeencoding) = mimetypes.guess_type(url)
if not mimetype:
ext = os.path.splitext(url)[1]
mimetype = _MIME_TYPES.get(... | [
"Use",
"the",
"mimetypes",
"module",
"to",
"lookup",
"the",
"type",
"for",
"an",
"extension",
"."
] | mar10/wsgidav | python | https://github.com/mar10/wsgidav/blob/cec0d84222fc24bea01be1cea91729001963f172/wsgidav/util.py#L1299-L1311 | [
"def",
"guess_mime_type",
"(",
"url",
")",
":",
"(",
"mimetype",
",",
"_mimeencoding",
")",
"=",
"mimetypes",
".",
"guess_type",
"(",
"url",
")",
"if",
"not",
"mimetype",
":",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"url",
")",
"[",
"1",... | cec0d84222fc24bea01be1cea91729001963f172 |
valid | Group.add_members | Add objects to the group.
Parameters
----------
new_members : list
A list of cobrapy objects to add to the group. | cobra/core/group.py | def add_members(self, new_members):
"""
Add objects to the group.
Parameters
----------
new_members : list
A list of cobrapy objects to add to the group.
"""
if isinstance(new_members, string_types) or \
hasattr(new_members, "id"):
... | def add_members(self, new_members):
"""
Add objects to the group.
Parameters
----------
new_members : list
A list of cobrapy objects to add to the group.
"""
if isinstance(new_members, string_types) or \
hasattr(new_members, "id"):
... | [
"Add",
"objects",
"to",
"the",
"group",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/group.py#L79-L95 | [
"def",
"add_members",
"(",
"self",
",",
"new_members",
")",
":",
"if",
"isinstance",
"(",
"new_members",
",",
"string_types",
")",
"or",
"hasattr",
"(",
"new_members",
",",
"\"id\"",
")",
":",
"warn",
"(",
"\"need to pass in a list\"",
")",
"new_members",
"=",... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | Group.remove_members | Remove objects from the group.
Parameters
----------
to_remove : list
A list of cobra objects to remove from the group | cobra/core/group.py | def remove_members(self, to_remove):
"""
Remove objects from the group.
Parameters
----------
to_remove : list
A list of cobra objects to remove from the group
"""
if isinstance(to_remove, string_types) or \
hasattr(to_remove, "id"):
... | def remove_members(self, to_remove):
"""
Remove objects from the group.
Parameters
----------
to_remove : list
A list of cobra objects to remove from the group
"""
if isinstance(to_remove, string_types) or \
hasattr(to_remove, "id"):
... | [
"Remove",
"objects",
"from",
"the",
"group",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/group.py#L97-L112 | [
"def",
"remove_members",
"(",
"self",
",",
"to_remove",
")",
":",
"if",
"isinstance",
"(",
"to_remove",
",",
"string_types",
")",
"or",
"hasattr",
"(",
"to_remove",
",",
"\"id\"",
")",
":",
"warn",
"(",
"\"need to pass in a list\"",
")",
"to_remove",
"=",
"[... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | geometric_fba | Perform geometric FBA to obtain a unique, centered flux distribution.
Geometric FBA [1]_ formulates the problem as a polyhedron and
then solves it by bounding the convex hull of the polyhedron.
The bounding forms a box around the convex hull which reduces
with every iteration and extracts a unique solu... | cobra/flux_analysis/geometric.py | def geometric_fba(model, epsilon=1E-06, max_tries=200, processes=None):
"""
Perform geometric FBA to obtain a unique, centered flux distribution.
Geometric FBA [1]_ formulates the problem as a polyhedron and
then solves it by bounding the convex hull of the polyhedron.
The bounding forms a box arou... | def geometric_fba(model, epsilon=1E-06, max_tries=200, processes=None):
"""
Perform geometric FBA to obtain a unique, centered flux distribution.
Geometric FBA [1]_ formulates the problem as a polyhedron and
then solves it by bounding the convex hull of the polyhedron.
The bounding forms a box arou... | [
"Perform",
"geometric",
"FBA",
"to",
"obtain",
"a",
"unique",
"centered",
"flux",
"distribution",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/flux_analysis/geometric.py#L18-L121 | [
"def",
"geometric_fba",
"(",
"model",
",",
"epsilon",
"=",
"1E-06",
",",
"max_tries",
"=",
"200",
",",
"processes",
"=",
"None",
")",
":",
"with",
"model",
":",
"# Variables' and constraints' storage variables.",
"consts",
"=",
"[",
"]",
"obj_vars",
"=",
"[",
... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList._generate_index | rebuild the _dict index | cobra/core/dictlist.py | def _generate_index(self):
"""rebuild the _dict index"""
self._dict = {v.id: k for k, v in enumerate(self)} | def _generate_index(self):
"""rebuild the _dict index"""
self._dict = {v.id: k for k, v in enumerate(self)} | [
"rebuild",
"the",
"_dict",
"index"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L52-L54 | [
"def",
"_generate_index",
"(",
"self",
")",
":",
"self",
".",
"_dict",
"=",
"{",
"v",
".",
"id",
":",
"k",
"for",
"k",
",",
"v",
"in",
"enumerate",
"(",
"self",
")",
"}"
] | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.get_by_any | Get a list of members using several different ways of indexing
Parameters
----------
iterable : list (if not, turned into single element list)
list where each element is either int (referring to an index in
in this DictList), string (a id of a member in this DictList) or... | cobra/core/dictlist.py | def get_by_any(self, iterable):
"""
Get a list of members using several different ways of indexing
Parameters
----------
iterable : list (if not, turned into single element list)
list where each element is either int (referring to an index in
in this Dict... | def get_by_any(self, iterable):
"""
Get a list of members using several different ways of indexing
Parameters
----------
iterable : list (if not, turned into single element list)
list where each element is either int (referring to an index in
in this Dict... | [
"Get",
"a",
"list",
"of",
"members",
"using",
"several",
"different",
"ways",
"of",
"indexing"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L64-L92 | [
"def",
"get_by_any",
"(",
"self",
",",
"iterable",
")",
":",
"def",
"get_item",
"(",
"item",
")",
":",
"if",
"isinstance",
"(",
"item",
",",
"int",
")",
":",
"return",
"self",
"[",
"item",
"]",
"elif",
"isinstance",
"(",
"item",
",",
"string_types",
... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.query | Query the list
Parameters
----------
search_function : a string, regular expression or function
Used to find the matching elements in the list.
- a regular expression (possibly compiled), in which case the
given attribute of the object should match the regula... | cobra/core/dictlist.py | def query(self, search_function, attribute=None):
"""Query the list
Parameters
----------
search_function : a string, regular expression or function
Used to find the matching elements in the list.
- a regular expression (possibly compiled), in which case the
... | def query(self, search_function, attribute=None):
"""Query the list
Parameters
----------
search_function : a string, regular expression or function
Used to find the matching elements in the list.
- a regular expression (possibly compiled), in which case the
... | [
"Query",
"the",
"list"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L94-L151 | [
"def",
"query",
"(",
"self",
",",
"search_function",
",",
"attribute",
"=",
"None",
")",
":",
"def",
"select_attribute",
"(",
"x",
")",
":",
"if",
"attribute",
"is",
"None",
":",
"return",
"x",
"else",
":",
"return",
"getattr",
"(",
"x",
",",
"attribut... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList._replace_on_id | Replace an object by another with the same id. | cobra/core/dictlist.py | def _replace_on_id(self, new_object):
"""Replace an object by another with the same id."""
the_id = new_object.id
the_index = self._dict[the_id]
list.__setitem__(self, the_index, new_object) | def _replace_on_id(self, new_object):
"""Replace an object by another with the same id."""
the_id = new_object.id
the_index = self._dict[the_id]
list.__setitem__(self, the_index, new_object) | [
"Replace",
"an",
"object",
"by",
"another",
"with",
"the",
"same",
"id",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L153-L157 | [
"def",
"_replace_on_id",
"(",
"self",
",",
"new_object",
")",
":",
"the_id",
"=",
"new_object",
".",
"id",
"the_index",
"=",
"self",
".",
"_dict",
"[",
"the_id",
"]",
"list",
".",
"__setitem__",
"(",
"self",
",",
"the_index",
",",
"new_object",
")"
] | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.append | append object to end | cobra/core/dictlist.py | def append(self, object):
"""append object to end"""
the_id = object.id
self._check(the_id)
self._dict[the_id] = len(self)
list.append(self, object) | def append(self, object):
"""append object to end"""
the_id = object.id
self._check(the_id)
self._dict[the_id] = len(self)
list.append(self, object) | [
"append",
"object",
"to",
"end"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L160-L165 | [
"def",
"append",
"(",
"self",
",",
"object",
")",
":",
"the_id",
"=",
"object",
".",
"id",
"self",
".",
"_check",
"(",
"the_id",
")",
"self",
".",
"_dict",
"[",
"the_id",
"]",
"=",
"len",
"(",
"self",
")",
"list",
".",
"append",
"(",
"self",
",",... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.union | adds elements with id's not already in the model | cobra/core/dictlist.py | def union(self, iterable):
"""adds elements with id's not already in the model"""
_dict = self._dict
append = self.append
for i in iterable:
if i.id not in _dict:
append(i) | def union(self, iterable):
"""adds elements with id's not already in the model"""
_dict = self._dict
append = self.append
for i in iterable:
if i.id not in _dict:
append(i) | [
"adds",
"elements",
"with",
"id",
"s",
"not",
"already",
"in",
"the",
"model"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L167-L173 | [
"def",
"union",
"(",
"self",
",",
"iterable",
")",
":",
"_dict",
"=",
"self",
".",
"_dict",
"append",
"=",
"self",
".",
"append",
"for",
"i",
"in",
"iterable",
":",
"if",
"i",
".",
"id",
"not",
"in",
"_dict",
":",
"append",
"(",
"i",
")"
] | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.extend | extend list by appending elements from the iterable | cobra/core/dictlist.py | def extend(self, iterable):
"""extend list by appending elements from the iterable"""
# Sometimes during initialization from an older pickle, _dict
# will not have initialized yet, because the initialization class was
# left unspecified. This is an issue because unpickling calls
... | def extend(self, iterable):
"""extend list by appending elements from the iterable"""
# Sometimes during initialization from an older pickle, _dict
# will not have initialized yet, because the initialization class was
# left unspecified. This is an issue because unpickling calls
... | [
"extend",
"list",
"by",
"appending",
"elements",
"from",
"the",
"iterable"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L175-L199 | [
"def",
"extend",
"(",
"self",
",",
"iterable",
")",
":",
"# Sometimes during initialization from an older pickle, _dict",
"# will not have initialized yet, because the initialization class was",
"# left unspecified. This is an issue because unpickling calls",
"# DictList.extend, which requires... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList._extend_nocheck | extends without checking for uniqueness
This function should only be used internally by DictList when it
can guarantee elements are already unique (as in when coming from
self or other DictList). It will be faster because it skips these
checks. | cobra/core/dictlist.py | def _extend_nocheck(self, iterable):
"""extends without checking for uniqueness
This function should only be used internally by DictList when it
can guarantee elements are already unique (as in when coming from
self or other DictList). It will be faster because it skips these
ch... | def _extend_nocheck(self, iterable):
"""extends without checking for uniqueness
This function should only be used internally by DictList when it
can guarantee elements are already unique (as in when coming from
self or other DictList). It will be faster because it skips these
ch... | [
"extends",
"without",
"checking",
"for",
"uniqueness"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L201-L218 | [
"def",
"_extend_nocheck",
"(",
"self",
",",
"iterable",
")",
":",
"current_length",
"=",
"len",
"(",
"self",
")",
"list",
".",
"extend",
"(",
"self",
",",
"iterable",
")",
"_dict",
"=",
"self",
".",
"_dict",
"if",
"current_length",
"is",
"0",
":",
"sel... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.index | Determine the position in the list
id: A string or a :class:`~cobra.core.Object.Object` | cobra/core/dictlist.py | def index(self, id, *args):
"""Determine the position in the list
id: A string or a :class:`~cobra.core.Object.Object`
"""
# because values are unique, start and stop are not relevant
if isinstance(id, string_types):
try:
return self._dict[id]
... | def index(self, id, *args):
"""Determine the position in the list
id: A string or a :class:`~cobra.core.Object.Object`
"""
# because values are unique, start and stop are not relevant
if isinstance(id, string_types):
try:
return self._dict[id]
... | [
"Determine",
"the",
"position",
"in",
"the",
"list"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L294-L313 | [
"def",
"index",
"(",
"self",
",",
"id",
",",
"*",
"args",
")",
":",
"# because values are unique, start and stop are not relevant",
"if",
"isinstance",
"(",
"id",
",",
"string_types",
")",
":",
"try",
":",
"return",
"self",
".",
"_dict",
"[",
"id",
"]",
"exc... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.insert | insert object before index | cobra/core/dictlist.py | def insert(self, index, object):
"""insert object before index"""
self._check(object.id)
list.insert(self, index, object)
# all subsequent entries now have been shifted up by 1
_dict = self._dict
for i, j in iteritems(_dict):
if j >= index:
_di... | def insert(self, index, object):
"""insert object before index"""
self._check(object.id)
list.insert(self, index, object)
# all subsequent entries now have been shifted up by 1
_dict = self._dict
for i, j in iteritems(_dict):
if j >= index:
_di... | [
"insert",
"object",
"before",
"index"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L334-L343 | [
"def",
"insert",
"(",
"self",
",",
"index",
",",
"object",
")",
":",
"self",
".",
"_check",
"(",
"object",
".",
"id",
")",
"list",
".",
"insert",
"(",
"self",
",",
"index",
",",
"object",
")",
"# all subsequent entries now have been shifted up by 1",
"_dict"... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.pop | remove and return item at index (default last). | cobra/core/dictlist.py | def pop(self, *args):
"""remove and return item at index (default last)."""
value = list.pop(self, *args)
index = self._dict.pop(value.id)
# If the pop occured from a location other than the end of the list,
# we will need to subtract 1 from every entry afterwards
if len(... | def pop(self, *args):
"""remove and return item at index (default last)."""
value = list.pop(self, *args)
index = self._dict.pop(value.id)
# If the pop occured from a location other than the end of the list,
# we will need to subtract 1 from every entry afterwards
if len(... | [
"remove",
"and",
"return",
"item",
"at",
"index",
"(",
"default",
"last",
")",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L345-L357 | [
"def",
"pop",
"(",
"self",
",",
"*",
"args",
")",
":",
"value",
"=",
"list",
".",
"pop",
"(",
"self",
",",
"*",
"args",
")",
"index",
"=",
"self",
".",
"_dict",
".",
"pop",
"(",
"value",
".",
"id",
")",
"# If the pop occured from a location other than ... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | DictList.sort | stable sort *IN PLACE*
cmp(x, y) -> -1, 0, 1 | cobra/core/dictlist.py | def sort(self, cmp=None, key=None, reverse=False):
"""stable sort *IN PLACE*
cmp(x, y) -> -1, 0, 1
"""
if key is None:
def key(i):
return i.id
if PY3:
list.sort(self, key=key, reverse=reverse)
else:
list.sort(self, cmp... | def sort(self, cmp=None, key=None, reverse=False):
"""stable sort *IN PLACE*
cmp(x, y) -> -1, 0, 1
"""
if key is None:
def key(i):
return i.id
if PY3:
list.sort(self, key=key, reverse=reverse)
else:
list.sort(self, cmp... | [
"stable",
"sort",
"*",
"IN",
"PLACE",
"*"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/dictlist.py#L375-L388 | [
"def",
"sort",
"(",
"self",
",",
"cmp",
"=",
"None",
",",
"key",
"=",
"None",
",",
"reverse",
"=",
"False",
")",
":",
"if",
"key",
"is",
"None",
":",
"def",
"key",
"(",
"i",
")",
":",
"return",
"i",
".",
"id",
"if",
"PY3",
":",
"list",
".",
... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | Metabolite.elements | Dictionary of elements as keys and their count in the metabolite
as integer. When set, the `formula` property is update accordingly | cobra/core/metabolite.py | def elements(self):
""" Dictionary of elements as keys and their count in the metabolite
as integer. When set, the `formula` property is update accordingly """
tmp_formula = self.formula
if tmp_formula is None:
return {}
# necessary for some old pickles which use the ... | def elements(self):
""" Dictionary of elements as keys and their count in the metabolite
as integer. When set, the `formula` property is update accordingly """
tmp_formula = self.formula
if tmp_formula is None:
return {}
# necessary for some old pickles which use the ... | [
"Dictionary",
"of",
"elements",
"as",
"keys",
"and",
"their",
"count",
"in",
"the",
"metabolite",
"as",
"integer",
".",
"When",
"set",
"the",
"formula",
"property",
"is",
"update",
"accordingly"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/metabolite.py#L73-L111 | [
"def",
"elements",
"(",
"self",
")",
":",
"tmp_formula",
"=",
"self",
".",
"formula",
"if",
"tmp_formula",
"is",
"None",
":",
"return",
"{",
"}",
"# necessary for some old pickles which use the deprecated",
"# Formula class",
"tmp_formula",
"=",
"str",
"(",
"self",
... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | Metabolite.shadow_price | The shadow price in the most recent solution.
Shadow price is the dual value of the corresponding constraint in the
model.
Warnings
--------
* Accessing shadow prices through a `Solution` object is the safer,
preferred, and only guaranteed to be correct way. You can s... | cobra/core/metabolite.py | def shadow_price(self):
"""
The shadow price in the most recent solution.
Shadow price is the dual value of the corresponding constraint in the
model.
Warnings
--------
* Accessing shadow prices through a `Solution` object is the safer,
preferred, and ... | def shadow_price(self):
"""
The shadow price in the most recent solution.
Shadow price is the dual value of the corresponding constraint in the
model.
Warnings
--------
* Accessing shadow prices through a `Solution` object is the safer,
preferred, and ... | [
"The",
"shadow",
"price",
"in",
"the",
"most",
"recent",
"solution",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/core/metabolite.py#L142-L193 | [
"def",
"shadow_price",
"(",
"self",
")",
":",
"try",
":",
"check_solver_status",
"(",
"self",
".",
"_model",
".",
"solver",
".",
"status",
")",
"return",
"self",
".",
"_model",
".",
"constraints",
"[",
"self",
".",
"id",
"]",
".",
"dual",
"except",
"At... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | to_yaml | Return the model as a YAML document.
``kwargs`` are passed on to ``yaml.dump``.
Parameters
----------
model : cobra.Model
The cobra model to represent.
sort : bool, optional
Whether to sort the metabolites, reactions, and genes or maintain the
order defined in the model.
... | cobra/io/yaml.py | def to_yaml(model, sort=False, **kwargs):
"""
Return the model as a YAML document.
``kwargs`` are passed on to ``yaml.dump``.
Parameters
----------
model : cobra.Model
The cobra model to represent.
sort : bool, optional
Whether to sort the metabolites, reactions, and genes ... | def to_yaml(model, sort=False, **kwargs):
"""
Return the model as a YAML document.
``kwargs`` are passed on to ``yaml.dump``.
Parameters
----------
model : cobra.Model
The cobra model to represent.
sort : bool, optional
Whether to sort the metabolites, reactions, and genes ... | [
"Return",
"the",
"model",
"as",
"a",
"YAML",
"document",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/io/yaml.py#L31-L58 | [
"def",
"to_yaml",
"(",
"model",
",",
"sort",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"obj",
"=",
"model_to_dict",
"(",
"model",
",",
"sort",
"=",
"sort",
")",
"obj",
"[",
"\"version\"",
"]",
"=",
"YAML_SPEC",
"return",
"yaml",
".",
"dump",
... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | save_yaml_model | Write the cobra model to a file in YAML format.
``kwargs`` are passed on to ``yaml.dump``.
Parameters
----------
model : cobra.Model
The cobra model to represent.
filename : str or file-like
File path or descriptor that the YAML representation should be
written to.
sort... | cobra/io/yaml.py | def save_yaml_model(model, filename, sort=False, **kwargs):
"""
Write the cobra model to a file in YAML format.
``kwargs`` are passed on to ``yaml.dump``.
Parameters
----------
model : cobra.Model
The cobra model to represent.
filename : str or file-like
File path or descri... | def save_yaml_model(model, filename, sort=False, **kwargs):
"""
Write the cobra model to a file in YAML format.
``kwargs`` are passed on to ``yaml.dump``.
Parameters
----------
model : cobra.Model
The cobra model to represent.
filename : str or file-like
File path or descri... | [
"Write",
"the",
"cobra",
"model",
"to",
"a",
"file",
"in",
"YAML",
"format",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/io/yaml.py#L83-L111 | [
"def",
"save_yaml_model",
"(",
"model",
",",
"filename",
",",
"sort",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"obj",
"=",
"model_to_dict",
"(",
"model",
",",
"sort",
"=",
"sort",
")",
"obj",
"[",
"\"version\"",
"]",
"=",
"YAML_SPEC",
"if",
"... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | load_yaml_model | Load a cobra model from a file in YAML format.
Parameters
----------
filename : str or file-like
File path or descriptor that contains the YAML document describing the
cobra model.
Returns
-------
cobra.Model
The cobra model as represented in the YAML document.
See... | cobra/io/yaml.py | def load_yaml_model(filename):
"""
Load a cobra model from a file in YAML format.
Parameters
----------
filename : str or file-like
File path or descriptor that contains the YAML document describing the
cobra model.
Returns
-------
cobra.Model
The cobra model as... | def load_yaml_model(filename):
"""
Load a cobra model from a file in YAML format.
Parameters
----------
filename : str or file-like
File path or descriptor that contains the YAML document describing the
cobra model.
Returns
-------
cobra.Model
The cobra model as... | [
"Load",
"a",
"cobra",
"model",
"from",
"a",
"file",
"in",
"YAML",
"format",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/io/yaml.py#L114-L137 | [
"def",
"load_yaml_model",
"(",
"filename",
")",
":",
"if",
"isinstance",
"(",
"filename",
",",
"string_types",
")",
":",
"with",
"io",
".",
"open",
"(",
"filename",
",",
"\"r\"",
")",
"as",
"file_handle",
":",
"return",
"model_from_dict",
"(",
"yaml",
".",... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | pfba | Perform basic pFBA (parsimonious Enzyme Usage Flux Balance Analysis)
to minimize total flux.
pFBA [1] adds the minimization of all fluxes the the objective of the
model. This approach is motivated by the idea that high fluxes have a
higher enzyme turn-over and that since producing enzymes is costly,
... | cobra/flux_analysis/parsimonious.py | def pfba(model, fraction_of_optimum=1.0, objective=None, reactions=None):
"""Perform basic pFBA (parsimonious Enzyme Usage Flux Balance Analysis)
to minimize total flux.
pFBA [1] adds the minimization of all fluxes the the objective of the
model. This approach is motivated by the idea that high fluxes ... | def pfba(model, fraction_of_optimum=1.0, objective=None, reactions=None):
"""Perform basic pFBA (parsimonious Enzyme Usage Flux Balance Analysis)
to minimize total flux.
pFBA [1] adds the minimization of all fluxes the the objective of the
model. This approach is motivated by the idea that high fluxes ... | [
"Perform",
"basic",
"pFBA",
"(",
"parsimonious",
"Enzyme",
"Usage",
"Flux",
"Balance",
"Analysis",
")",
"to",
"minimize",
"total",
"flux",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/flux_analysis/parsimonious.py#L23-L71 | [
"def",
"pfba",
"(",
"model",
",",
"fraction_of_optimum",
"=",
"1.0",
",",
"objective",
"=",
"None",
",",
"reactions",
"=",
"None",
")",
":",
"reactions",
"=",
"model",
".",
"reactions",
"if",
"reactions",
"is",
"None",
"else",
"model",
".",
"reactions",
... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | add_pfba | Add pFBA objective
Add objective to minimize the summed flux of all reactions to the
current objective.
See Also
-------
pfba
Parameters
----------
model : cobra.Model
The model to add the objective to
objective :
An objective to set in combination with the pFBA ob... | cobra/flux_analysis/parsimonious.py | def add_pfba(model, objective=None, fraction_of_optimum=1.0):
"""Add pFBA objective
Add objective to minimize the summed flux of all reactions to the
current objective.
See Also
-------
pfba
Parameters
----------
model : cobra.Model
The model to add the objective to
ob... | def add_pfba(model, objective=None, fraction_of_optimum=1.0):
"""Add pFBA objective
Add objective to minimize the summed flux of all reactions to the
current objective.
See Also
-------
pfba
Parameters
----------
model : cobra.Model
The model to add the objective to
ob... | [
"Add",
"pFBA",
"objective"
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/flux_analysis/parsimonious.py#L74-L105 | [
"def",
"add_pfba",
"(",
"model",
",",
"objective",
"=",
"None",
",",
"fraction_of_optimum",
"=",
"1.0",
")",
":",
"if",
"objective",
"is",
"not",
"None",
":",
"model",
".",
"objective",
"=",
"objective",
"if",
"model",
".",
"solver",
".",
"objective",
".... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | metabolite_summary | Print a summary of the production and consumption fluxes.
This method requires the model for which this metabolite is a part
to be solved.
Parameters
----------
solution : cobra.Solution, optional
A previously solved model solution to use for generating the
summary. If none provide... | cobra/flux_analysis/summary.py | def metabolite_summary(met, solution=None, threshold=0.01, fva=False,
names=False, floatfmt='.3g'):
"""
Print a summary of the production and consumption fluxes.
This method requires the model for which this metabolite is a part
to be solved.
Parameters
----------
so... | def metabolite_summary(met, solution=None, threshold=0.01, fva=False,
names=False, floatfmt='.3g'):
"""
Print a summary of the production and consumption fluxes.
This method requires the model for which this metabolite is a part
to be solved.
Parameters
----------
so... | [
"Print",
"a",
"summary",
"of",
"the",
"production",
"and",
"consumption",
"fluxes",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/flux_analysis/summary.py#L23-L144 | [
"def",
"metabolite_summary",
"(",
"met",
",",
"solution",
"=",
"None",
",",
"threshold",
"=",
"0.01",
",",
"fva",
"=",
"False",
",",
"names",
"=",
"False",
",",
"floatfmt",
"=",
"'.3g'",
")",
":",
"if",
"names",
":",
"emit",
"=",
"attrgetter",
"(",
"... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | model_summary | Print a summary of the input and output fluxes of the model.
Parameters
----------
solution: cobra.Solution, optional
A previously solved model solution to use for generating the
summary. If none provided (default), the summary method will
resolve the model. Note that the solution o... | cobra/flux_analysis/summary.py | def model_summary(model, solution=None, threshold=0.01, fva=None, names=False,
floatfmt='.3g'):
"""
Print a summary of the input and output fluxes of the model.
Parameters
----------
solution: cobra.Solution, optional
A previously solved model solution to use for generatin... | def model_summary(model, solution=None, threshold=0.01, fva=None, names=False,
floatfmt='.3g'):
"""
Print a summary of the input and output fluxes of the model.
Parameters
----------
solution: cobra.Solution, optional
A previously solved model solution to use for generatin... | [
"Print",
"a",
"summary",
"of",
"the",
"input",
"and",
"output",
"fluxes",
"of",
"the",
"model",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/flux_analysis/summary.py#L147-L257 | [
"def",
"model_summary",
"(",
"model",
",",
"solution",
"=",
"None",
",",
"threshold",
"=",
"0.01",
",",
"fva",
"=",
"None",
",",
"names",
"=",
"False",
",",
"floatfmt",
"=",
"'.3g'",
")",
":",
"if",
"names",
":",
"emit",
"=",
"attrgetter",
"(",
"'nam... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | _process_flux_dataframe | Some common methods for processing a database of flux information into
print-ready formats. Used in both model_summary and metabolite_summary. | cobra/flux_analysis/summary.py | def _process_flux_dataframe(flux_dataframe, fva, threshold, floatfmt):
"""Some common methods for processing a database of flux information into
print-ready formats. Used in both model_summary and metabolite_summary. """
abs_flux = flux_dataframe['flux'].abs()
flux_threshold = threshold * abs_flux.max(... | def _process_flux_dataframe(flux_dataframe, fva, threshold, floatfmt):
"""Some common methods for processing a database of flux information into
print-ready formats. Used in both model_summary and metabolite_summary. """
abs_flux = flux_dataframe['flux'].abs()
flux_threshold = threshold * abs_flux.max(... | [
"Some",
"common",
"methods",
"for",
"processing",
"a",
"database",
"of",
"flux",
"information",
"into",
"print",
"-",
"ready",
"formats",
".",
"Used",
"in",
"both",
"model_summary",
"and",
"metabolite_summary",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/flux_analysis/summary.py#L260-L329 | [
"def",
"_process_flux_dataframe",
"(",
"flux_dataframe",
",",
"fva",
",",
"threshold",
",",
"floatfmt",
")",
":",
"abs_flux",
"=",
"flux_dataframe",
"[",
"'flux'",
"]",
".",
"abs",
"(",
")",
"flux_threshold",
"=",
"threshold",
"*",
"abs_flux",
".",
"max",
"(... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | linear_reaction_coefficients | Coefficient for the reactions in a linear objective.
Parameters
----------
model : cobra model
the model object that defined the objective
reactions : list
an optional list for the reactions to get the coefficients for. All
reactions if left missing.
Returns
-------
... | cobra/util/solver.py | def linear_reaction_coefficients(model, reactions=None):
"""Coefficient for the reactions in a linear objective.
Parameters
----------
model : cobra model
the model object that defined the objective
reactions : list
an optional list for the reactions to get the coefficients for. All... | def linear_reaction_coefficients(model, reactions=None):
"""Coefficient for the reactions in a linear objective.
Parameters
----------
model : cobra model
the model object that defined the objective
reactions : list
an optional list for the reactions to get the coefficients for. All... | [
"Coefficient",
"for",
"the",
"reactions",
"in",
"a",
"linear",
"objective",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/util/solver.py#L45-L76 | [
"def",
"linear_reaction_coefficients",
"(",
"model",
",",
"reactions",
"=",
"None",
")",
":",
"linear_coefficients",
"=",
"{",
"}",
"reactions",
"=",
"model",
".",
"reactions",
"if",
"not",
"reactions",
"else",
"reactions",
"try",
":",
"objective_expression",
"=... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | _valid_atoms | Check whether a sympy expression references the correct variables.
Parameters
----------
model : cobra.Model
The model in which to check for variables.
expression : sympy.Basic
A sympy expression.
Returns
-------
boolean
True if all referenced variables are containe... | cobra/util/solver.py | def _valid_atoms(model, expression):
"""Check whether a sympy expression references the correct variables.
Parameters
----------
model : cobra.Model
The model in which to check for variables.
expression : sympy.Basic
A sympy expression.
Returns
-------
boolean
T... | def _valid_atoms(model, expression):
"""Check whether a sympy expression references the correct variables.
Parameters
----------
model : cobra.Model
The model in which to check for variables.
expression : sympy.Basic
A sympy expression.
Returns
-------
boolean
T... | [
"Check",
"whether",
"a",
"sympy",
"expression",
"references",
"the",
"correct",
"variables",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/util/solver.py#L79-L96 | [
"def",
"_valid_atoms",
"(",
"model",
",",
"expression",
")",
":",
"atoms",
"=",
"expression",
".",
"atoms",
"(",
"optlang",
".",
"interface",
".",
"Variable",
")",
"return",
"all",
"(",
"a",
".",
"problem",
"is",
"model",
".",
"solver",
"for",
"a",
"in... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | set_objective | Set the model objective.
Parameters
----------
model : cobra model
The model to set the objective for
value : model.problem.Objective,
e.g. optlang.glpk_interface.Objective, sympy.Basic or dict
If the model objective is linear, the value can be a new Objective
object... | cobra/util/solver.py | def set_objective(model, value, additive=False):
"""Set the model objective.
Parameters
----------
model : cobra model
The model to set the objective for
value : model.problem.Objective,
e.g. optlang.glpk_interface.Objective, sympy.Basic or dict
If the model objective is... | def set_objective(model, value, additive=False):
"""Set the model objective.
Parameters
----------
model : cobra model
The model to set the objective for
value : model.problem.Objective,
e.g. optlang.glpk_interface.Objective, sympy.Basic or dict
If the model objective is... | [
"Set",
"the",
"model",
"objective",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/util/solver.py#L99-L165 | [
"def",
"set_objective",
"(",
"model",
",",
"value",
",",
"additive",
"=",
"False",
")",
":",
"interface",
"=",
"model",
".",
"problem",
"reverse_value",
"=",
"model",
".",
"solver",
".",
"objective",
".",
"expression",
"reverse_value",
"=",
"interface",
".",... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | interface_to_str | Give a string representation for an optlang interface.
Parameters
----------
interface : string, ModuleType
Full name of the interface in optlang or cobra representation.
For instance 'optlang.glpk_interface' or 'optlang-glpk'.
Returns
-------
string
The name of the inte... | cobra/util/solver.py | def interface_to_str(interface):
"""Give a string representation for an optlang interface.
Parameters
----------
interface : string, ModuleType
Full name of the interface in optlang or cobra representation.
For instance 'optlang.glpk_interface' or 'optlang-glpk'.
Returns
------... | def interface_to_str(interface):
"""Give a string representation for an optlang interface.
Parameters
----------
interface : string, ModuleType
Full name of the interface in optlang or cobra representation.
For instance 'optlang.glpk_interface' or 'optlang-glpk'.
Returns
------... | [
"Give",
"a",
"string",
"representation",
"for",
"an",
"optlang",
"interface",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/util/solver.py#L168-L184 | [
"def",
"interface_to_str",
"(",
"interface",
")",
":",
"if",
"isinstance",
"(",
"interface",
",",
"ModuleType",
")",
":",
"interface",
"=",
"interface",
".",
"__name__",
"return",
"re",
".",
"sub",
"(",
"r\"optlang.|.interface\"",
",",
"\"\"",
",",
"interface"... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | get_solver_name | Select a solver for a given optimization problem.
Parameters
----------
mip : bool
Does the solver require mixed integer linear programming capabilities?
qp : bool
Does the solver require quadratic programming capabilities?
Returns
-------
string
The name of feasibl... | cobra/util/solver.py | def get_solver_name(mip=False, qp=False):
"""Select a solver for a given optimization problem.
Parameters
----------
mip : bool
Does the solver require mixed integer linear programming capabilities?
qp : bool
Does the solver require quadratic programming capabilities?
Returns
... | def get_solver_name(mip=False, qp=False):
"""Select a solver for a given optimization problem.
Parameters
----------
mip : bool
Does the solver require mixed integer linear programming capabilities?
qp : bool
Does the solver require quadratic programming capabilities?
Returns
... | [
"Select",
"a",
"solver",
"for",
"a",
"given",
"optimization",
"problem",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/util/solver.py#L187-L229 | [
"def",
"get_solver_name",
"(",
"mip",
"=",
"False",
",",
"qp",
"=",
"False",
")",
":",
"if",
"len",
"(",
"solvers",
")",
"==",
"0",
":",
"raise",
"SolverNotFound",
"(",
"\"no solvers installed\"",
")",
"# Those lists need to be updated as optlang implements more sol... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | choose_solver | Choose a solver given a solver name and model.
This will choose a solver compatible with the model and required
capabilities. Also respects model.solver where it can.
Parameters
----------
model : a cobra model
The model for which to choose the solver.
solver : str, optional
Th... | cobra/util/solver.py | def choose_solver(model, solver=None, qp=False):
"""Choose a solver given a solver name and model.
This will choose a solver compatible with the model and required
capabilities. Also respects model.solver where it can.
Parameters
----------
model : a cobra model
The model for which to ... | def choose_solver(model, solver=None, qp=False):
"""Choose a solver given a solver name and model.
This will choose a solver compatible with the model and required
capabilities. Also respects model.solver where it can.
Parameters
----------
model : a cobra model
The model for which to ... | [
"Choose",
"a",
"solver",
"given",
"a",
"solver",
"name",
"and",
"model",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/util/solver.py#L232-L266 | [
"def",
"choose_solver",
"(",
"model",
",",
"solver",
"=",
"None",
",",
"qp",
"=",
"False",
")",
":",
"if",
"solver",
"is",
"None",
":",
"solver",
"=",
"model",
".",
"problem",
"else",
":",
"model",
".",
"solver",
"=",
"solver",
"# Check for QP, raise err... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | add_cons_vars_to_problem | Add variables and constraints to a Model's solver object.
Useful for variables and constraints that can not be expressed with
reactions and lower/upper bounds. Will integrate with the Model's context
manager in order to revert changes upon leaving the context.
Parameters
----------
model : a c... | cobra/util/solver.py | def add_cons_vars_to_problem(model, what, **kwargs):
"""Add variables and constraints to a Model's solver object.
Useful for variables and constraints that can not be expressed with
reactions and lower/upper bounds. Will integrate with the Model's context
manager in order to revert changes upon leaving... | def add_cons_vars_to_problem(model, what, **kwargs):
"""Add variables and constraints to a Model's solver object.
Useful for variables and constraints that can not be expressed with
reactions and lower/upper bounds. Will integrate with the Model's context
manager in order to revert changes upon leaving... | [
"Add",
"variables",
"and",
"constraints",
"to",
"a",
"Model",
"s",
"solver",
"object",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/util/solver.py#L269-L291 | [
"def",
"add_cons_vars_to_problem",
"(",
"model",
",",
"what",
",",
"*",
"*",
"kwargs",
")",
":",
"context",
"=",
"get_context",
"(",
"model",
")",
"model",
".",
"solver",
".",
"add",
"(",
"what",
",",
"*",
"*",
"kwargs",
")",
"if",
"context",
":",
"c... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
valid | remove_cons_vars_from_problem | Remove variables and constraints from a Model's solver object.
Useful to temporarily remove variables and constraints from a Models's
solver object.
Parameters
----------
model : a cobra model
The model from which to remove the variables and constraints.
what : list or tuple of optlang ... | cobra/util/solver.py | def remove_cons_vars_from_problem(model, what):
"""Remove variables and constraints from a Model's solver object.
Useful to temporarily remove variables and constraints from a Models's
solver object.
Parameters
----------
model : a cobra model
The model from which to remove the variable... | def remove_cons_vars_from_problem(model, what):
"""Remove variables and constraints from a Model's solver object.
Useful to temporarily remove variables and constraints from a Models's
solver object.
Parameters
----------
model : a cobra model
The model from which to remove the variable... | [
"Remove",
"variables",
"and",
"constraints",
"from",
"a",
"Model",
"s",
"solver",
"object",
"."
] | opencobra/cobrapy | python | https://github.com/opencobra/cobrapy/blob/9d1987cdb3a395cf4125a3439c3b002ff2be2009/cobra/util/solver.py#L294-L313 | [
"def",
"remove_cons_vars_from_problem",
"(",
"model",
",",
"what",
")",
":",
"context",
"=",
"get_context",
"(",
"model",
")",
"model",
".",
"solver",
".",
"remove",
"(",
"what",
")",
"if",
"context",
":",
"context",
"(",
"partial",
"(",
"model",
".",
"s... | 9d1987cdb3a395cf4125a3439c3b002ff2be2009 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.