Пример #1
0
def urlquote(s, safe=''):
    """Quote all reserved characters according to RFC3986 unless told otherwise.

       The urllib.urlquote has a weird default which excludes '/' from
       quoting even though it is a reserved character.  We would never
       want this when encoding elements in Deriva REST API URLs, so
       this wrapper changes the default to have no declared safe
       characters.

    """
    return _urlquote(s.encode('utf-8'), safe=safe)
Пример #2
0
 def urlquote(url, safe='/', **kwargs):
     safe += '~'
     return _urlquote(url, safe=safe, **kwargs)
Пример #3
0
    def as_xml(self, seqno, sample_id, indent_level=1, print_xml=False):
        """
        Build an XML string representation of this AcquisitionActivity (for
        use in instances of the NexusLIMS schema)

        Parameters
        ----------
        seqno : int
            An integer number representing what number activity this is in a
            sequence of activities.
        sample_id : str
            A unique identifier pointing to a sample identifier. No checks
            are done on this value; it is merely reproduced in the XML output
        indent_level : int
            (Default is 1) the level of indentation to use in exporting. If
            0, no lines will be indented. A value of 1 should be appropriate
            for most cases as used in the Nexus schema
        print_xml : bool
            Whether to print the XML output to the console or not (Default:
            False)

        Returns
        -------
        activity_xml : str
            A string representing this AcquisitionActivity (note: is not a
            properly-formed complete XML document since it does not have a
            header or namespace definitions)
        """

        aqAc_xml = ''
        INDENT = '  ' * indent_level
        line_ending = '\n'

        aqAc_xml += f'{INDENT}<acquisitionActivity seqno="{seqno}">{line_ending}'
        aqAc_xml += f'{INDENT*2}<startTime>{self.start.isoformat()}' \
                        f'</startTime>{line_ending}'
        aqAc_xml += f'{INDENT*2}<sampleID>{sample_id}</sampleID>{line_ending}'
        aqAc_xml += f'{INDENT*2}<setup>{line_ending}'
        for pk, pv in sorted(self.setup_params.items(),
                             key=lambda i: i[0].lower()):
            # metadata values to skip in XML output
            if pk in ['warnings', 'DatasetType']:
                pass
            else:
                if isinstance(pv, str) and any(c in pv for c in '<&'):
                    pv = escape(pv)
                # for setup parameters, a key in the first dataset's warning
                # list is the same as in all of them
                pk_warning = pk in self.warnings[0]
                aqAc_xml += f'{INDENT*3}<param name="{pk}"' + \
                            (' warning="true">' if pk_warning else '>') + \
                            f'{pv}</param>{line_ending}'
        aqAc_xml += f'{INDENT*2}</setup>{line_ending}'

        for f, m, um, w in zip(self.files, self.meta, self.unique_meta,
                               self.warnings):
            # escape any bad characters in the filename
            if isinstance(f, str) and any(c in f for c in '<&'):
                f = escape(f)

            # build path to thumbnail
            rel_fname = f.replace(_os.environ["mmfnexus_path"], '')
            rel_thumb_name = f'{rel_fname}.thumb.png'

            # encode for safe URLs
            rel_fname = _urlquote(rel_fname)
            rel_thumb_name = _urlquote(rel_thumb_name)

            # f is string; um is a dictionary, w is a list
            aqAc_xml += f'{INDENT*2}<dataset ' \
                        f'type="{m["DatasetType"]}" ' \
                        f'role="Experimental">{line_ending}'
            aqAc_xml += f'{INDENT*3}<name>{_os.path.basename(f)}' \
                        f'</name>{line_ending}'
            aqAc_xml += f'{INDENT*3}<location>{rel_fname}' \
                        f'</location>{line_ending}'
            aqAc_xml += f'{INDENT*3}<preview>{rel_thumb_name}' \
                        f'</preview>{line_ending}'
            for meta_k, meta_v in sorted(um.items(),
                                         key=lambda i: i[0].lower()):
                if meta_k in ['warnings', 'DatasetType']:
                    pass
                else:
                    if isinstance(meta_v, str) and \
                            any(c in meta_v for c in '<&'):
                        meta_v = escape(meta_v)
                    meta_k_warning = meta_k in w
                    aqAc_xml += f'{INDENT*3}<meta name="{meta_k}"' + \
                                (' warning="true">' if
                                 meta_k_warning else '>') + \
                                f'{meta_v}</meta>{line_ending}'
            aqAc_xml += f'{INDENT*2}</dataset>{line_ending}'

        aqAc_xml += f'{INDENT}</acquisitionActivity>{line_ending}'

        if print_xml:
            print(aqAc_xml)

        return aqAc_xml
Пример #4
0
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from urllib.parse import quote_plus as _urlquote

from . import _utils
from .base import *


DATABASE_URI = 'postgres://{username}:{password}@{host}:{port}/{database}'.format(
    host=_utils.VCAP.SERVICES['pz-postgres.credentials.hostname'],
    port=_utils.VCAP.SERVICES['pz-postgres.credentials.port'],
    database=_utils.VCAP.SERVICES['pz-postgres.credentials.database'],
    username=_utils.VCAP.SERVICES['pz-postgres.credentials.username'],
    password=_urlquote(_utils.VCAP.SERVICES['pz-postgres.credentials.password']),
)

SECRET_KEY  = os.urandom(32).hex()

CATALOG_SCHEME = 'https'
CATALOG_HOST   = os.getenv('CATALOG_HOST')

PIAZZA_SCHEME  = 'https'
PIAZZA_HOST    = os.getenv('PIAZZA_HOST')
PIAZZA_API_KEY = os.getenv('PIAZZA_API_KEY')

GEOSERVER_SCHEME   = 'http'
GEOSERVER_HOST     = _utils.VCAP.SERVICES['pz-geoserver-efs.credentials.hostname']
GEOSERVER_USERNAME = _utils.VCAP.SERVICES['pz-geoserver-efs.credentials.username']
GEOSERVER_PASSWORD = _utils.VCAP.SERVICES['pz-geoserver-efs.credentials.password']