signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def __init__(self, agent_interface_format=None, map_size=None): | if not agent_interface_format:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self._agent_interface_format = agent_interface_format<EOL>aif = self._agent_interface_format<EOL>if (aif.use_feature_units<EOL>or aif.use_camera_position<EOL>or aif.use_raw_units):<EOL><INDENT>self.init_camera(<EOL>aif.feature_dimensio... | Initialize a Features instance matching the specified interface format.
Args:
agent_interface_format: See the documentation for `AgentInterfaceFormat`.
map_size: The size of the map in world units, needed for feature_units.
Raises:
ValueError: if agent_interface_format is... | f1614:c18:m0 |
def init_camera(<EOL>self, feature_dimensions, map_size, camera_width_world_units): | if not map_size or not camera_width_world_units:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>map_size = point.Point.build(map_size)<EOL>self._world_to_world_tl = transform.Linear(point.Point(<NUM_LIT:1>, -<NUM_LIT:1>),<EOL>point.Point(<NUM_LIT:0>, map_size.y))<EOL>self._wo... | Initialize the camera (especially for feature_units).
This is called in the constructor and may be called repeatedly after
`Features` is constructed, since it deals with rescaling coordinates and not
changing environment/action specs.
Args:
feature_dimensions: See the documen... | f1614:c18:m1 |
def _update_camera(self, camera_center): | self._world_tl_to_world_camera_rel.offset = (<EOL>-self._world_to_world_tl.fwd_pt(camera_center) *<EOL>self._world_tl_to_world_camera_rel.scale)<EOL> | Update the camera transform based on the new camera center. | f1614:c18:m2 |
def observation_spec(self): | obs_spec = named_array.NamedDict({<EOL>"<STR_LIT>": (<NUM_LIT:0>,), <EOL>"<STR_LIT>": (<NUM_LIT:0>,), <EOL>"<STR_LIT>": (<NUM_LIT:0>,),<EOL>"<STR_LIT>": (<NUM_LIT:0>, len(UnitLayer)), <EOL>"<STR_LIT>": (<NUM_LIT:0>, len(UnitLayer)), <EOL>"<STR_LIT>": (<NUM_LIT:1>,),<EOL>"<STR_LIT>": (<NUM_LIT:10>, <NUM_LIT:2>),<EOL... | The observation spec for the SC2 environment.
It's worth noting that the image-like observations are in y,x/row,column
order which is different than the actions which are in x,y order. This is
due to conflicting conventions, and to facilitate printing of the images.
Returns:
... | f1614:c18:m3 |
def action_spec(self): | return self._valid_functions<EOL> | The action space pretty complicated and fills the ValidFunctions. | f1614:c18:m4 |
@sw.decorate<EOL><INDENT>def transform_obs(self, obs):<DEDENT> | empty = np.array([], dtype=np.int32).reshape((<NUM_LIT:0>, <NUM_LIT:7>))<EOL>out = named_array.NamedDict({ <EOL>"<STR_LIT>": empty,<EOL>"<STR_LIT>": empty,<EOL>"<STR_LIT>": empty,<EOL>"<STR_LIT>": empty,<EOL>"<STR_LIT>": np.array([<NUM_LIT:0>], dtype=np.int32),<EOL>})<EOL>def or_zeros(layer, size):<EOL><INDENT>if laye... | Render some SC2 observations into something an agent can handle. | f1614:c18:m5 |
@sw.decorate<EOL><INDENT>def available_actions(self, obs):<DEDENT> | available_actions = set()<EOL>hide_specific_actions = self._agent_interface_format.hide_specific_actions<EOL>for i, func in six.iteritems(actions.FUNCTIONS_AVAILABLE):<EOL><INDENT>if func.avail_fn(obs):<EOL><INDENT>available_actions.add(i)<EOL><DEDENT><DEDENT>for a in obs.abilities:<EOL><INDENT>if a.ability_id not in a... | Return the list of available action ids. | f1614:c18:m6 |
@sw.decorate<EOL><INDENT>def transform_action(self, obs, func_call, skip_available=False):<DEDENT> | func_id = func_call.function<EOL>try:<EOL><INDENT>func = actions.FUNCTIONS[func_id]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>" % func_id)<EOL><DEDENT>if not (skip_available or func_id in self.available_actions(obs)):<EOL><INDENT>raise ValueError("<STR_LIT>" % (<EOL>func_id, func.name))<EOL><D... | Tranform an agent-style action to one that SC2 can consume.
Args:
obs: a `sc_pb.Observation` from the previous frame.
func_call: a `FunctionCall` to be turned into a `sc_pb.Action`.
skip_available: If True, assume the action is available. This should only
be used for... | f1614:c18:m7 |
@sw.decorate<EOL><INDENT>def reverse_action(self, action):<DEDENT> | FUNCTIONS = actions.FUNCTIONS <EOL>aif = self._agent_interface_format<EOL>def func_call_ability(ability_id, cmd_type, *args):<EOL><INDENT>"""<STR_LIT>"""<EOL>if ability_id not in actions.ABILITY_IDS:<EOL><INDENT>logging.warning("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>", ability_id)<EOL>return FUNCTIONS.no_op()<EOL><... | Transform an SC2-style action into an agent-style action.
This should be the inverse of `transform_action`.
Args:
action: a `sc_pb.Action` to be transformed.
Returns:
A corresponding `actions.FunctionCall`.
Raises:
ValueError: if it doesn't know how to t... | f1614:c18:m8 |
def run(self, funcs): | funcs = [f if callable(f) else functools.partial(*f) for f in funcs]<EOL>if len(funcs) == <NUM_LIT:1>: <EOL><INDENT>return [funcs[<NUM_LIT:0>]()]<EOL><DEDENT>if len(funcs) > self._workers: <EOL><INDENT>self.shutdown()<EOL>self._workers = len(funcs)<EOL>self._executor = futures.ThreadPoolExecutor(self._workers)<EOL><D... | Run a set of functions in parallel, returning their results.
Make sure any function you pass exits with a reasonable timeout. If it
doesn't return within the timeout or the result is ignored due an exception
in a separate thread it will continue to stick around until it finishes,
includ... | f1615:c0:m1 |
def DEFINE_point(name, default, help): | flags.DEFINE(PointParser(), name, default, help)<EOL> | Registers a flag whose value parses as a point. | f1616:m0 |
def clean(): | for build_dir in list(BUILD_DIRS) + [DOC_OUTPUT, DEV_DB_DIR]:<EOL><INDENT>local("<STR_LIT>" % build_dir)<EOL><DEDENT> | Clean build files. | f1620:m0 |
@contextmanager<EOL>def _dist_wrapper(): | try:<EOL><INDENT>for rst_file, txt_file in zip(SDIST_RST_FILES, SDIST_TXT_FILES):<EOL><INDENT>local("<STR_LIT>" % (rst_file, txt_file))<EOL><DEDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>for rst_file in SDIST_TXT_FILES:<EOL><INDENT>local("<STR_LIT>" % rst_file, capture=False)<EOL><DEDENT><DEDENT> | Add temporary distribution build files (and then clean up). | f1620:m1 |
def sdist(): | with _dist_wrapper():<EOL><INDENT>local("<STR_LIT>", capture=False)<EOL><DEDENT> | Package into distribution. | f1620:m2 |
def register(): | with _dist_wrapper():<EOL><INDENT>local("<STR_LIT>", capture=False)<EOL><DEDENT> | Register and prep user for PyPi upload.
.. note:: May need to tweak ~/.pypirc file per issue:
http://stackoverflow.com/questions/1569315 | f1620:m3 |
def upload(): | with _dist_wrapper():<EOL><INDENT>local("<STR_LIT>", capture=False)<EOL><DEDENT> | Upload package. | f1620:m4 |
def pylint(rcfile=PYLINT_CFG): | <EOL>local("<STR_LIT>" %<EOL>(rcfile, "<STR_LIT:U+0020>".join(CHECK_INCLUDES)), capture=False)<EOL> | Run pylint style checker.
:param rcfile: PyLint configuration file. | f1620:m5 |
def check(): | <EOL>pylint()<EOL> | Run all checkers. | f1620:m6 |
def _parse_bool(value): | if isinstance(value, bool):<EOL><INDENT>return value<EOL><DEDENT>elif isinstance(value, str):<EOL><INDENT>if value == '<STR_LIT:True>':<EOL><INDENT>return True<EOL><DEDENT>elif value == '<STR_LIT:False>':<EOL><INDENT>return False<EOL><DEDENT><DEDENT>raise Exception("<STR_LIT>" % value)<EOL> | Convert ``string`` or ``bool`` to ``bool``. | f1620:m7 |
def docs(output=DOC_OUTPUT, proj_settings=PROJ_SETTINGS, github=False): | local("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (proj_settings, DOC_INPUT, output),<EOL>capture=False)<EOL>if _parse_bool(github):<EOL><INDENT>local("<STR_LIT>" % output, capture=False)<EOL><DEDENT> | Generate API documentation (using Sphinx).
:param output: Output directory.
:param proj_settings: Django project settings to use.
:param github: Convert to GitHub-friendly format? | f1620:m8 |
def _manage(target, extra='<STR_LIT>', proj_settings=PROJ_SETTINGS): | local("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" %<EOL>(proj_settings, target, extra),<EOL>capture=False)<EOL> | Generic wrapper for ``django-admin.py``. | f1620:m9 |
def syncdb(proj_settings=PROJ_SETTINGS): | local("<STR_LIT>" % DEV_DB_DIR)<EOL>_manage("<STR_LIT>", proj_settings=proj_settings)<EOL> | Run syncdb. | f1620:m10 |
def run_server(addr="<STR_LIT>", proj_settings=PROJ_SETTINGS): | _manage("<STR_LIT>", addr, proj_settings)<EOL> | Run Django dev. server. | f1620:m11 |
@classmethod<EOL><INDENT>def from_settings(cls):<DEDENT> | from cloud_browser.app_settings import settings<EOL>from django.core.exceptions import ImproperlyConfigured<EOL>conn_cls = conn_fn = None<EOL>datastore = settings.CLOUD_BROWSER_DATASTORE<EOL>if datastore == '<STR_LIT>':<EOL><INDENT>from cloud_browser.cloud.aws import AwsConnection<EOL>account = settings.CLOUD_BROWSER_A... | Create configuration from Django settings or environment. | f1622:c0:m0 |
@classmethod<EOL><INDENT>def get_connection_cls(cls):<DEDENT> | if cls.__connection_cls is None:<EOL><INDENT>cls.__connection_cls, _ = cls.from_settings()<EOL><DEDENT>return cls.__connection_cls<EOL> | Return connection class.
:rtype: :class:`type` | f1622:c0:m1 |
@classmethod<EOL><INDENT>def get_connection(cls):<DEDENT> | if cls.__connection_obj is None:<EOL><INDENT>if cls.__connection_fn is None:<EOL><INDENT>_, cls.__connection_fn = cls.from_settings()<EOL><DEDENT>cls.__connection_obj = cls.__connection_fn()<EOL><DEDENT>return cls.__connection_obj<EOL> | Return connection object.
:rtype: :class:`cloud_browser.cloud.base.CloudConnection` | f1622:c0:m2 |
@classmethod<EOL><INDENT>@requires(cloudfiles, '<STR_LIT>')<EOL>def lazy_translations(cls):<DEDENT> | return {<EOL>cloudfiles.errors.NoSuchContainer: errors.NoContainerException,<EOL>cloudfiles.errors.NoSuchObject: errors.NoObjectException,<EOL>}<EOL> | Lazy translations. | f1623:c0:m0 |
@wrap_rs_errors<EOL><INDENT>def _get_object(self):<DEDENT> | return self.container.native_container.get_object(self.name)<EOL> | Return native storage object. | f1623:c1:m0 |
@wrap_rs_errors<EOL><INDENT>def _read(self):<DEDENT> | return self.native_obj.read()<EOL> | Return contents of object. | f1623:c1:m1 |
@classmethod<EOL><INDENT>def from_info(cls, container, info_obj):<DEDENT> | create_fn = cls.from_subdir if '<STR_LIT>' in info_objelse cls.from_file_info<EOL>return create_fn(container, info_obj)<EOL> | Create from subdirectory or file info object. | f1623:c1:m2 |
@classmethod<EOL><INDENT>def from_subdir(cls, container, info_obj):<DEDENT> | return cls(container,<EOL>info_obj['<STR_LIT>'],<EOL>obj_type=cls.type_cls.SUBDIR)<EOL> | Create from subdirectory info object. | f1623:c1:m3 |
@classmethod<EOL><INDENT>def choose_type(cls, content_type):<DEDENT> | return cls.type_cls.SUBDIR if content_type in cls.subdir_typeselse cls.type_cls.FILE<EOL> | Choose object type from content type. | f1623:c1:m4 |
@classmethod<EOL><INDENT>def from_file_info(cls, container, info_obj):<DEDENT> | <EOL>return cls(container,<EOL>name=info_obj['<STR_LIT:name>'],<EOL>size=info_obj['<STR_LIT>'],<EOL>content_type=info_obj['<STR_LIT>'],<EOL>last_modified=dt_from_header(info_obj['<STR_LIT>']),<EOL>obj_type=cls.choose_type(info_obj['<STR_LIT>']))<EOL> | Create from regular info object. | f1623:c1:m5 |
@classmethod<EOL><INDENT>def from_obj(cls, container, file_obj):<DEDENT> | <EOL>return cls(container,<EOL>name=file_obj.name,<EOL>size=file_obj.size,<EOL>content_type=file_obj.content_type,<EOL>last_modified=dt_from_header(file_obj.last_modified),<EOL>obj_type=cls.choose_type(file_obj.content_type))<EOL> | Create from regular info object. | f1623:c1:m6 |
@wrap_rs_errors<EOL><INDENT>def _get_container(self):<DEDENT> | return self.conn.native_conn.get_container(self.name)<EOL> | Return native container object. | f1623:c2:m0 |
@wrap_rs_errors<EOL><INDENT>def get_objects(self, path, marker=None,<EOL>limit=settings.CLOUD_BROWSER_DEFAULT_LIST_LIMIT):<DEDENT> | object_infos, full_query = self._get_object_infos(path, marker, limit)<EOL>if full_query and len(object_infos) < limit:<EOL><INDENT>object_infos, _ = self._get_object_infos(path, marker, <NUM_LIT:2> * limit)<EOL>object_infos = object_infos[:limit]<EOL><DEDENT>return [self.obj_cls.from_info(self, x) for x in object_info... | Get objects.
**Pseudo-directory Notes**: Rackspace has two approaches to pseudo-
directories within the (really) flat storage object namespace:
1. Dummy directory storage objects. These are real storage objects
of type "application/directory" and must be manually uploaded
... | f1623:c2:m1 |
@wrap_rs_errors<EOL><INDENT>def _get_object_infos(self, path, marker=None,<EOL>limit=settings.CLOUD_BROWSER_DEFAULT_LIST_LIMIT):<DEDENT> | <EOL>orig_limit = limit<EOL>limit += <NUM_LIT:1><EOL>if limit > RS_MAX_LIST_OBJECTS_LIMIT:<EOL><INDENT>raise errors.CloudException("<STR_LIT>" %<EOL>RS_MAX_LIST_OBJECTS_LIMIT)<EOL><DEDENT>def _collapse(infos):<EOL><INDENT>"""<STR_LIT>"""<EOL>name = None<EOL>for info in infos:<EOL><INDENT>name = info.get('<STR_LIT:name>... | Get raw object infos (single-shot). | f1623:c2:m2 |
@wrap_rs_errors<EOL><INDENT>def get_object(self, path):<DEDENT> | obj = self.native_container.get_object(path)<EOL>return self.obj_cls.from_obj(self, obj)<EOL> | Get single object. | f1623:c2:m3 |
def __init__(self, account, secret_key, servicenet=False, authurl=None): | super(RackspaceConnection, self).__init__(account, secret_key)<EOL>self.servicenet = servicenet<EOL>self.authurl = authurl<EOL> | Initializer. | f1623:c3:m0 |
@wrap_rs_errors<EOL><INDENT>@requires(cloudfiles, '<STR_LIT>')<EOL>def _get_connection(self):<DEDENT> | kwargs = {<EOL>'<STR_LIT:username>': self.account,<EOL>'<STR_LIT>': self.secret_key,<EOL>}<EOL>if self.servicenet:<EOL><INDENT>kwargs['<STR_LIT>'] = True<EOL><DEDENT>if self.authurl:<EOL><INDENT>kwargs['<STR_LIT>'] = self.authurl<EOL><DEDENT>return cloudfiles.get_connection(**kwargs)<EOL> | Return native connection object. | f1623:c3:m1 |
@wrap_rs_errors<EOL><INDENT>def _get_containers(self):<DEDENT> | infos = self.native_conn.list_containers_info()<EOL>return [self.cont_cls(self, i['<STR_LIT:name>'], i['<STR_LIT:count>'], i['<STR_LIT>'])<EOL>for i in infos]<EOL> | Return available containers. | f1623:c3:m2 |
@wrap_rs_errors<EOL><INDENT>def _get_container(self, path):<DEDENT> | cont = self.native_conn.get_container(path)<EOL>return self.cont_cls(self,<EOL>cont.name,<EOL>cont.object_count,<EOL>cont.size_used)<EOL> | Return single container. | f1623:c3:m3 |
def __new__(cls, *args, **kwargs): | obj = object.__new__(cls, *args, **kwargs)<EOL>if not obj.translations:<EOL><INDENT>lazy_translations = cls.lazy_translations()<EOL>if lazy_translations:<EOL><INDENT>obj.translations = lazy_translations<EOL><DEDENT><DEDENT>return obj<EOL> | New. | f1624:c5:m0 |
@classmethod<EOL><INDENT>def excepts(cls):<DEDENT> | if cls._excepts is None:<EOL><INDENT>cls._excepts = tuple(cls.translations.keys())<EOL><DEDENT>return cls._excepts<EOL> | Return tuple of underlying exception classes to trap and wrap.
:rtype: ``tuple`` of ``type`` | f1624:c5:m1 |
def translate(self, exc): | <EOL>for key in self.translations.keys():<EOL><INDENT>if isinstance(exc, key):<EOL><INDENT>return self.translations[key](str(exc))<EOL><DEDENT><DEDENT>return None<EOL> | Return translation of exception to new class.
Calling code should only raise exception if exception class is passed
in, else ``None`` (which signifies no wrapping should be done). | f1624:c5:m2 |
def __call__(self, operation): | @wraps(operation)<EOL>def wrapped(*args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>return operation(*args, **kwargs)<EOL><DEDENT>except self.excepts() as exc:<EOL><INDENT>new_exc = self.translate(exc)<EOL>if new_exc:<EOL><INDENT>raise new_exc.__class__(new_exc, sys.exc_info()[<NUM_LIT:2>])<EOL><DEDENT... | Call and wrap exceptions. | f1624:c5:m3 |
@classmethod<EOL><INDENT>def lazy_translations(cls):<DEDENT> | return None<EOL> | Lazy translations definitions (for additional checks). | f1624:c5:m4 |
@classmethod<EOL><INDENT>def _is_gs_folder(cls, result):<DEDENT> | return (cls.is_key(result) and<EOL>result.size == <NUM_LIT:0> and<EOL>result.name.endswith(cls._gs_folder_suffix))<EOL> | Return ``True`` if GS standalone folder object.
GS will create a 0 byte ``<FOLDER NAME>_$folder$`` key as a
pseudo-directory place holder if there are no files present. | f1625:c0:m0 |
@classmethod<EOL><INDENT>@requires(boto, '<STR_LIT>')<EOL>def is_key(cls, result):<DEDENT> | from boto.gs.key import Key<EOL>return isinstance(result, Key)<EOL> | Return ``True`` if result is a key object. | f1625:c0:m1 |
@classmethod<EOL><INDENT>@requires(boto, '<STR_LIT>')<EOL>def is_prefix(cls, result):<DEDENT> | from boto.s3.prefix import Prefix<EOL>return isinstance(result, Prefix) or cls._is_gs_folder(result)<EOL> | Return ``True`` if result is a prefix object.
.. note::
Boto uses the S3 Prefix object for GS prefixes. | f1625:c0:m2 |
@classmethod<EOL><INDENT>def from_prefix(cls, container, prefix):<DEDENT> | if cls._is_gs_folder(prefix):<EOL><INDENT>name, suffix, extra = prefix.name.partition(cls._gs_folder_suffix)<EOL>if (suffix, extra) == (cls._gs_folder_suffix, '<STR_LIT>'):<EOL><INDENT>prefix.name = name<EOL><DEDENT><DEDENT>return super(GsObject, cls).from_prefix(container, prefix)<EOL> | Create from prefix object. | f1625:c0:m3 |
def get_objects(self, path, marker=None,<EOL>limit=settings.CLOUD_BROWSER_DEFAULT_LIST_LIMIT): | <EOL>folder = path.split(SEP)[-<NUM_LIT:1>]<EOL>objs = super(GsContainer, self).get_objects(path, marker, limit + <NUM_LIT:1>)<EOL>objs = [o for o in objs if not (o.size == <NUM_LIT:0> and o.name == folder)]<EOL>return objs[:limit]<EOL> | Get objects.
Certain upload clients may add a 0-byte object (e.g., ``FOLDER`` object
for path ``path/to/FOLDER`` - ``path/to/FOLDER/FOLDER``). We add an
extra +1 limit query and ignore any such file objects. | f1625:c1:m0 |
@base.BotoConnection.wrap_boto_errors<EOL><INDENT>@requires(boto, '<STR_LIT>')<EOL>def _get_connection(self):<DEDENT> | return boto.connect_gs(self.account, self.secret_key)<EOL> | Return native connection object. | f1625:c2:m0 |
@classmethod<EOL><INDENT>@requires(boto, '<STR_LIT>')<EOL>def is_key(cls, result):<DEDENT> | from boto.s3.key import Key<EOL>return isinstance(result, Key)<EOL> | Return ``True`` if result is a key object. | f1626:c0:m0 |
@classmethod<EOL><INDENT>@requires(boto, '<STR_LIT>')<EOL>def is_prefix(cls, result):<DEDENT> | from boto.s3.prefix import Prefix<EOL>return isinstance(result, Prefix)<EOL> | Return ``True`` if result is a prefix object. | f1626:c0:m1 |
@base.BotoConnection.wrap_boto_errors<EOL><INDENT>@requires(boto, '<STR_LIT>')<EOL>def _get_connection(self):<DEDENT> | return boto.connect_s3(self.account, self.secret_key)<EOL> | Return native connection object. | f1626:c2:m0 |
def __init__(self, container, name, **kwargs): | self.container = container<EOL>self.name = name.rstrip(SEP)<EOL>self.size = kwargs.get('<STR_LIT:size>', <NUM_LIT:0>)<EOL>self.content_type = kwargs.get('<STR_LIT>', '<STR_LIT>')<EOL>self.content_encoding = kwargs.get('<STR_LIT>', '<STR_LIT>')<EOL>self.last_modified = kwargs.get('<STR_LIT>', None)<EOL>self.type = kwarg... | Initializer.
:param container: Container object.
:param name: Object name / path.
:kwarg size: Number of bytes in object.
:kwarg content_type: Document 'content-type'.
:kwarg content_encoding: Document 'content-encoding'.
:kwarg last_modified: Last modified date.
... | f1627:c1:m0 |
@property<EOL><INDENT>def native_obj(self):<DEDENT> | if self.__native is None:<EOL><INDENT>self.__native = self._get_object()<EOL><DEDENT>return self.__native<EOL> | Native storage object. | f1627:c1:m1 |
def _get_object(self): | raise NotImplementedError<EOL> | Return native storage object. | f1627:c1:m2 |
@property<EOL><INDENT>def is_subdir(self):<DEDENT> | return self.type == self.type_cls.SUBDIR<EOL> | Is a subdirectory? | f1627:c1:m3 |
@property<EOL><INDENT>def is_file(self):<DEDENT> | return self.type == self.type_cls.FILE<EOL> | Is a file object? | f1627:c1:m4 |
@property<EOL><INDENT>def path(self):<DEDENT> | return path_join(self.container.name, self.name)<EOL> | Full path (including container). | f1627:c1:m5 |
@property<EOL><INDENT>def basename(self):<DEDENT> | return basename(self.name)<EOL> | Base name from rightmost separator. | f1627:c1:m6 |
@property<EOL><INDENT>def smart_content_type(self):<DEDENT> | content_type = self.content_type<EOL>if content_type in (None, '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>content_type, _ = mimetypes.guess_type(self.name)<EOL><DEDENT>return content_type<EOL> | Smart content type. | f1627:c1:m7 |
@property<EOL><INDENT>def smart_content_encoding(self):<DEDENT> | encoding = self.content_encoding<EOL>if not encoding:<EOL><INDENT>base_list = self.basename.split('<STR_LIT:.>')<EOL>while (not encoding) and len(base_list) > <NUM_LIT:1>:<EOL><INDENT>_, encoding = mimetypes.guess_type('<STR_LIT:.>'.join(base_list))<EOL>base_list.pop()<EOL><DEDENT><DEDENT>return encoding<EOL> | Smart content encoding. | f1627:c1:m8 |
def read(self): | return self._read()<EOL> | Return contents of object. | f1627:c1:m9 |
def _read(self): | raise NotImplementedError<EOL> | Return contents of object. | f1627:c1:m10 |
def __init__(self, conn, name=None, count=None, size=None): | self.conn = conn<EOL>self.name = name<EOL>self.count = count<EOL>self.size = size<EOL>self.__native = None<EOL> | Initializer. | f1627:c2:m0 |
@property<EOL><INDENT>def native_container(self):<DEDENT> | if self.__native is None:<EOL><INDENT>self.__native = self._get_container()<EOL><DEDENT>return self.__native<EOL> | Native container object. | f1627:c2:m1 |
def _get_container(self): | raise NotImplementedError<EOL> | Return native container object. | f1627:c2:m2 |
def get_objects(self, path, marker=None,<EOL>limit=settings.CLOUD_BROWSER_DEFAULT_LIST_LIMIT): | raise NotImplementedError<EOL> | Get objects. | f1627:c2:m3 |
def get_object(self, path): | raise NotImplementedError<EOL> | Get single object. | f1627:c2:m4 |
def __init__(self, account, secret_key): | self.account = account<EOL>self.secret_key = secret_key<EOL>self.__native = None<EOL> | Initializer. | f1627:c3:m0 |
@property<EOL><INDENT>def native_conn(self):<DEDENT> | if self.__native is None:<EOL><INDENT>self.__native = self._get_connection()<EOL><DEDENT>return self.__native<EOL> | Native connection object. | f1627:c3:m1 |
def _get_connection(self): | raise NotImplementedError<EOL> | Return native connection object. | f1627:c3:m2 |
def get_containers(self): | permitted = lambda c: settings.container_permitted(c.name)<EOL>return [c for c in self._get_containers() if permitted(c)]<EOL> | Return available containers. | f1627:c3:m3 |
def _get_containers(self): | raise NotImplementedError<EOL> | Return available containers. | f1627:c3:m4 |
def get_container(self, path): | if not settings.container_permitted(path):<EOL><INDENT>raise errors.NotPermittedException(<EOL>"<STR_LIT>" % path)<EOL><DEDENT>return self._get_container(path)<EOL> | Return single container. | f1627:c3:m5 |
def _get_container(self, path): | raise NotImplementedError<EOL> | Return single container. | f1627:c3:m6 |
def get_connection(): | from cloud_browser.cloud.config import Config<EOL>return Config.get_connection()<EOL> | Return global connection object.
:rtype: :class:`cloud_browser.cloud.base.CloudConnection` | f1628:m0 |
def get_connection_cls(): | from cloud_browser.cloud.config import Config<EOL>return Config.get_connection_cls()<EOL> | Return global connection class.
:rtype: :class:`type` | f1628:m1 |
def not_dot(path): | return NO_DOT_RE.match(os.path.basename(path))<EOL> | Check if non-dot. | f1629:m0 |
def is_dir(path): | return not_dot(path) and os.path.isdir(path)<EOL> | Check if non-dot and directory. | f1629:m1 |
def _get_object(self): | return object()<EOL> | Return native storage object. | f1629:c2:m0 |
def _read(self): | with open(self.base_path, '<STR_LIT:rb>') as file_obj:<EOL><INDENT>return file_obj.read()<EOL><DEDENT> | Return contents of object. | f1629:c2:m1 |
@property<EOL><INDENT>def base_path(self):<DEDENT> | return os.path.join(self.container.base_path, self.name)<EOL> | Base absolute path of container. | f1629:c2:m2 |
@classmethod<EOL><INDENT>def from_path(cls, container, path):<DEDENT> | from datetime import datetime<EOL>path = path.strip(SEP)<EOL>full_path = os.path.join(container.base_path, path)<EOL>last_modified = datetime.fromtimestamp(os.path.getmtime(full_path))<EOL>obj_type = cls.type_cls.SUBDIR if is_dir(full_path)else cls.type_cls.FILE<EOL>return cls(container,<EOL>name=path,<EOL>size=os.path... | Create object from path. | f1629:c2:m3 |
def _get_container(self): | return object()<EOL> | Return native container object. | f1629:c3:m0 |
@wrap_fs_obj_errors<EOL><INDENT>def get_objects(self, path, marker=None,<EOL>limit=settings.CLOUD_BROWSER_DEFAULT_LIST_LIMIT):<DEDENT> | def _filter(name):<EOL><INDENT>"""<STR_LIT>"""<EOL>return (not_dot(name) and<EOL>(marker is None or<EOL>os.path.join(path, name).strip(SEP) > marker.strip(SEP)))<EOL><DEDENT>search_path = os.path.join(self.base_path, path)<EOL>objs = [self.obj_cls.from_path(self, os.path.join(path, o))<EOL>for o in os.listdir(search_pa... | Get objects. | f1629:c3:m1 |
@wrap_fs_obj_errors<EOL><INDENT>def get_object(self, path):<DEDENT> | return self.obj_cls.from_path(self, path)<EOL> | Get single object. | f1629:c3:m2 |
@property<EOL><INDENT>def base_path(self):<DEDENT> | return os.path.join(self.conn.abs_root, self.name)<EOL> | Base absolute path of container. | f1629:c3:m3 |
@classmethod<EOL><INDENT>def from_path(cls, conn, path):<DEDENT> | path = path.strip(SEP)<EOL>full_path = os.path.join(conn.abs_root, path)<EOL>return cls(conn, path, <NUM_LIT:0>, os.path.getsize(full_path))<EOL> | Create container from path. | f1629:c3:m4 |
def __init__(self, root): | super(FilesystemConnection, self).__init__(None, None)<EOL>self.root = root<EOL>self.abs_root = os.path.abspath(root)<EOL> | Initializer. | f1629:c4:m0 |
def _get_connection(self): | return object()<EOL> | Return native connection object. | f1629:c4:m1 |
@wrap_fs_cont_errors<EOL><INDENT>def _get_containers(self):<DEDENT> | def full_fn(path):<EOL><INDENT>return os.path.join(self.abs_root, path)<EOL><DEDENT>return [self.cont_cls.from_path(self, d)<EOL>for d in os.listdir(self.abs_root) if is_dir(full_fn(d))]<EOL> | Return available containers. | f1629:c4:m2 |
@wrap_fs_cont_errors<EOL><INDENT>def _get_container(self, path):<DEDENT> | path = path.strip(SEP)<EOL>if SEP in path:<EOL><INDENT>raise errors.InvalidNameException(<EOL>"<STR_LIT>" % (SEP, path))<EOL><DEDENT>return self.cont_cls.from_path(self, path)<EOL> | Return single container. | f1629:c4:m3 |
@requires(boto, '<STR_LIT>')<EOL><INDENT>def translate(self, exc):<DEDENT> | from boto.exception import StorageResponseError<EOL>if isinstance(exc, StorageResponseError):<EOL><INDENT>if exc.status == <NUM_LIT>:<EOL><INDENT>return self.error_cls(str(exc))<EOL><DEDENT><DEDENT>return None<EOL> | Return whether or not to do translation. | f1630:c0:m0 |
@classmethod<EOL><INDENT>def is_key(cls, result):<DEDENT> | raise NotImplementedError<EOL> | Return ``True`` if result is a key object. | f1630:c3:m0 |
@classmethod<EOL><INDENT>def is_prefix(cls, result):<DEDENT> | raise NotImplementedError<EOL> | Return ``True`` if result is a prefix object. | f1630:c3:m1 |
@wrap_boto_errors<EOL><INDENT>def _get_object(self):<DEDENT> | return self.container.native_container.get_key(self.name)<EOL> | Return native storage object. | f1630:c3:m2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.