text:
'''
This file contains all the utilities needed for escaping and parsing
names in the syntax of

    project-ID-or-name:folder/path/to/filename

For more details, see external documentation [TODO: Put link here].
'''

from __future__ import print_function, unicode_literals, division, absolute_import

import os, sys, json, re

import dxpy
from .describe import get_ls_l_desc
from ..compat import str, input, basestring
from ..cli import try_call, INTERACTIVE_CLI
from ..exceptions import DXCLIError, DXError

def pick(choices, default=None, str_choices=None, prompt=None, allow_mult=False, more_choices=False):
    '''
    :param choices: Strings between which the user will make a choice
    :type choices: list of strings
    :param default: Number the index to be used as the default
    :type default: int or None
    :param str_choices: Strings to be used as aliases for the choices; must be of the same length as choices and each string must be unique
    :type str_choices: list of strings
    :param prompt: A custom prompt to be used
    :type prompt: string
    :param allow_mult: Whether "*" is a valid option to select all choices
    :type allow_mult: boolean
    :param more_choices: Whether "m" is a valid option to ask for more options
    :type more_choices: boolean
    :returns: The user's choice, i.e. one of a numbered index of choices (e.g. 0 for the first item), "*" (only if allow_mult is True), or "m" (only if more_results is True)
    :rtype: int or string
    :raises: :exc:`EOFError` to signify quitting the process

    At most one of allow_mult and more_choices should be set to True.
    '''
    if len(choices) == 1:
        choice = 0
        return choice

    for i in range(len(choices)):
        prefix = str(i) + ') '
        lines = choices[i].split("\n")
        joiner = "\n" + " " * len(prefix)
        print(prefix + joiner.join(lines))
    if more_choices:
        print('m) More options not shown...')
    print('')
    if prompt is None:
        prompt = 'Pick a numbered choice'
        if allow_mult:
            prompt += ' or "*" for all'
        elif more_choices:
            prompt += ' or "m" for more options'
        if default is not None:
            prompt += ' [' + str(default) + ']'
        prompt += ': '
    while True:
        try:
            value = input(prompt)
        except KeyboardInterrupt:
            print('')
            raise
        except EOFError:
            print('')
            raise
        if default is not None and value == '':
            return default
        if allow_mult and value == '*':
            return value
        if more_choices and value == 'm':
            return value
        try:
            choice = str_choices.index(value)
            return choice
        except:
            pass
        try:
            choice = int(value)
            if choice not in range(len(choices)):
                raise IndexError()
            return choice
        except Exception:
            print('Not a valid selection')

def paginate_and_pick(generator, render_fn=str, filter_fn=None, page_len=10, **pick_opts):
    any_results = False
    while True:
        results = []
        while len(results) < page_len:
            possible_next = next(generator, None)
            if possible_next is None:
                break
            if filter_fn is None:
                results.append(possible_next)
            else:
                if filter_fn(possible_next):
                    results.append(possible_next)
            any_results = True
        if not any_results:
            return "none found"
        elif len(results) == 0:
            return "none picked"

        try:
            choice = pick([render_fn(result) for result in results],
                          more_choices=(len(results) == page_len),
                          **pick_opts)
        except KeyboardInterrupt:
            return "none picked"
        if choice == 'm':
            continue
        else:
            return results[choice]

# The following caches project names to project IDs because they are
# unlikely to change.
cached_project_names = {}
# Possible cache for the future of project ID->folderpath->object name->ID
# cached_project_paths = {}

class ResolutionError(DXError):
    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return self.msg

data_obj_pattern = re.compile('^(record|applet|file|workflow|database)-[0-9A-Za-z]{24}$')
hash_pattern = re.compile('^(record|app|applet|workflow|globalworkflow|job|analysis|project|container|file|database)-[0-9A-Za-z]{24}$')
nohash_pattern = re.compile('^(user|org|app|globalworkflow|team)-')
jbor_pattern = re.compile('^(job|analysis)-[0-9A-Za-z]{24}:[a-zA-Z_][0-9a-zA-Z_]*$')

def is_hashid(string):
    return hash_pattern.match(string) is not None

def is_data_obj_id(string):
    return data_obj_pattern.match(string) is not None

def is_container_id(string):
    return is_hashid(string) and (string.startswith('project-') or string.startswith('container-'))

def is_project_id(string):
    return is_hashid(string) and string.startswith('project-')

def is_analysis_id(string):
    return is_hashid(string) and string.startswith('analysis-')

def is_job_id(string):
    return is_hashid(string) and string.startswith('job-')

def is_localjob_id(thing):
    return (os.environ.get('DX_JOB_ID') is None and thing.startswith('localjob-'))

def is_nohash_id(string):
    return nohash_pattern.match(string) is not None

def is_glob_pattern(string):
    return (get_last_pos_of_char('*', string) >= 0) or (get_last_pos_of_char('?', string) >= 0)

def is_jbor_str(string):
    return jbor_pattern.match(string) is not None

def is_project_explicit(path):
    """
    Returns True if the specified path explicitly specifies a project.
    """
    # This method encodes our rules for deciding when a path shows an explicit
    # affinity to a particular project. This is a stronger notion than just
    # saying that the path resolves to an object in that project.
    #
    # For an explanation of the rules, see the unit tests
    # (test_dxpy.TestResolver.test_is_project_explicit).
    #
    # Note, this method need not validate that the path can otherwise be
    # resolved; it can assume this as a precondition.
    path = _maybe_convert_stringified_dxlink(path)
    return not is_hashid(path)

def object_exists_in_project(obj_id, proj_id):
    '''
    :param obj_id: object ID
    :type obj_id: str
    :param proj_id: project ID
    :type proj_id: str

    Returns True if the specified data object can be found in the specified
    project.
    '''
    if obj_id is None:
        raise ValueError("Expected obj_id to be a string")
    if proj_id is None:
        raise ValueError("Expected proj_id to be a string")
    if not is_container_id(proj_id):
        raise ValueError('Expected %r to be a container ID' % (proj_id,))
    return try_call(dxpy.DXHTTPRequest, '/' + obj_id + '/describe', {'project': proj_id})['project'] == proj_id

# Special characters in bash to be escaped: #?*: ;&`"'/!$({[<>|~
def escaper(match):
    return "\\" + match.group(0)

def escape_folder_str(string):
    return re.sub("([#\?\*: ;&`\"'!$\(\)\{\[<>|~])", escaper, string.replace('\\', '\\\\'))

def escape_name_str(string):
    return re.sub("([#\?\*: ;&`\"'/!$\(\)\{\[<>|~])", escaper, string.replace('\\', '\\\\'))

def unescaper(match):
    return match.group(0)[1]

def unescape_folder_str(string):
    return re.sub("(\\\[#\?*: ;&`\"'!$\(\){[<>|~])", unescaper, string).replace('\\\\', '\\')

def unescape_name_str(string):
    return re.sub("(\\\[#\?*: ;&`\"'/!$\(\){[<>|~])", unescaper, string).replace('\\\\', '\\')

def get_last_pos_of_char(char, string):
    '''
    :param char: The character to find
    :type char: string
    :param string: The string in which to search for *char*
    :type string: string
    :returns: Index in *string* where *char* last appears (unescaped by a preceding "\\"), -1 if not found
    :rtype: int

    Finds the last occurrence of *char* in *string* in which *char* is
    not present as an escaped character.

    '''
    pos = len(string)
    while pos > 0:
        pos = string[:pos].rfind(char)
        if pos == -1:
            return -1
        num_backslashes = 0
        test_index = pos - 1
        while test_index >= 0 and string[test_index] == '\\':
            num_backslashes += 1
            test_index -= 1
        if num_backslashes % 2 == 0:
            return pos
    return -1

def get_first_pos_of_char(char, string):
    '''
    :param char: The character to find
    :type char: string
    :param string: The string in which to search for *char*
    :type string: string
    :returns: Index in *string* where *char* last appears (unescaped by a preceding "\\"), -1 if not found
    :rtype: int

    Finds the first occurrence of *char* in *string* in which *char* is
    not present as an escaped character.

    '''
    first_pos = -1
    pos = len(string)
    while pos > 0:
        pos = string[:pos].rfind(char)
        if pos == -1:
            return first_pos
        num_backslashes = 0
        test_index = pos - 1
        while test_index >= 0 and string[test_index] == '\\':
            num_backslashes += 1
            test_index -= 1
        if num_backslashes % 2 == 0:
            first_pos = pos
    return first_pos

def split_unescaped(char, string, include_empty_strings=False):
    '''
    :param char: The character on which to split the string
    :type char: string
    :param string: The string to split
    :type string: string
    :returns: List of substrings of *string*
    :rtype: list of strings

    Splits *string* whenever *char* appears without an odd number of
    backslashes ('\\') preceding it, discarding any empty string
    elements.

    '''
    words = []
    pos = len(string)
    lastpos = pos
    while pos >= 0:
        pos = get_last_pos_of_char(char, string[:lastpos])
        if pos >= 0:
            if pos + 1 != lastpos or include_empty_strings:
                words.append(string[pos + 1: lastpos])
            lastpos = pos
    if lastpos != 0 or include_empty_strings:
        words.append(string[:lastpos])
    words.reverse()
    return words

def clean_folder_path(path, expected=None):
    '''
    :param path: A folder path to sanitize and parse
    :type path: string
    :param expected: Whether a folder ("folder"), a data object ("entity"), or either (None) is expected
    :type expected: string or None
    :returns: *folderpath*, *name*

    Unescape and parse *path* as a folder path to possibly an entity
    name.  Consecutive unescaped forward slashes "/" are collapsed to
    a single forward slash.  If *expected* is "folder", *name* is
    always returned as None.  Otherwise, the string to the right of
    the last unescaped "/" is considered a possible data object name
    and returned as such.

    '''
    folders = split_unescaped('/', path)

    if len(folders) == 0:
        return '/', None

    if expected == 'folder' or folders[-1] == '.' or folders[-1] == '..' or get_last_pos_of_char('/', path) == len(path) - 1:
        entity_name = None
    else:
        entity_name = unescape_name_str(folders.pop())

    sanitized_folders = []

    for folder in folders:
        if folder == '.':
            pass
        elif folder == '..':
            if len(sanitized_folders) > 0:
                sanitized_folders.pop()
        else:
            sanitized_folders.append(unescape_folder_str(folder))

    return ('/' + '/'.join(sanitized_folders)), entity_name

def resolve_container_id_or_name(raw_string, is_error=False, multi=False):
    '''
    :param raw_string: A potential project or container ID or name
    :type raw_string: string
    :param is_error: Whether to raise an exception if the project or
            container ID cannot be resolved
    :type is_error: boolean
    :returns: Project or container ID if found or else None
    :rtype: string or None
    :raises: :exc:`ResolutionError` if *is_error* is True and the
            project or container could not be resolved

    Unescapes and attempts to resolve *raw_string* to a project or
    container ID.

    '''
    string = unescape_name_str(raw_string)
    if is_container_id(string):
        return ([string] if multi else string)

    if string in cached_project_names:
        return ([cached_project_names[string]] if multi else cached_project_names[string])

    try:
        results = list(dxpy.find_projects(name=string, describe=True, level='VIEW'))
    except Exception as details:
        raise ResolutionError(str(details))

    if len(results) == 1:
        cached_project_names[string] = results[0]['id']
        return ([results[0]['id']] if multi else results[0]['id'])
    elif len(results) == 0:
        if is_error:
            raise ResolutionError('Could not find a project named "' + string + '"')
        return ([] if multi else None)
    elif not multi:
        if INTERACTIVE_CLI:
            print('Found multiple projects with name "' + string + '"')
            choice = pick(['{id} ({level})'.format(id=result['id'], level=result['level'])
                           for result in results])
            return results[choice]['id']
        else:
            raise ResolutionError('Found multiple projects with name "' + string + '"; please use a project ID to specify the desired project')
    else:
        # len(results) > 1 and multi
        return [result['id'] for result in results]

def _maybe_convert_stringified_dxlink(path):
    try:
        possible_hash = json.loads(path)
        if isinstance(possible_hash, dict) and '$dnanexus_link' in possible_hash:
            if isinstance(possible_hash['$dnanexus_link'], basestring):
                return possible_hash['$dnanexus_link']
            elif (isinstance(possible_hash['$dnanexus_link'], dict) and
                  isinstance(possible_hash['$dnanexus_link'].get('project', None), basestring) and
                  isinstance(possible_hash['$dnanexus_link'].get('id', None), basestring)):
                return possible_hash['$dnanexus_link']['project'] + ':' + possible_hash['$dnanexus_link']['id']
    except:
        pass
    return path

def resolve_path(path, expected=None, multi_projects=False, allow_empty_string=True):
    '''
    :param path: A path to a data object to attempt to resolve
    :type path: string
    :param expected: one of the following: "folder", "entity", or None
            to indicate whether the expected path is a folder, a data
            object, or either
    :type expected: string or None
    :returns: A tuple of 3 values: container_ID, folderpath, entity_name
    :rtype: string, string, string
    :raises: exc:`ResolutionError` if the project cannot be resolved by
            name or the path is malformed
    :param allow_empty_string: If false, a ResolutionError will be
            raised if *path* is an empty string. Use this when resolving
            the empty string could result in unexpected behavior.
    :type allow_empty_string: boolean

    Attempts to resolve *path* to a project or container ID, a folder
    path, and a data object or folder name.  This method will NOT
    raise an exception if the specified folder or object does not
    exist.  This method is primarily for parsing purposes.

    Returns one of the following:

      (project, folder, maybe_name)
      where
        project is a container ID (non-null)
        folder is a folder path
        maybe_name is a string if the path could represent a folder or an object, or
        maybe_name is None if the path could only represent a folder

    OR

      (maybe_project, None, object_id)
      where
        maybe_project is a container ID or None
        object_id is a dataobject, app, or execution (specified by ID, not name)

    OR

      (job_id, None, output_name)
      where
        job_id and output_name are both non-null

    '''
    # TODO: callers that intend to obtain a data object probably won't be happy
    # with an app or execution ID. Callers should probably have to specify
    # whether they are okay with getting an execution ID or not.

    # TODO: callers that are looking for a place to write data, rather than
    # read it, probably won't be happy with receiving an object ID, or a
    # JBOR. Callers should probably specify whether they are looking for an
    # "LHS" expression or not.

    if '_DX_FUSE' in os.environ:
        from xattr import xattr
        path = xattr(path)['project'] + ":" + xattr(path)['id']

    if path == '' and not allow_empty_string:
        raise ResolutionError('Cannot parse ""; expected the path to be a non-empty string')
    path = _maybe_convert_stringified_dxlink(path)

    # Easy case: ":"
    if path == ':':
        if dxpy.WORKSPACE_ID is None:
            raise ResolutionError("Cannot resolve \":\": expected a project name or ID "
                                  "to the left of the colon, or for a current project to be set")
        return ([dxpy.WORKSPACE_ID] if multi_projects else dxpy.WORKSPACE_ID), '/', None
    # Second easy case: empty string
    if path == '':
        if dxpy.WORKSPACE_ID is None:
            raise ResolutionError('Expected a project name or ID to the left of a colon, '
                                  'or for a current project to be set')
        return ([dxpy.WORKSPACE_ID] if multi_projects else dxpy.WORKSPACE_ID), dxpy.config.get('DX_CLI_WD', '/'), None
    # Third easy case: hash ID
    if is_container_id(path):
        return ([path] if multi_projects else path), '/', None
    elif is_hashid(path):
        return ([dxpy.WORKSPACE_ID] if multi_projects else dxpy.WORKSPACE_ID), None, path

    # using a numerical sentinel value to indicate that it hasn't been
    # set in case dxpy.WORKSPACE_ID is actually None
    project = 0
    folderpath = None
    entity_name = None
    wd = dxpy.config.get('DX_CLI_WD', u'/')

    # Test for multiple colons
    last_colon = get_last_pos_of_char(':', path)
    if last_colon >= 0:
        last_last_colon = get_last_pos_of_char(':', path[:last_colon])
        if last_last_colon >= 0:
            raise ResolutionError('Cannot parse "' + path + '" as a path; at most one unescaped colon can be present')

    substrings = split_unescaped(':', path)

    if len(substrings) == 2:
        # One of the following:
        # 1) job-id:fieldname
        # 2) project-name-or-id:folderpath/to/possible/entity
        if is_job_id(substrings[0]):
            return ([substrings[0]] if multi_projects else substrings[0]), None, substrings[1]

        if multi_projects:
            project_ids = resolve_container_id_or_name(substrings[0], is_error=True, multi=True)
        else:
            project = resolve_container_id_or_name(substrings[0], is_error=True)
        wd = '/'
    elif get_last_pos_of_char(':', path) >= 0:
        # :folderpath/to/possible/entity OR project-name-or-id:
        # Colon is either at the beginning or at the end
        wd = '/'
        if path.startswith(':'):
            if dxpy.WORKSPACE_ID is None:
                raise ResolutionError('Cannot resolve "%s": expected a project name or ID to the left of the '
                                      'colon, or for a current project to be set' % (path,))
            project = dxpy.WORKSPACE_ID
        else:
            # One nonempty string to the left of a colon
            project = resolve_container_id_or_name(substrings[0], is_error=True)
            folderpath = '/'
    else:
        # One nonempty string, no colon present, do NOT interpret as
        # project
        project = dxpy.WORKSPACE_ID
        if project is None:
            raise ResolutionError('Cannot resolve "%s": expected the path to be qualified with a project name or ID, '
                                  'and a colon; or for a current project to be set' % (path,))

    # Determine folderpath and entity_name if necessary
    if folderpath is None:
        folderpath = substrings[-1]
        folderpath, entity_name = clean_folder_path(('' if folderpath.startswith('/') else wd + '/') + folderpath, expected)

    if multi_projects:
        return (project_ids if project == 0 else [project]), folderpath, entity_name
    else:
        return project, folderpath, entity_name

def resolve_job_ref(job_id, name, describe={}):
    try:
        job_desc = dxpy.api.job_describe(job_id)
    except Exception as details:
        raise ResolutionError(str(details))
    project = job_desc['project']
    describe['project'] = project
    if job_desc['state'] != 'done':
        raise ResolutionError('the job ' + job_id + ' is ' + job_desc['state'] + ', and it must be in the done state for its outputs to be accessed')

    index = None
    if '.' in name:
        try:
            actual_name, str_index = name.rsplit('.', 1)
            index = int(str_index)
            name = actual_name
        except ValueError:
            pass

    output_field = job_desc['output'].get(name, None)
    if index is not None:
        if not isinstance(output_field, list):
            raise ResolutionError('Found "' + name + '" as an output field name of ' + job_id +
                                  ', but it is not an array and cannot be indexed')
        if index < 0 or index >= len(output_field):
            raise ResolutionError('Found "' + name + '" as an output field name of ' + job_id +
                                  ', but the specified index ' + str_index + ' is out of range')
        output_field = output_field[index]
    results = []
    if output_field is not None:
        if isinstance(output_field, list):
            if len(output_field) > 0:
                if not isinstance(output_field[0], dict) or '$dnanexus_link' not in output_field[0]:
                    raise ResolutionError('Found "' + name + '" as an output field name of ' + job_id + ', but it is an array of non-data objects')
                ids = [link['$dnanexus_link'] for link in output_field]
                try:
                    results = [{"id": out_id,
                                "describe": dxpy.DXHTTPRequest('/' + out_id + '/describe', describe)} for out_id in ids]
                except Exception as details:
                    raise ResolutionError(str(details))
            else:
                raise ResolutionError('Found "' + name + '" as an output field name of ' + job_id + ', but it is an empty array')
        elif isinstance(output_field, dict) and '$dnanexus_link' in output_field:
            obj_id = output_field['$dnanexus_link']
            try:
                results = [{"id": obj_id, "describe": dxpy.DXHTTPRequest('/' + obj_id + '/describe', describe)}]
            except Exception as details:
                raise ResolutionError(str(details))
        else:
            raise ResolutionError('Found "' + name + '" as an output field name of ' + job_id + ', but it is not of a data object class')
    else:
        raise ResolutionError('Could not find "' + name + '" as an output field name of ' + job_id + '; available fields are: ' + ', '.join(job_desc['output'].keys()))

    return results

def _check_resolution_needed(path, project, folderpath, entity_name, expected_classes=None, describe=True,
                             enclose_in_list=False):
    """
    :param path: Path to the object that required resolution; propagated from
                 command-line
    :type path: string
    :param project: The potential project the entity belongs to
    :type project: string
    :param folderpath: Path to the entity
    :type folderpath: string
    :param entity_name: The name of the entity
    :type entity_name: string
    :param expected_classes: A list of expected classes the entity is allowed
                             to belong to if it is an ID (e.g. "record",
                             "file", "job"); if None, then entity_name may be
                             any data object class
    :type expected_classes: list or None
    :param describe: Dictionary of inputs to the describe API call; if
                     no describe input is provided (default value True), then
                     an empty mapping is passed to the describe API method
    :type describe: dict or True
    :param enclose_in_list: Whether the describe output is to be in the form
                            of a list (if False, the last return value is a
                            dictionary; if True, the last return value is a
                            list of one dictionary); it will only have an
                            effect if entity_name is a DX ID and is described
    :type enclose_in_list: boolean
    :returns: Whether or not the entity needs to be resolved with a more
              general resolution method, the project, the folderpath, and the
              entity name
    :rtype: tuple of 4 elements
    :raises: ResolutionError if the entity fails to be described

    Attempts to resolve the entity to a folder or an object, and describes
    the entity iff it is a DX ID of an expected class in the list
    expected_classes.
    Otherwise, determines whether or not more general resolution may be able
    to resolve the entity.

    If a more general resolution method is needed, then the return values will
    look like:
    (True, <project>, <folderpath>, <entity_name>)

    If the entity is a DX ID, but is not one of the supplied expected
    classes, then the return values will look like:
    (False, None, None, None)

    If the entity can be successfully described, then the return values will
    look like:
    <desc_output> ::= {"id": entity_name, "describe": {...}}
    <desc_or_desc_list> ::= <desc_output> || [<desc_output>]
    (False, <project>, <folderpath>, <desc_or_desc_list>)

    If the entity may be a folder, then the return values will look like:
    (False, <project>, <folderpath>, None)

    TODO: Allow arbitrary flags for the describe mapping.
    """
    if entity_name is None:
        # Definitely a folder (or project)
        # TODO: find a good way to check if folder exists and expected=folder
        return False, project, folderpath, None
    elif is_hashid(entity_name):
        entity_class = entity_name.split("-")[0]
        found_valid_class = True
        if expected_classes is not None and entity_class not in expected_classes:
            found_valid_class = False

        if not found_valid_class:
            return False, None, None, None

        if describe is True:
            describe = {}

        # entity is an ID of a valid class, try to describe it
        if 'project' not in describe:
            if project != dxpy.WORKSPACE_ID:
                describe['project'] = project
            elif dxpy.WORKSPACE_ID is not None:
                describe['project'] = dxpy.WORKSPACE_ID
        try:
            desc = dxpy.DXHTTPRequest('/' + entity_name + '/describe', describe)
            desc = dxpy.append_underlying_workflow_describe(desc)
        except Exception as details:
            if 'project' in describe:
                # Now try it without the hint
                del describe['project']
                try:
                    desc = dxpy.DXHTTPRequest('/' + entity_name + '/describe', describe)
                except Exception as details2:
                    raise ResolutionError(str(details2))
            else:
                raise ResolutionError(str(details))
        result = {"id": entity_name, "describe": desc}
        if enclose_in_list:
            return False, project, folderpath, [result]
        else:
            return False, project, folderpath, result

    else:
        # Need to resolve later
        return True, project, folderpath, entity_name

def _resolve_folder(project, parent_folder, folder_name):
    """
    :param project: The project that the folder belongs to
    :type project: string
    :param parent_folder: Full path to the parent folder that contains
                         folder_name
    :type parent_folder: string
    :param folder_name: Name of the folder
    :type folder_name: string
    :returns: The path to folder_name, if it exists, in the form of
              "<parent_folder>/<folder_name>"
    :rtype: string
    :raises: ResolutionError if folder_name is not a folder, or if
             folder_name points to a folder that does not exist

    Attempts to resolve folder_name at location parent_folder in project.
    """
    if '/' in folder_name:
        # Then there's no way it's supposed to be a folder
        raise ResolutionError('Object of name ' + str(folder_name) + ' could not be resolved in folder ' +
                              str(parent_folder) + ' of project ID ' + str(project))
    possible_folder, _skip = clean_folder_path(parent_folder + '/' + folder_name, 'folder')

    if not check_folder_exists(project, parent_folder, folder_name):
        raise ResolutionError('Unable to resolve "' + folder_name +
                              '" to a data object or folder name in \'' + parent_folder + "'")
    return possible_folder

def _validate_resolution_output_length(path, entity_name, results, allow_mult=False, all_mult=False,
                                       ask_to_resolve=True):
    """
    :param path: Path to the object that required resolution; propagated from
                 command-line
    :type path: string
    :param entity_name: Name of the object
    :type entity_name: string
    :param results: Result of resolution; non-empty list of object
                    specifications (each specification is a dictionary with
                    keys "project" and "id")
    :type results: list of dictionaries
    :param allow_mult: If True, it is okay to choose from multiple results
                       of a single resolved object, or return all results
                       found; if False, raise an error if multiple results
                       are found
    :type allow_mult: boolean
    :param all_mult: If True, return all results if multiple results are
                     found for a single resolved object; if False, user needs
                     to choose a single result if multiple are found; the value
                     of all_mult only has an effect if allow_mult is True)
    :type all_mult: boolean
    :param ask_to_resolve: Whether picking may be necessary (if True, a
                           list is returned; if False, only one result
                           is returned); if specified as True, then all
                           results will be returned, regardless of the
                           values of allow_mult and all_mult
    :type ask_to_resolve: boolean
    :returns: The results of resolving entity_name, expected to be of the
              following form:
              <resolved_object>  # If only one result is present or the user
                                 # is able to select from multiple
              OR
              [<resolved_object>, ...]  # If multiple results are present and
                                        # it is allowed
              where <resolved_object> is of the following form:
              {"project": <project_id>, "id": <object_id>}
    :rtype: dict or list of dicts
    :raises: ValueError if results is empty
    :raises: ResolutionError if too many results are found and the user is
             not in interactive mode and cannot select one

    Precondition: results must be a nonempty list

    Validates length of results.

    If there are multiple results found and the user is in interactive mode,
    then the user will be prompted to select a single result to be returned.
    """
    if len(results) == 0:
        raise ValueError("'results' must be nonempty.")

    # Caller wants ALL results, so return the entire results list
    # At this point, do not care about the values of allow_mult or all_mult
    if not ask_to_resolve:
        return results

    if len(results) > 1:
        # The other way the caller can specify it wants all results is by setting
        # allow_mult to be True and allowing all_mult to be True (or if the object name is a glob pattern)
        if allow_mult and (all_mult or is_glob_pattern(entity_name)):
            return results
        if INTERACTIVE_CLI:
            print('The given path "' + path + '" resolves to the following data objects:')
            if any(['describe' not in result for result in results]):
                # findDataObject API call must be made to get 'describe' mappings
                project, folderpath, entity_name = resolve_path(path, expected='entity')
                results = _resolve_global_entity(project, folderpath, entity_name)
            choice = pick([get_ls_l_desc(result['describe']) for result in results],
                          allow_mult=allow_mult)
            if allow_mult and choice == '*':
                return results
            else:
                return [results[choice]] if allow_mult else results[choice]
        else:
            raise ResolutionError('The given path "' + path + '" resolves to ' +
                                  str(len(results)) + ' data objects')
    else:
        return [results[0]] if allow_mult else results[0]

def _resolve_global_entity(project_or_job_id, folderpath, entity_name, describe=True, visibility="either"):
    """
    :param project_or_job_id: The project ID to which the entity belongs
                              (then the entity is an existing data object),
                              or the job ID to which the entity belongs
                              (then the entity is a job-based object
                              reference to an object that may not exist yet)
    :type project_or_job_id: string
    :param folderpath: Full path to the object (parsed from command line)
    :type folderpath: string
    :param entity_name: Name of the object
    :type entity_name: string
    :param describe: Input mapping used to describe the job's project if
                     project_or_job_id is a job ID, or True if the input
                     mapping is to be empty
    :type describe: dict or True
    :param visibility: The expected visibility of the entity ("either",
                       "hidden", or "visible"); to be used in resolution
    :type visibility: string
    :returns: The results obtained from attempting to resolve the entity;
              the expected format of the return value is described below
    :rtype: list
    :raises: ResolutionError if dxpy.find_data_objects throws an error

    If project_or_job_id is a job ID, then return value will be like:
        [{"id": ..., "describe": {...}}, ...]

    Otherwise, the return value will be like:
        [{"id": ..., "project": ..., "describe": {...}}, ...]
    Note that if the entity is successfully resolved, then the "describe"
    key will be in the dictionary if and only if a nonempty describe
    mapping was provided.

    TODO: Inspect entity_name and conditionally treat it as a "glob" pattern.

    TODO: Callers should specify exactly what fields they want, and then
    hopefully we can avoid having a default set of fields that may be very
    expensive
    """
    if is_job_id(project_or_job_id):
        if describe is True:
            describe = {}
        # The following function call will raise a ResolutionError if no results
        # could be found.
        # If the call is successful, then the project will be incorporated into the
        # "describe" mapping of the returned dictionaries.
        return resolve_job_ref(project_or_job_id, entity_name, describe=describe)
    else:
        try:
            return list(dxpy.find_data_objects(project=project_or_job_id,
                                               folder=folderpath,
                                               name=entity_name,
                                               name_mode='glob',
                                               recurse=False,
                                               describe=describe,
                                               visibility=visibility))
        except Exception as details:
            raise ResolutionError(str(details))

def _format_resolution_output(path, project, folderpath, entity_name, result):
    """
    :param path: Path to the object that required resolution; propagated from
                 command-line
    :type path: string
    :param project: The potential project the entity belongs to
    :type project: string
    :param folderpath: Path to the entity
    :type folderpath: string
    :param entity_name: The name of the entity
    :type entity_name: string
    :param result: The result of resolving entity_name
    :type result: list of dictionaries
    :returns: The validated resolution output
    :rtype: dictionary

    Formats the output from the resolution of entity_name based on the number
    of resolved entities.

    If no results are found and entity_name can be resolved to a folder, then
    the return value will look like:
    {"project": <project>, "folder": <folder>, "name": None}

    If exactly one result is found, then the return value will look like:
    {"project": <project>, "folder": <folder>, "name": {"id": <id>,
                                                        "project": <project>}}
    OR
    {"project": None, "folder": <folder>, "name": {"id": <id>,
                                                   "project": <project>}}

    Else, the return value will look like:
    {"project": None, "folder": None, "name": None}
    """
    try:
        if len(result) == 0:
            folder = _resolve_folder(project, folderpath, entity_name)
            return {"project": project, "folder": folder, "name": None}
        else:
            validated_results = _validate_resolution_output_length(path, entity_name, result)
            return {"project": None if is_job_id(project) else project,
                    "folder": None, "name": validated_results}
    except ResolutionError:
        return {"project": None, "folder": None, "name": None}

def resolve_multiple_existing_paths(paths):
    """
    :param paths: A list of paths to items that need to be resolved
    :type paths: list
    :returns: A dictionary mapping a specified path to either its resolved
              object or Nones, if the object could not be resolved
    :rtype: dict

    For each input given in paths, attempts to resolve the path, and returns
    the resolved object in a dictionary.

    The return value will look like:
    {<path1>: <resolved_object1>, <path2>: <resolved_object2>,...}

    If entity_id is a DX ID that can be described,
        <resolved_object*> ::= {"project": None,
                                "folder": None,
                                "name": {"id": <id>,
                                         "describe": <describe_output>}}

    Else if a general resolution (or search) method will be used to resolve
    the entity,
        <resolved_object*> ::= {"project": <project>,
                                "folder": None,
                                "name": {"project": <project>,
                                         "id": <resolved_id>}}

    Else if <project> is a job ID,
        <resolved_object*> ::= {"project": None,
                                "folder": None,
                                "name": {"project": <project>,
                                         "id": <resolved_id>}}

    Else if the path refers to a folder instead of a data object,
        <resolved_object*> ::= {"project": <project>,
                                "folder": <folder>,
                                "name": None}

    Else if description or resolution fails,
        <resolved_object*> ::= {"project": None, "folder": None, "name": None}
    """
    done_objects = {}  # Return value
    to_resolve_in_batch_paths = []  # Paths to resolve
    to_resolve_in_batch_inputs = []  # Project, folderpath, and entity name
    for path in paths:
        project, folderpath, entity_name = resolve_path(path, expected='entity')
        try:
            must_resolve, project, folderpath, entity_name = _check_resolution_needed(
                path, project, folderpath, entity_name)
        except:
            must_resolve = False

        if must_resolve:
            if is_glob_pattern(entity_name):
                # TODO: Must call findDataObjects because resolveDataObjects does not support glob patterns
                try:
                    find_results = _resolve_global_entity(project, folderpath, entity_name)
                    done_objects[path] = _format_resolution_output(path, project, folderpath, entity_name,
                                                                   find_results)
                except ResolutionError:
                    # Catches any ResolutionError thrown by _resolve_global_entity
                    done_objects[path] = {"project": None, "folder": None, "name": None}
            else:
                # Prepare batch call for resolveDataObjects
                to_resolve_in_batch_paths.append(path)
                to_resolve_in_batch_inputs.append({"project": project, "folder": folderpath, "name": entity_name})
        else:
            # No need to resolve
            done_objects[path] = {"project": project, "folder": folderpath, "name": entity_name}

    # Call resolveDataObjects
    resolution_results = dxpy.resolve_data_objects(to_resolve_in_batch_inputs)
    for path, inputs, result in zip(to_resolve_in_batch_paths, to_resolve_in_batch_inputs,
                                    resolution_results):
        done_objects[path] = _format_resolution_output(path, inputs["project"], inputs["folder"], inputs["name"],
                                                       result)
    return done_objects

def resolve_existing_path(path, expected=None, ask_to_resolve=True, expected_classes=None, allow_mult=False,
                          describe=True, all_mult=False, allow_empty_string=True, visibility="either"):
    '''
    :param expected: one of the following: "folder", "entity", or None to indicate
                     whether the expected path is a folder, a data object, or either
    :type expected: string or None
    :param ask_to_resolve: Whether picking may be necessary (if true, a list is returned; if false, only one result is returned)
    :type ask_to_resolve: boolean
    :param expected_classes: A list of expected classes the entity is allowed
                             to belong to if it is an ID (e.g. "record",
                             "file", "job"); if None, then entity_name may be
                             any data object class
    :type expected_classes: list or None
    :param allow_mult: Whether to allow the user to select multiple results from the same path
    :type allow_mult: boolean
    :param describe: Input hash to describe call for the results, or True if no describe input
                     is to be provided
    :type describe: dict or True
    :param all_mult: Whether to return all matching results without prompting (only applicable if allow_mult == True)
    :type all_mult: boolean
    :returns: A LIST of results when ask_to_resolve is False or allow_mult is True
    :raises: :exc:`ResolutionError` if the request path was invalid, or a single result was requested and input is not a TTY
    :param allow_empty_string: If false, a ResolutionError will be raised if *path* is an empty string. Use this when resolving the empty string could result in unexpected behavior.
    :type allow_empty_string: boolean
    :param visibility: The visibility expected ("either", "hidden", or "visible")
    :type visibility: string

    Returns either a list of results or a single result (depending on
    how many is expected; if only one, then an interactive picking of
    a choice will be initiated if input is a tty, or else throw an error).

    TODO: Always treats the path as a glob pattern.

    Output is of the form {"id": id, "describe": describe hash} a list
    of those

    TODO: Callers should specify exactly what fields they want, and then
    hopefully we can avoid having a default set of fields that may be very
    expensive

    NOTE: if expected_classes is provided and conflicts with the class
    of the hash ID, it will return None for all fields.
    '''
    project, folderpath, entity_name = resolve_path(path, expected=expected, allow_empty_string=allow_empty_string)
    must_resolve, project, folderpath, entity_name = _check_resolution_needed(path,
                                                                              project,
                                                                              folderpath,
                                                                              entity_name,
                                                                              expected_classes=expected_classes,
                                                                              describe=describe,
                                                                              enclose_in_list=(not ask_to_resolve or
                                                                                allow_mult))

    if must_resolve:
        results = _resolve_global_entity(project, folderpath, entity_name, describe=describe, visibility=visibility)
        if len(results) == 0:
            # Could not resolve entity, so it is probably a folder
            folder = _resolve_folder(project, folderpath, entity_name)
            return project, folder, None
        else:
            validated_results = _validate_resolution_output_length(path,
                                                                   entity_name,
                                                                   results,
                                                                   allow_mult=allow_mult,
                                                                   all_mult=all_mult,
                                                                   ask_to_resolve=ask_to_resolve)
            if is_job_id(project):
                return None, None, validated_results
            return project, None, validated_results
    return project, folderpath, entity_name

def check_folder_exists(project, path, folder_name):
    '''
    :param project: project id
    :type project: string
    :param path: path to where we should look for the folder in question
    :type path: string
    :param folder_name: name of the folder in question
    :type folder_name: string
    :returns: A boolean True or False whether the folder exists at the specified path
    :type: boolean
    :raises: :exc:'ResolutionError' if dxpy.api.container_list_folder raises an exception

    This function returns a boolean value that indicates whether a folder of the
    specified name exists at the specified path

    Note: this function will NOT work on the root folder case, i.e. '/'
    '''
    if folder_name is None or path is None:
        return False
    try:
        folder_list = dxpy.api.container_list_folder(project, {"folder": path, "only": "folders"})
    except dxpy.exceptions.DXAPIError as e:
        if e.name == 'ResourceNotFound':
            raise ResolutionError(str(e.msg))
        else:
            raise e
    target_folder = path + '/' + folder_name
    # sanitize input if necessary
    target_folder, _skip = clean_folder_path(target_folder, 'folder')

    # Check that folder name exists in return from list folder API call
    return target_folder in folder_list['folders']

def get_app_from_path(path):
    '''
    :param path: A string to attempt to resolve to an app object
    :type path: string
    :returns: The describe hash of the app object if found, or None otherwise
    :rtype: dict or None

    This method parses a string that is expected to perhaps refer to
    an app object.  If found, its describe hash will be returned.  For
    more information on the contents of this hash, see the API
    documentation. [TODO: external link here]

    '''
    alias = None
    if not path.startswith('app-'):
        path = 'app-' + path
    if '/' in path:
        alias = path[path.find('/') + 1:]
        path = path[:path.find('/')]
    try:
        return dxpy.api.app_describe(path, alias=alias)
    except dxpy.DXAPIError:
        return None

def get_global_workflow_from_path(path):
    '''
    :param path: A string to attempt to resolve to a global workflow object
    :type path: string
    :returns: The describe hash of the global workflow object if found, or None otherwise
    :rtype: dict or None

    This method parses a string that is expected to perhaps refer to
    a global workflow object.  If found, its describe hash will be returned.
    For more information on the contents of this hash, see the API
    documentation. [TODO: external link here]

    '''
    alias = None
    if not path.startswith('globalworkflow-'):
        path = 'globalworkflow-' + path
    if '/' in path:
        alias = path[path.find('/') + 1:]
        path = path[:path.find('/')]

    try:
        return dxpy.api.global_workflow_describe(path, alias=alias)
    except dxpy.DXAPIError:
        return None

def get_global_exec_from_path(path):
    if path.startswith('app-'):
        return get_app_from_path(path)
    elif path.startswith('globalworkflow-'):
        return get_global_workflow_from_path(path)
    # If the path doesn't include a prefix, we must try describing
    # as an app and, if that fails, as a global workflow
    desc = get_app_from_path(path)
    if not desc:
        desc = get_global_workflow_from_path(path)
    return desc

def resolve_app(path):
    '''
    :param path: A string which is supposed to identify an app
    :type path: string
    :returns: The describe hash of the app object
    :raises: :exc:`ResolutionError` if it cannot be found

    *path* is expected to have one of the following forms:

    - hash ID, e.g. "app-B8GZ8bQ0xky1PKY6FjGQ000J"
    - named ID, e.g. "app-myapp"
    - named ID with alias (version or tag), e.g. "app-myapp/1.2.0"
    '''
    desc = get_app_from_path(path)
    if desc is None:
        raise ResolutionError('The given path "' + path + '" could not be resolved to an accessible app')
    else:
        return desc

def resolve_global_workflow(path):
    '''
    :param path: A string which is supposed to identify a global workflow
    :type path: string
    :returns: The describe hash of the global workflow object
    :raises: :exc:`ResolutionError` if it cannot be found

    *path* is expected to have one of the following forms:

    - hash ID, e.g. "globalworkflow-F85Z6bQ0xku1PKY6FjGQ011J"
    - named ID, e.g. "globalworkflow-myworkflow"
    - named ID with alias (version or tag), e.g. "globalworkflow-myworkflow/1.2.0"
    '''
    desc = get_global_workflow_from_path(path)
    if desc is None:
        raise ResolutionError('The given path "' + path + '" could not be resolved to an accessible global workflow')
    else:
        return desc

def resolve_global_executable(path, is_version_required=False):
    """
    :param path: A string which is supposed to identify a global executable (app or workflow)
    :type path: string
    :param is_version_required: If set to True, the path has to specify a specific version/alias, e.g. "myapp/1.0.0"
    :type is_version_required: boolean
    :returns: The describe hash of the global executable object (app or workflow)
    :raises: :exc:`ResolutionError` if it cannot be found

    *path* is expected to have one of the following forms:

    - hash ID, e.g. "globalworkflow-F85Z6bQ0xku1PKY6FjGQ011J", "app-FBZ3f200yfzkKYyp9JkFVQ97"
    - named ID, e.g. "app-myapp", "globalworkflow-myworkflow"
    - named ID with alias (version or tag), e.g. "myapp/1.2.0", "myworkflow/1.2.0"
    - named ID with prefix and with alias (version or tag), e.g. "app-myapp/1.2.0", "globalworkflow-myworkflow/1.2.0"
    """
    if not is_hashid(path) and is_version_required and "/" not in path:
        raise ResolutionError('Version is required, e.g. "myexec/1.0.0"'.format())

    # First, check if the prefix is provided, then we don't have to resolve the name
    if path.startswith('app-'):
        return resolve_app(path)
    elif path.startswith('globalworkflow-'):
        return resolve_global_workflow(path)

    # If the path doesn't include a prefix, we must try describing
    # as an app and, if that fails, as a global workflow
    desc = get_app_from_path(path)
    if not desc:
        desc = get_global_workflow_from_path(path)
    if desc is None:
        raise ResolutionError(
            'The given path "' + path + '" could not be resolved to an accessible global executable (app or workflow)')
    return desc

def get_exec_handler(path, alias=None):
    handler = None
    def get_handler_from_desc(desc):
        if desc['class'] == 'applet':
            return dxpy.DXApplet(desc['id'], project=desc['project'])
        elif desc['class'] == 'app':
            return dxpy.DXApp(dxid=desc['id'])
        elif desc['class'] == 'workflow':
            return dxpy.DXWorkflow(desc['id'], project=desc['project'])
        elif desc['class'] == 'globalworkflow':
            return dxpy.DXGlobalWorkflow(dxid=desc['id'])
        else:
            raise DXError('The executable class {} is not supported'.format(desc['class']))

    def path_starts_with_non_global_prefix(path):
        return path.startswith('workflow-') or path.startswith('applet-')

    # First attempt to resolve a global executable: app or global workflow
    # skip if it has non-global prefix
    global_exec_desc = None
    if not path_starts_with_non_global_prefix(path):
        global_exec_desc = get_global_exec_from_path(path)

    if alias is None:
        try:
            # Look for applets and workflows
            _project, _folderpath, entity_results = resolve_existing_path(path,
                                                                          expected='entity',
                                                                          ask_to_resolve=False,
                                                                          expected_classes=['applet', 'record', 'workflow'],
                                                                          visibility="visible")
            def is_applet_or_workflow(i):
                return (i['describe']['class'] in ['applet', 'workflow'])
            if entity_results is not None:
                entity_results = [i for i in entity_results if is_applet_or_workflow(i)]
                if len(entity_results) == 0:
                    entity_results = None
        except ResolutionError:
            if global_exec_desc is None:
                raise
            else:
                entity_results = None

        if entity_results is not None and len(entity_results) == 1 and global_exec_desc is None:
            handler = get_handler_from_desc(entity_results[0]['describe'])
        elif entity_results is None and global_exec_desc is not None:
            handler = get_handler_from_desc(global_exec_desc)
        elif entity_results is not None:
            if not INTERACTIVE_CLI:
                raise ResolutionError('Found multiple executables with the path ' + path)
            print('Found multiple executables with the path ' + path)
            choice_descriptions = [get_ls_l_desc(r['describe']) for r in entity_results]
            if global_exec_desc is not None:
                choice_descriptions.append(
                    '{prefix}-{name}, version {version}'.format(
                        prefix=global_exec_desc['class'],
                        name=global_exec_desc['name'],
                        version=global_exec_desc['version']))
            choice = pick(choice_descriptions)
            if choice < len(entity_results):
                # all applet/workflow choices show up before the global app/workflow,
                # of which there is always at most one possible choice
                handler = get_handler_from_desc(entity_results[choice]['describe'])
            else:
                handler = get_handler_from_desc(global_exec_desc)
        else:
            raise ResolutionError("No matches found for " + path)
    else:
        handler = get_handler_from_desc(global_exec_desc)
    return handler

def resolve_to_objects_or_project(path, all_matching_results=False):
    '''
    :param path: Path to resolve
    :type path: string
    :param all_matching_results: Whether to return a list of all matching results
    :type all_matching_results: boolean

    A thin wrapper over :meth:`resolve_existing_path` which throws an
    error if the path does not look like a project and doesn't match a
    data object path.

    Returns either a list of results or a single result (depending on
    how many is expected; if only one, then an interactive picking of
    a choice will be initiated if input is a tty, or else throw an error).
    '''
    # Attempt to resolve name
    project, folderpath, entity_results = resolve_existing_path(path,
                                                                expected='entity',
                                                                allow_mult=True,
                                                                all_mult=all_matching_results)
    if entity_results is None and not is_container_id(path):
        if folderpath != None and folderpath != '/':
            raise ResolutionError('Could not resolve "' + path + \
                                  '''" to an existing data object or to only a project;
                                  if you were attempting to refer to a project by name,
                                  please append a colon ":" to indicate that it is a project.''')
    return project, folderpath, entity_results

# Generic function to parse an input key-value pair of the form '-ikey=val'
# e.g. returns ("key", "val") in the example above
def parse_input_keyval(keyeqval):
    try:
        first_eq_pos = get_first_pos_of_char('=', keyeqval)
        if first_eq_pos == -1:
            raise
        name = split_unescaped('=', keyeqval)[0]
        value = keyeqval[first_eq_pos + 1:]
        return (name, value)
    except:
        raise DXCLIError('An input was found that did not conform to the syntax: -i<input name>=<input value>')


text:
import logging
import inspect
from asyncio import CancelledError

from . import events
from .http import HttpRequest

log = logging.getLogger(__name__)

class Spider:

    @classmethod
    def from_crawler(cls, crawler):
        cls.crawler = crawler
        cls.config = crawler.config
        spider = cls()
        crawler.event_bus.subscribe(spider.open, events.crawler_start)
        crawler.event_bus.subscribe(spider.close, events.crawler_shutdown)
        return spider

    @property
    def logger(self):
        return log

    def log(self, message, *args, level=logging.INFO, **kwargs):
        self.logger.log(level, message, *args, **kwargs)

    def parse(self, response):
        raise NotImplementedError

    def start_requests(self):
        raise NotImplementedError

    def open(self):
        pass

    def close(self):
        pass

    async def request_success(self, response):
        callback = response.request.callback
        if callback:
            res = self._get_mothod(callback)(response)
        else:
            res = self.parse(response)
        if inspect.iscoroutine(res):
            res = await res
        return res

    async def request_error(self, request, error):
        try:
            if request and request.errback:
                r = self._get_mothod(request.errback)(request, error)
                if inspect.iscoroutine(r):
                    await r
        except CancelledError:
            raise
        except Exception:
            log.warning("Error occurred in the error callback of spider", exc_info=True)

    def _get_mothod(self, method):
        if isinstance(method, str):
            method = getattr(self, method)
        return method

class RequestsSpider(Spider):
    def start_requests(self):
        requests = self.config.get('start_requests')
        i = 0
        for r in requests:
            if isinstance(r, str):
                r = HttpRequest(r)
            if isinstance(r, HttpRequest):
                r.meta['request_index'] = i
                r.dont_filter = True
                r.callback = self.parse
                r.errback = self.handle_error
                yield r
            else:
                self.logger.warning('Requests must be str or HttpRequest, got %s', type(r).__name__)
            i += 1

    def parse(self, response):
        results = self.config.get('results')
        results[response.meta['request_index']] = response

    def handle_error(self, request, err):
        results = self.config.get('results')
        results[request.meta['request_index']] = err

redpajama_set_name: RedPajamaGithub


text:
The Crossword Definition is a minimal object that defines the
crossword. It should have the following properties:

- crosswordDefinition.width: The width of the crossword.
- crosswordDefinition.height: The hight of the crossword.
- crosswordDefinition.acrossClues: The clues which go across.
- crosswordDefinition.downClues: The clues which go down.

Clues have the following fields:

- clue.number: The clue number.
- clue.length: The length, an array such as [6] or [4,2].
- clue.clue: The actual clue text.


text:
<?php $this->beginContent('application.modules_core.activity.views.activityLayout', array('activity' => $activity)); ?>
<?php
echo Yii::t('PostModule.views_activities_PostCreated', '%displayName% created a new post.', array(
    '%displayName%' => '<strong>' . CHtml::encode($user->displayName) . '</strong>'
));
?>
<?php $this->endContent(); ?>


text:
CKEDITOR.plugins.setLang( 'clipboard', 'da', {
	copy: 'Kopiér',
	copyError: 'Din browsers sikkerhedsindstillinger tillader ikke editoren at få automatisk adgang til udklipsholderen.

Brug i stedet tastaturet til at kopiere teksten (Ctrl/Cmd+C).',
	cut: 'Klip',
	cutError: 'Din browsers sikkerhedsindstillinger tillader ikke editoren at få automatisk adgang til udklipsholderen.

Brug i stedet tastaturet til at klippe teksten (Ctrl/Cmd+X).',
	paste: 'Indsæt',
	pasteArea: 'Indsæt område',
	pasteMsg: 'Indsæt i feltet herunder (Ctrl/Cmd+V) og klik på OK.',
	securityMsg: 'Din browsers sikkerhedsindstillinger tillader ikke editoren at få automatisk adgang til udklipsholderen.

Du skal indsætte udklipsholderens indhold i dette vindue igen.',
	title: 'Indsæt'
} );


text:
This is a simple and short library for C especially for Arrays.
I am working on developing and it will be way better in the next few days.
I accept all your suggestions.

For anything you can contact <young.khaled99@gmail.com>.


text:
package apple.coredata;

import java.io.*;
import java.nio.*;
import java.util.*;
import com.google.j2objc.annotations.*;
import com.google.j2objc.runtime.*;
import com.google.j2objc.runtime.block.*;
import apple.audiotoolbox.*;
import apple.corefoundation.*;
import apple.coregraphics.*;
import apple.coreservices.*;
import apple.foundation.*;

/**
 * @since Available in iOS 8.0 and later.
 */
@Library("CoreData/CoreData.h") @Mapping("NSAsynchronousFetchRequest")
public class NSAsynchronousFetchRequest
    extends NSPersistentStoreRequest
     {

    @Mapping("init")
    public NSAsynchronousFetchRequest() { }

    @Mapping("fetchRequest")
    public native NSFetchRequest getFetchRequest();
    @Mapping("completionBlock")
    public native @Block VoidBlock1<NSAsynchronousFetchResult> getCompletionBlock();
    @Mapping("estimatedResultCount")
    public native @MachineSizedSInt long getEstimatedResultCount();
    @Mapping("setEstimatedResultCount:")
    public native void setEstimatedResultCount(@MachineSizedSInt long v);

}


text:
package com.blochstech.bitcoincardterminal.Interfaces;

//TODO: Is this used? Delete it?
public enum CardState {
	NoCard,
	CardReady,
	CardConnected
}


text:
package com.planet_ink.coffee_mud.Abilities.Druid;
import com.planet_ink.coffee_mud.core.interfaces.*;
import com.planet_ink.coffee_mud.core.*;
import com.planet_ink.coffee_mud.Abilities.interfaces.*;
import com.planet_ink.coffee_mud.Areas.interfaces.*;
import com.planet_ink.coffee_mud.Behaviors.interfaces.*;
import com.planet_ink.coffee_mud.CharClasses.interfaces.*;
import com.planet_ink.coffee_mud.Commands.interfaces.*;
import com.planet_ink.coffee_mud.Common.interfaces.*;
import com.planet_ink.coffee_mud.Exits.interfaces.*;
import com.planet_ink.coffee_mud.Items.interfaces.*;
import com.planet_ink.coffee_mud.Locales.interfaces.*;
import com.planet_ink.coffee_mud.MOBS.interfaces.*;
import com.planet_ink.coffee_mud.Races.interfaces.*;

import java.util.*;

@SuppressWarnings("unchecked")
public class Chant_PrayerWard extends Chant
{
	public String ID() { return "Chant_PrayerWard"; }
	public String name(){return "Prayer Ward";}
	public String displayText(){return "(Prayer Ward)";}
	public int abstractQuality(){ return Ability.QUALITY_BENEFICIAL_SELF;}
	protected int canAffectCode(){return CAN_MOBS;}
    public int classificationCode(){return Ability.ACODE_CHANT|Ability.DOMAIN_PRESERVING;}

	public void unInvoke()
	{
		// undo the affects of this spell
		if((affected==null)||(!(affected instanceof MOB)))
			return;
		MOB mob=(MOB)affected;
		if(canBeUninvoked())
			mob.tell("Your ward against prayers fades.");

		super.unInvoke();

	}

    public int castingQuality(MOB mob, Environmental target)
    {
        if(mob!=null)
        {
            if(target instanceof MOB)
            {
                MOB victim=((MOB)target).getVictim();
                if((victim!=null)&&(CMLib.flags().domainAbilities(victim,Ability.ACODE_PRAYER).size()==0))
                    return Ability.QUALITY_INDIFFERENT;
            }
        }
        return super.castingQuality(mob,target);
    }

	public boolean okMessage(Environmental myHost, CMMsg msg)
	{
		if((affected==null)||(!(affected instanceof MOB)))
			return super.okMessage(myHost,msg);

		MOB mob=(MOB)affected;
		if((msg.amITarget(mob))
		&&(CMath.bset(msg.targetCode(),CMMsg.MASK_MALICIOUS))
		&&(msg.targetMinor()==CMMsg.TYP_CAST_SPELL)
		&&(msg.tool()!=null)
		&&(msg.tool() instanceof Ability)
		&&((((Ability)msg.tool()).classificationCode()&Ability.ALL_ACODES)==Ability.ACODE_PRAYER)
		&&(invoker!=null)
		&&(!mob.amDead())
		&&(CMLib.dice().rollPercentage()<35))
		{
			mob.location().show(mob,null,CMMsg.MSG_OK_VISUAL,"The ward around <S-NAME> inhibits "+msg.tool().name()+"!");
			return false;
		}
		return super.okMessage(myHost,msg);
	}

	public boolean invoke(MOB mob, Vector commands, Environmental givenTarget, boolean auto, int asLevel)
	{
		MOB target=mob;
		if((auto)&&(givenTarget!=null)&&(givenTarget instanceof MOB))
			target=(MOB)givenTarget;
		if(target.fetchEffect(ID())!=null)
		{
			mob.tell(target,null,null,"<S-NAME> <S-IS-ARE> already affected by "+name()+".");
			return false;
		}

		if(!super.invoke(mob,commands,givenTarget,auto,asLevel))
			return false;

		boolean success=proficiencyCheck(mob,0,auto);
		if(success)
		{
			CMMsg msg=CMClass.getMsg(mob,target,this,verbalCastCode(mob,target,auto),auto?"<T-NAME> <T-IS-ARE> protected from prayers.":"^S<S-NAME> chant(s) for a ward against prayers around <T-NAMESELF>.^?");
			if(mob.location().okMessage(mob,msg))
			{
				mob.location().send(mob,msg);
				beneficialAffect(mob,target,asLevel,0);
			}
		}
		else
			beneficialWordsFizzle(mob,target,"<S-NAME> chant(s) for a ward, but nothing happens.");

		return success;
	}
}


text:
include_recipe 'apt'
include_recipe 'zip'
include_recipe 'java' if node['wso2']['install_java']
include_recipe 'swap_tuning'


text:
from AppKit import *
import vanilla
from defconAppKit.windows.baseWindow import BaseWindowController
from mojo.events import addObserver, removeObserver
from robofab.glifLib import writeGlyphToString, readGlyphFromString

from defcon.objects.glyph import addRepresentationFactory

from lib.scripting.codeEditor import CodeEditor

from mojo.roboFont import CurrentGlyph, OpenWindow, RGlyph

def PlistFactory(glyph, font):
    return writeGlyphToString(glyph.name, glyph, glyph.drawPoints)

addRepresentationFactory("com.typemytype.GlyphXMLViewer", PlistFactory)

class GlyphXMLViewer(BaseWindowController):

    def __init__(self):
        self.currentGlyph = None
        self.w = vanilla.Window((500, 500), "Plist Viewer", minSize=(100, 100))
        self.w.xml = CodeEditor((0, 0, -0, -30), "", lexer="xml")

        self.w.applyButton = vanilla.Button((-70, -25, -20, 22), "Apply", callback=self.applyCallback, sizeStyle="small")
        addObserver(self, "currentGlyphChanged", "currentGlyphChanged")
        self.setUpBaseWindowBehavior()

        self.currentGlyphChanged({})

        self.w.open()

    def windowCloseCallback(self, sender):
        self._unsubscribeGlyph()
        removeObserver(self, "currentGlyphChanged")
        super(GlyphXMLViewer, self).windowCloseCallback(sender)

    def applyCallback(self, sender):
        if self.currentGlyph is not None:
            xml = self.w.xml.get()

            dummyGlyph = RGlyph()
            try:
                readGlyphFromString(str(xml), dummyGlyph, dummyGlyph.getPointPen())
            except:
                import traceback
                error = "A problem occured when trying to parse the glif plist."
                suggestion = traceback.format_exc(5)
                self.showMessage(error, suggestion)
                return

            self.currentGlyph.clear()
            readGlyphFromString(str(xml), self.currentGlyph, self.currentGlyph.getPointPen())

    def setXML(self):
        if self.currentGlyph is not None:
            xml = self.currentGlyph.naked().getRepresentation("com.typemytype.GlyphXMLViewer")
            self.w.xml.set(xml)

    def currentGlyphChanged(self, info):
        glyph = CurrentGlyph()

        if glyph == self.currentGlyph:
            return
        self._unsubscribeGlyph()
        if glyph is not None:
            self.subscribeGlyph(glyph)
            self.currentGlyph = glyph
            self.setXML()
        else:
            self.w.xml.set("")

    def _unsubscribeGlyph(self):
        if self.currentGlyph is not None:
            self.currentGlyph.removeObserver(self, "Glyph.Changed")
            self.currentGlyph = None

    def subscribeGlyph(self, glyph):
        if glyph is not None:
            glyph.addObserver(self, "_glyphChanged", "Glyph.Changed")

    def _glyphChanged(self, notification):
        self.setXML()

OpenWindow(GlyphXMLViewer)


text:
atf_test_case main
main_head()
{
    atf_set "descr" "Verifies that variable names with symbols not" \
                    "allowed as part of shell variable names work"
}
main_body()
{
    h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
    atf_check -s eq:0 -o match:'a.b: test value 1' \
        -o match:'c-d: test value 2' -e ignore ${h} normalize
}

atf_init_test_cases()
{
    atf_add_test_case main
}

# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4


text:
Insurance

RISE Physical Therapy is contracted with numerous health insurance providers to offer in-network physical therapy services.

These include, but are not limited to:

Commercial Plans

Aetna

Ameriplan USA

Anthem Blue Cross

ASH (American Specialty Health)

Beech Street

Capp Care & PPO Next

Blue Shield

California Foundation for Medical Care

Cigna

Community Health Group

HMO, Special Needs Plan, CalMediConnect

First Health

Fortified Provider Network

Freedom Physicians Corp

Galaxy Health Network

Global Excel Management

Great West

Health Management Association (HMA)

Health Net

HMO (where not capped)

Covered CA Plans (including Enhance Care PPO)

Pure Care

Comm. Care (Direct Network Only)

HHCG-PPN

Independent Medical Systems

IntegraHome

Integrated Health Plan

Molina Healthcare (IPO & Covered CA)

Multiplan

Network By Design

OccuNet

Pacific Health Alliance

Premier Access

Premier Provider Network

Primary Care Associates

Prime Health Services

Private Healthcare Systems (PHCS)

Provider Select Inc.

R2R USA

Scripps (PPO & EPO)

The Reny Company

The Health Connection

Three Rivers Provider Network

Union Roofers Health & Welfare Fund

United Healthcare

USA Managed Care Organization

Federal Plans

Blue Shield Federal

CHAMPVA

Department of Labor

Medicare

TRICARE

Medi-Medi Plans

TriWest

Worker's Comp. Plans

Align

Anthem MarketPlace Worker's Comp

Care IQ

Corvel

Employers

HealthSmart

InterMed Cost Containment Services

Key Risk Management Services (KRMS)

MedRisk

One Call

Orchid Medical

Paradigm Specialty Networks

Premier Comp Solutions

Procura

Rockport Healthcare Group

Southern California Edison

Status Medical Management

Workwell Systems

Zelis

We also offer affordable cash rates for all physical therapy and performance training services. Contact us to learn more.


text:
package cz.tomkren.kutil2.core;

import java.awt.Color;
import java.awt.Graphics2D;

import java.util.*;

import cz.tomkren.helpers.Log;
import cz.tomkren.kutil2.items.*;
import cz.tomkren.kutil2.kevents.*;
import cz.tomkren.kutil2.kobjects.frame.Frame;
import net.phys2d.math.ROVector2f;
import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;
import net.phys2d.raw.StaticBody;
import net.phys2d.raw.World;
import net.phys2d.raw.shapes.DynamicShape;
import net.phys2d.raw.strategies.QuadSpaceStrategy;

/** TODO */
public class KObject implements KAttVal {

    private Kutil kutil;

    private KObject                 parent;     // objekt, v jehož vnitřku je tento object

    private Items                   items;      // drží všechny položky tohoto objektu pohromadě
    private KItem<List<KObject>>    inside;     // objekty tvořící vnitřek tohoto objektu
    private KItem<String>           type;       // typ tohoto objektu
    private KItem<String>           id;         // id tohoto objektu

    private KItem<Int2D>            pos;        // fyzická pozice tohoto objektu
    private KItem<String>           shapeCmd;   // příkaz definující tvar objektu
    private KItem<Boolean>          physical;   // určuje zda se jedná o fyzickální objekt
    private KItem<Boolean>          attached;   // určuje zda je fyzický objekt nepohyblivý(pro nefyz.nemá význam)

    private KItem<Boolean>          movable;    // určuje zda je možno objektem hýbat myší
    private KItem<Boolean>          rotable;    // určuje zda objekt může být rotován - true nedoporučeno
    private KItem<Boolean>          guiStuff;   // určuje zda je tento objekt součást gui a tedy s ním nejdou některé nepříjemnosti (smazat, vylézt nad)

    private KItem<Boolean>          main;       // určuje, zda se jedná o hlavní objekt

    private World   world;                // fyzikální simulace uvnitř objektu
    private Body    body;                 // těleso reprezentující tento objekt ve vnitřku parent objektu
    private boolean isAffectedByGravity;  // určuje, zda je objekt ovlivněn gravitací

    private KShape  shape;              // tvar objektu
    private boolean stepInside;         // určuje, zda je vnitřním objektům tohoto objektu posílaná instrukce na udělání kroku
    private double  rot;                // rotace objektu
    private Color   bgcolor;            // barva pozadí vnitřku
    private boolean isHighlighted ;     // udává, zda je objekt zvýrazněn (při o značení např.)

    private List<KObject> objectsToAdd;    //objekty čekající na přidaní na poslední místo do vnitřku
    private List<KObject> objectsToRemove; //objekty čekající na vymazání z vnitřku

    private String  oldCopyId;     // pomocná proměnná používaná při kopírování objektů
    private boolean isInitialised; // určuje zda už proběhla inicializace metodou init() // todo k čemu to tu vlastně je ???? PRavděpodobně hax pro: insertKObjectToSystem

    public KObject(KAtts kAtts, Kutil kutil) {
        this.kutil = kutil;

        items = new Items();

        type   = items.addString(kAtts, "type", null);
        id     = items.addString(kAtts, "id", null);
        inside = items.addList(kAtts, "inside");

        pos      = items.addInt2D(kAtts, "pos", Int2D.zero());
        shapeCmd = items.addString(kAtts, "shape", null);
        physical = items.addBoolean(kAtts, "physical", false);
        attached = items.addBoolean(kAtts, "attached", false);
        movable  = items.addBoolean(kAtts, "movable", true);
        rotable  = items.addBoolean(kAtts, "rotable", false);
        guiStuff = items.addBoolean(kAtts, "guiStuff", false);
        main     = items.addBoolean(kAtts, "main", false);

        create();
    }

    // TODO | bylo zatím používáno jen v Text, který už není KOBject, pokudmožno uplně odstranit, ale nejprve prozkoumat, zda není potřeba v budoucnu jinde
    // todo | No používá se to pro dědice co potřebujou vznikat např Kispem, aka Box()...
    /*
    public KObject(Kutil kutil){
        this.kutil = kutil;

        items = new Items();

        type    = items.add("type", null);
        id      = items.add("id", null);
        inside  = items.addEmptyList("inside");

        pos      = items.add("pos", Int2D.zero());
        shapeCmd = items.add("shape", null);
        physical = items.add("physical", false, false);
        attached = items.add("attached", false, false);
        movable  = items.add("movable", true, true);
        rotable  = items.add("rotable", false, false);
        guiStuff = items.add("guiStuff", false, false);
        main     = items.add("main", false, false);

        create();
    }
    */

    public KObject copy() {return new KObject(this, kutil);}

    // TODO celý nějaký podezřelý, maj ostatní taky kopírovací konstruktory?? něšlo by to automatizovaně přes xml-string repre s dodatečnym updatama líp?  atd... PROMYSLET
    // TODO nestrácí to třeba ty vlastnosti co tomu přidá potomek bez overdajdlího kopírovacího konstruktoru??? atd
    public KObject(KObject b, Kutil kutil) {
        this.kutil = kutil;

        items = new Items();

        type     = items.add("type", null);
        id       = items.add("id", null);
        inside   = items.addEmptyList("inside");

        pos      = items.add("pos", b.pos.get().copy());
        shapeCmd = items.add("shape", b.shapeCmd.get());
        physical = items.add("physical", b.physical.get(), false);
        attached = items.add("attached", b.attached.get(), false);
        movable  = items.add("movable", b.movable.get(), true);
        rotable  = items.add("rotable", b.rotable.get(), false);
        guiStuff = items.add("guiStuff", b.guiStuff.get(), false);
        main     = items.add("main", b.main.get(), false);

        for (KObject o :  b.inside()) {
            KObject copy = o.copy();
            inside.get().add(copy);
        }

        oldCopyId = b.id();

        create();
    }

    private void create() {
        /* TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */

        isInitialised = false;

        if (main.get()) {
            rucksack().setMain(this);
        }

        shape = kutil.shapeFactory().newKShape(shapeCmd.get(), kutil);

        stepInside = true;

        bgcolor = Color.white; // TODO prozatímní zjednodušení !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        rot = 0f;

        isAffectedByGravity = true;

        world = new World( new Vector2f(0.0f, 10.0f), 10, new QuadSpaceStrategy(20,5) );

        objectsToAdd    = new ArrayList<>();
        objectsToRemove = new ArrayList<>();
    }

    /** Tato metoda je volána při vytváření objektu pro informovaní objektu o jeho rodiči. */
    public void parentInfo(KObject parent) {
        this.parent = parent;
        inside.get().forEach(o -> o.parentInfo(this));
    }

    /** Voláním této metody se dokončí druhá fáze inicializace objektu. */
    public void init() {

        if (isInitialised) {return;}
        isInitialised = true;

        // pokud objekt nemá explicitní id, dostane nějaké přiděleno.
        if (id.get() == null) {
            id.set( idDB().getUniqueID() );
            idDB().put(id.get(), this);
            Log.it("přidáno implicitní id " + id.get());
        }

        // pokud tento objekt vznikl jako kopie
        if (isCopied()) {
            kutil().getIdChangeDB().put(oldCopyId, id.get());
        }

        // pokud se jedná o fyzikální objekt:
        // - vytvoříme vhodné fyzikální těleso
        // - toto těleso vložíme do světa parent objektu
        if (physical.get()) {

            DynamicShape phys2dShape = shape.getPhys2dShape();
            body = attached.get() ? new StaticBody(phys2dShape) : new Body(phys2dShape, 100.0f);

            body.setGravityEffected(isAffectedByGravity);
            body.setRotatable(rotable.get());
            body.setUserData(this);

            setBodyPos(pos.get());

            World parentWorld = getParentWorld();
            if( parentWorld != null ){
                parentWorld.add(body);
            }
        }

        /* todo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        if( onInit.get() != null ){
            Global.rucksack().cmd( onInit.get() );
        }
        */

        inside.get().forEach(KObject::init);

    }

    public void step() {

        // TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! zkopčeno jen minimum, potřeba rozšířit pak !!!!!!!!!!!!!!!!!!!!!!

        if (physical.get()) {
            pos.set( shape.getPosByPhys2dCenter(body.getPosition()) );
            rot = body.getRotation();
        }

        if (stepInside && rucksack().isSimulationRunning() && world.getBodies().size() > 0) {
            world.step();
            world.step();
            world.step();
            world.step();
            world.step();
        }

        if (!objectsToRemove.isEmpty()) {
            internalRemove();
        }

        if(!objectsToAdd.isEmpty()) {
            internalAdd();
        }

        if (stepInside) {
            for (KObject o : inside.get()) {
                o.step();
                /* TODO !!!
                if( o instanceof Field ) manageField( (Field) o );
                */
            }
        }

    }

    public void setType(String t) {type.set(t);}

    public KObject parent(){return parent;}
    public void setParent( KObject newParent ){parent = newParent;}

    public String id(){return id.get();}
    public Items items() {return items;}
    public List<KObject> inside(){return inside.get();}

    public Kutil kutil() {return kutil;}
    public Rucksack rucksack() {return kutil.rucksack();}
    public IdDB idDB() {return kutil.getIdDB();}

    /** Vrací zda tento objekt vznikl kopírováním. */
    public boolean isCopied() {
        return oldCopyId != null;
    }

    /**
     * Pokud objekt potřebuje zareagovat na to, že byl zkopírován, dělá to v této metodě. Tato metoda volá tuto metodu svých vnitřních objektů.
     * TODO adept na zneškodnění nebo nějak elegantnějc celý spolčně s insertKObjectToSystem kterej to volá
     */
    public void resolveCopying() {
        if (isCopied()) {
            inside.get().forEach(KObject::resolveCopying);
        }
    }

    // TODO nové, pokus vyřešit problém při undo, lépe pojmenovat začlenit etc
    public void resolveCopying_2(Set<String> ids) {
        inside().forEach(o -> o.resolveCopying_2(ids));
    }

    //POZN nové (#k2), pokus vyřešit problém při undo
    public Set<String> getIds() {
        Set<String> ids = new HashSet<>();
        addIds(ids);
        return ids;
    }
    private void addIds(Set<String> ids) {
        ids.add(id.get());
        inside().forEach(o -> o.addIds(ids));
    }

    public KShape shape() {return shape;}

    public Int2D pos() {return pos.get();}

    public void setPos( Int2D p ){
        pos.set(p);
        setBodyPos(p);
    }

    public boolean getIsMovable(){return movable.get();}
    public void setMovable (boolean b) {movable.set(b);}

    public boolean getIsGuiStuff() {return guiStuff.get();}
    public void setIsGuiStuff(boolean b){
        guiStuff.set(b);
    }

    public Color bgcolor(){
        return bgcolor;
    }

    public void setHighlighted(boolean isHighlighted) {this.isHighlighted = isHighlighted;}
    public boolean isHighlighted() {return isHighlighted;}

    // --- PHYS STUFF ---

    public boolean isPhysical() {return physical.get();}
    public void setIsAffectedByGravity(boolean b) {isAffectedByGravity = b;}

    public Body getBody(){return body;}

    private void setBodyPos(Int2D newPos) {
        if (body == null) {return;}
        ROVector2f bodyPos = shape.getPhys2dCenter(newPos);
        body.setPosition(bodyPos.getX(), bodyPos.getY());
    }

    public void setSpeed( Int2D v ){
        if (body == null) {return;}
        ROVector2f vel = body.getVelocity();
        body.adjustVelocity(new Vector2f(v.getX() - vel.getX(), v.getY() - vel.getY()));
    }

    public World getWorld(){return world;}

    public World getParentWorld(){
        if( parent != null ){
            return parent.getWorld();
        }
        return null;
    }

    public void drawInside(Graphics2D g, Int2D center, int frameDepth, double zoom, Int2D zoomCenter) {
        for (KObject o : inside.get()) {
            o.drawOutside(g, center, frameDepth, zoom, zoomCenter);
        }
    }

    public void drawOutside(Graphics2D g, Int2D center, int frameDepth, double zoom, Int2D zoomCenter) {
        shape.draw(g, isHighlighted, rucksack().showInfo() ? getInfoString() : null , pos.get(), center, rot, rotable.get(), zoom, zoomCenter);
    }

    public String getInfoString() {
        return id.get() + " ["+pos.get()+"]";
    }

    public Xml toXml(){
        XmlElement ret = new XmlElement(XmlLoader.OBJECT_TAG);
        items.addAttsToXmlElement(ret);
        return ret;
    }

    /**
     * Vrací, zda je objekt zasažen kliknutím.
     * @param clickPos pozice kliknutí
     * @return zda byl objekt zasažen
     */
    public boolean isHit(Int2D clickPos, double zoom, Int2D center) {
        return shape.isHit(pos.get(), clickPos, rot, zoom, center);
    }

    /**
     * Reaguje na událost uvnitř objektu.
     * @param kEvent událost, na kterou se má reagovat
     */
    public void event(KEvent kEvent, double zoom, Int2D center) {
        if      (kEvent instanceof ClickEvent)  { clickEvent  ((ClickEvent)   kEvent, zoom, center);} // todo megahnus to předávání zoom a center, dat do eventu pokud potřeba!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        else if (kEvent instanceof DragEvent)   { dragEvent   ((DragEvent)    kEvent, zoom, center);}
        else if (kEvent instanceof ReleaseEvent){ releaseEvent((ReleaseEvent) kEvent, zoom, center);}
        else if (kEvent instanceof WheelEvent)  { wheelEvent  ((WheelEvent)   kEvent, zoom, center);}
    }

    private ListIterator<KObject> getLastIteratorOfInside() {
        List<KObject> xs = inside.get();
        return xs.listIterator(xs.size());
    }

    private void wheelEvent(WheelEvent e, double zoom, Int2D center) {
        // TODO co sem patří ??

        ListIterator<KObject> iter = getLastIteratorOfInside(); //TODO bylo tady a dále (kdyby zlobilo tak možna pro tyto změny) inside.get().descendingIterator(); obdobne bylo next hasNext...
        while ( iter.hasPrevious() ){
            KObject o = iter.previous();
            if( o.isHit(e.getPos(), zoom, center) ){
                o.wheel(e.getPos());
                return;
            }
        }

    }

    private void clickEvent(ClickEvent e, double zoom, Int2D center) {

        rucksack().setSelectedFrame(e.getFrame());

        ListIterator<KObject> iter = getLastIteratorOfInside(); //TODO bylo tady a dále (kdyby zlobilo tak možna pro tyto změny) inside.get().descendingIterator(); obdobne bylo next hasNext...
        while ( iter.hasPrevious() ){
            KObject o = iter.previous();
            if( o.isHit(e.getPos(), zoom, center) ){
                o.click(e.getPos());
                return;
            }
        }
        rucksack().setSelected( e.getFrame() );
    }

    private void dragEvent(DragEvent e, double zoom, Int2D center) {

        rucksack().setSelectedFrame( e.getFrame() );
        rucksack().onDrag(e.getPos());

        ListIterator<KObject> iter = getLastIteratorOfInside(); // inside.get().descendingIterator();
        while ( iter.hasPrevious() ){
            //try {
                KObject o = iter.previous();

                if( o.isHit(e.getPos(),zoom, center)) {
                    o.drag(e.getPos(), e.getDelta(), e.getFrame());
                    return;
                }
            //} catch (ConcurrentModificationException ex) {
            //    Log.it("Bacha, dragovací eksepšn brácho!");
            //}
        }
        if( ! rucksack().somethingOnCursor() ){
            e.getFrame().moveCam(e.getDelta());
        }
        rucksack().setSelected( e.getFrame() );
    }

    private void releaseEvent(ReleaseEvent e, double zoom, Int2D center){

        ListIterator<KObject> iter = getLastIteratorOfInside(); // inside.get().descendingIterator();
        while ( iter.hasPrevious() ){
            KObject o = iter.previous();
            if( o.isHit( e.getPos(), zoom, center) ){

                if( !(this instanceof Frame ) && ! o.getIsMovable()) {

                    //Log.it("1");

                    rucksack().pasteFromCursor(this, e.getPos() );
                    return;
                }

                //Log.it("2");

                o.release(e.getPos(),this);

                return;
            }
        }

        //Log.it("3");
        rucksack().pasteFromCursor(this, e.getPos());
    }

    /**
     * Reakce na táhnutí myši na samotném objektu (na jeho vnějšku).
     * @param clickPos pozice začátku táhnutí
     * @param delta vektor táhnutí (kolik se táhlo)
     */
    public void drag(Int2D clickPos, Int2D delta, Frame f) {
        if (movable.get()) {
            rucksack().cutToCursor(this , clickPos);
        }
        else{
            if( rucksack().somethingOnCursor() ) return;
            rucksack().setSelected(this);
            f.moveCam(delta);
        }
    }

    /**
     * Reakce na kliknutí myši na samotném objektu (na jeho vnějšku).
     * @param clickPos pozice kliknutí
     */
    public void click(Int2D clickPos) {
        rucksack().setSelected(this);
    }

    public void wheel(Int2D wheelPos) {
        // asi nic ale ve framu se overridne
    }

    /**
     * Reakce na pustění tlačítka myši na samotném objektu (na jeho vnějšku).
     * @param clickPos pozice puštění
     */
    public void release(Int2D clickPos , KObject obj ){
        //rucksack().pasteFromCursor(this , Int2D.zero ); //pokud tam je tak umožnuje vkladat dovnitř
        // objektu pouhým přetažením

        rucksack().pasteFromCursor(obj, clickPos);
    }

    // ============= přidávání mazání etc =============  TODO chtělo by nějakou pořádnou revizi imho

    // -- Přidávání --

    /**
     * Přidá daný objekt do vntřku (na konec) tohoto objektu.
     * @param o objekt k přidání
     */
    public void add(KObject o) {
        objectsToAdd.add(o);
    }

    private void internalAdd() {
        for( KObject o : objectsToAdd ){
            if (o.isPhysical()) {
                world.add(o.getBody());
            }
            inside.get().add(o);
        }
        objectsToAdd.clear();
    }

    // -- Mazání --

    /** Úplně smaže objekt. */
    public void delete(){
        remove();
        idDB().remove(id());
    }

    /** Odstraní objekt ze svého rodiče. */
    public void remove(){
        if( parent != null ){
            parent.remove(this);
        }
    }

    /**
     * Odstraní daný objekt z vntřku tohoto objektu.
     * @param o objekt k vymazání
     */
    public void remove(KObject o) {
        objectsToRemove.add(o);
    }

    private void internalRemove(){

        for (KObject o : objectsToRemove) {

            /* TODO field stuff ... !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            for( KObject f : inside.get() ){
                if( f instanceof Field ) ( (Field) f ).informFieldAboutDeletation(o);
            }
            */

            if (o.isPhysical()) {
                world.remove(o.getBody());
            }
            inside.get().remove(o);
        }

        objectsToRemove.clear();
    }

}


text:
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" media="screen" href="<?php echo base_url().'content/bootstrap/css/bootstrap.css'; ?>">
    <link rel="stylesheet" media="screen" href="<?php echo base_url(); ?>content/bnw/styles/dashBoardStyles.css" type="text/css" />
    <link rel="stylesheet" media="screen" href="<?php echo base_url(); ?>content/bnw/styles/stylesForGadgets.css" type="text/css" />

    <link rel="stylesheet" type="text/css" href="<?php echo base_url() . 'content/bnw/styles/imgareaselect-animated.css'; ?>" />
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">

    <?php
    if (isset($meta)) {
        foreach ($meta as $data) {
            $title[] = $data->value;// isssue of title is solved
        }
    }
    ?>
    <title><?php echo $title[1]; ?></title>

          <button type="button" class="navbar-toggle" id="togglemenu" data-toggle="collapse" data-target="#myNavbar">

        </button>
      <a href="<?php echo base_url('bnw'); ?>"> <img style="height:43px;" src="<?php echo base_url() . "content/bnw/images/bnw.png"; ?>"/>
       <img style="height:43px;" src="<?php echo base_url() . "content/bnw/images/toggle.png"; ?>"/>

<a id="switchlink" href="<?php echo base_url(); ?>" target="_blank" > View Site

 Add new

                <a href="<?php echo base_url('offers/addpost'); ?>">

                    Post
                    <a href="<?php echo base_url('page/addpage'); ?>">
                        Page
                        <a href="<?php echo base_url('media/addmedia'); ?>">
                            Media
                            <a href="<?php echo base_url('user/adduser'); ?>">
                                User

                 <?php if ($this->session->userdata('admin_logged_in')) { ?>
                 <?php $username= $this->session->userdata('username'); ?>

                    hellow, <?php echo $username; ?>

                      <a href="<?php echo base_url('login/logout'); ?>" > Logout

              <?php } ?>


text:
See the Tag Data Translation Standard

#### Example: Translating EPC code to GS1 scheme (giai-202)
````
EPCTagEngine eng = new EPCTagEngine("383559CCA5AB56EC183072E583060E5CB76EE1B346CD9A800000");

  TDTScheme sc = eng.getScheme();
  System.out.println(sc.getName() + " (" + sc.getFriendlyName()+")");
  System.out.println("PureURI=" + eng.buildPureIdentityURI());
  System.out.println("TagURI=" + eng.buildTagURI());
  System.out.println(eng.getSegmentName(0) + ":" + eng.getSegment(0).toString());
  System.out.println(eng.getSegmentName(1) + ":" + eng.getSegment(1).toString());
````

 Output:
 ````
 giai-202 (Global Individual Asset Identifier)
 PureURI=urn:epc:id:giai:5665577.557000990009977864665
 TagURI=urn:epc:tag:giai-202:1.5665577.557000990009977864665
 Company Prefix:5665577
 Individual Asset Reference:557000990009977864665
 ````


text:
function setup(){
 createCanvas(100,100);
 smooth();
};

function draw(){
  background(255);
  drawBlackCircle();
};

var drawBlackCircle = function() {
  fill(0);
  ellipse(50,50,20,20);
};


text:
//
//  HCSearchBar.m
//  HCSinaWeibo
//
//  Created by tunny on 15/6/18.
//  Copyright (c) 2015年 tunny. All rights reserved.
//

#import "HCSearchBarView.h"

@implementation HCSearchBarView

/**
 *  创建一个搜索框
 *
 *  @param frame 搜索框的尺寸和位置
 *
 *  @return searchBar
 */
+ (instancetype)searchBarWithFrame:(CGRect)frame
{
    //searchbar basic
    HCSearchBarView *searchBar = [[HCSearchBarView alloc] init];
    searchBar.frame = frame;
    searchBar.background = [UIImage imageNamed:@"searchbar_textfield_background"];
    searchBar.font = [UIFont systemFontOfSize:15];
    searchBar.placeholder = @"请输入搜索条件";

    //leftView
    UIImageView *searchIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    searchIcon.image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
    searchIcon.contentMode = UIViewContentModeCenter;

    searchBar.leftView = searchIcon;
    searchBar.leftViewMode = UITextFieldViewModeAlways;

    return searchBar;
}

@end


text:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>edu.ustc.mix</groupId>
		<artifactId>mix-parent</artifactId>
		<version>1.0.0</version>
		<relativePath>../pom.xml</relativePath>
	</parent>

	<artifactId>mix-service-public</artifactId>

	<build>
		<finalName>mix-service-public</finalName>
	</build>
</project>


text:
package ru.org.sevn.winplay;

//http://download.videolan.org/pub/videolan/vlc/last/win64/

public class App {
    public static void main( String[] args ) throws Exception {
//    	VideoExample.artwork();
        Mp34PlayerFrame.runMain();
//        NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), LIB_PATH_LOC);
//        System.out.println(LibVlc.INSTANCE.libvlc_get_version());
    }
}


text:
title: "Archive"
tagline: "The compiled writing portfolio."
description: "A collection of writings and tutorials that mostly focusses about stock market, front-end web development, and positive living."
layout: page
archive: true
feature_image: "/assets/img/archive.jpg"
permalink: "/archive/"
redirect_from: "/archives/"
---

{% for post in site.posts %}

  {% unless post.next %}

{{ post.date | date: '%Y' }}

  {% else %}
    {%- capture year -%}{{ post.date | date: '%Y' }}{%- endcapture -%}
    {%- capture nyear -%}{{ post.next.date | date: '%Y' }}{%- endcapture -%}
    {% if year != nyear %}

{{ post.date | date: '%Y' }}

    {% endif %}
  {% endunless %}

          {{ post.title | smartify | strip_html | normalize_whitespace | escape_once }}

        <time class="dt-published" datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: '%b %-d, %Y' }}</time>

  {% if post.last_modified_at %}<time class="dt-updated" style="display: none;" datetime="{{ post.last_modified_at | date_to_xmlschema }}">{{ post.last_modified_at | date: '%b %-d, %Y' }}</time>{% endif %}

{% endfor %}


text:
cask :v1 => 'codebox' do
  version :latest
  sha256 :no_check

  url 'https://www.codebox.io/download/mac'
  homepage 'https://www.codebox.io'
  license :unknown

  app 'Codebox.app'
end