Return a unicode object with the Gremlin representation of this block.
541280
def to_gremlin(self):
        """"""
        self.validate()
        if self.optional:
            # Optional edges have to be handled differently than non-optionals, since the compiler
            # provides the guarantee that properties read from an optional, non-existing location
            # always resolve to a "null" value. This guarantee is not upheld by default by Gremlin;
            # in fact, Gremlin .as('foo').out().as('bar').optional('foo') does not provide
            # ANY guarantees as to what the value at any "bar.*" is -- it could be "null",
            # it could be a previous pipeline element's location at "bar.*" or anything else.
            # The .ifThenElse block ensures that the edge traversal happens only if the edge exists,
            # and that otherwise the result in the pipeline is replaced with "null".
            #
            # The code below makes the assumption that links to outward/inward edges are stored
            # as vertex properties named "<direction>_<edge_name>" where direction is "in" or "out".
            # For example, the links to outward edges named "Person_SpeechBy" from Person
            # are assumed to be stored as "out_Person_SpeechBy" on the Person node.
            return (u'ifThenElse{{it.{direction}_{edge_name} == null}}'
                    u'{{null}}{{it.{direction}({edge_quoted})}}'.format(
                        direction=self.direction,
                        edge_name=self.edge_name,
                        edge_quoted=safe_quoted_string(self.edge_name)))
        elif self.within_optional_scope:
            # During a traversal, the pipeline element may be null.
            # The following code returns null when the current pipeline entity is null
            # (an optional edge did not exist at some earlier traverse).
            # Otherwise it performs a normal traversal (previous optional edge did exist).
            return (u'ifThenElse{{it == null}}'
                    u'{{null}}{{it.{direction}({edge_quoted})}}'.format(
                        direction=self.direction,
                        edge_quoted=safe_quoted_string(self.edge_name)))
        else:
            return u'{direction}({edge})'.format(
                direction=self.direction,
                edge=safe_quoted_string(self.edge_name))
1192041
def to_python(self, data):
        
        if data is None:
            return u''
        if isinstance(data, unicode):
            return data
        else:
            return unicode(data, DEFAULT_ENCODING)
20086
def recursive_unicode(obj):
    
    if isinstance(obj, dict):
        return dict((recursive_unicode(k), recursive_unicode(v)) for (k, v) in obj.items())
    elif isinstance(obj, list):
        return list(recursive_unicode(i) for i in obj)
    elif isinstance(obj, tuple):
        return tuple(recursive_unicode(i) for i in obj)
    elif isinstance(obj, bytes_type):
        return to_unicode(obj)
    else:
        return obj
1307783
def unicode2str(content):
    """"""
    if isinstance(content, dict):
        result = {}
        for key in content.keys():
            result[unicode2str(key)] = unicode2str(content[key])
        return result
    elif isinstance(content, list):
        return [unicode2str(element) for element in content]
    elif isinstance(content, int) or isinstance(content, float):
        return content
    else:
        return content.encode("utf-8")
49307
def _unicode_to_native(s):
  """"""
  if six.PY2:
    return s.encode("utf-8") if isinstance(s, unicode) else s
  else:
    return s
518301
def to_gremlin(self):
        """"""
        self.validate()

        mark_name, field_name = self.location.get_location_name()
        validate_safe_string(mark_name)
        validate_safe_string(field_name)

        if '@' in field_name:
            template = u'm.{mark_name}[\'{field_name}\']'
        else:
            template = u'm.{mark_name}.{field_name}'

        format_value = None
        stripped_field_type = strip_non_null_from_type(self.field_type)
        if GraphQLDate.is_same_type(stripped_field_type):
            template += '.format("{format}")'
            format_value = STANDARD_DATE_FORMAT
        elif GraphQLDateTime.is_same_type(stripped_field_type):
            template += '.format("{format}")'
            format_value = STANDARD_DATETIME_FORMAT

        return template.format(mark_name=mark_name, field_name=field_name,
                               format=format_value)
81467
def get_unicode(data):
    
    # if this is a common string, return its unicode representation
    if isinstance(data, str):
        return safe_unicode(data)

    # if this is a list of values, return list of unicode values
    if isinstance(data, list):
        return [get_unicode(item) for item in data]

    # if this is a dictionary, return dictionary of unicode keys and values
    if isinstance(data, dict):
        return {
            get_unicode(key): get_unicode(value)
            for key, value in data.iteritems()
        }
    # if it's anything else, return it in its original form
    return data
598135
def to_unicode(text):
    
    if not isinstance(text, str):
        tmpl = 'expected unicode string, got %s value %s'
        raise TypeError(tmpl % (type(text), text))
    return text
594507
def u2s(self,u):
		""""""

		try:
			return u.encode('utf-8',errors='ignore')
		except (UnicodeDecodeError,AttributeError) as e:
			try:
				return str(u)
			except UnicodeEncodeError:
				return unicode(u).encode('utf-8',errors='ignore')
472056
def _decode(obj):  # type: (bytes or str or unicode or object) -> unicode # noqa ignore=F821
    
    if obj is None:
        return u''
    if six.PY3 and isinstance(obj, six.binary_type):
        # transforms a byte string (b'') in unicode
        return obj.decode('latin1')
    elif six.PY3:
        # PY3 strings are unicode.
        return str(obj)
    elif isinstance(obj, six.text_type):
        # returns itself if it is unicode
        return obj
    else:
        # decodes pY2 string to unicode
        return str(obj).decode('utf-8')
1088980
def to_unicode(obj, encoding='utf-8'):
    
    if isinstance(obj, string_types) or isinstance(obj, binary_type):
        if not isinstance(obj, text_type):
            obj = text_type(obj, encoding)
    return obj
381232
def _decode(self, obj):
        
        if self.decode_responses and isinstance(obj, bytes):
            try:
                return obj.decode(self.encoding)
            except UnicodeDecodeError:
                return obj
        return obj
349919
def _convert_folded_blocks(folded_ir_blocks):
    """"""
    new_folded_ir_blocks = []

    def folded_context_visitor(expression):
        """Transform LocalField objects into their Gremlin-specific counterpart."""
        if not isinstance(expression, LocalField):
            return expression

        return GremlinFoldedLocalField(expression.field_name)

    for block in folded_ir_blocks:
        new_block = block

        if isinstance(block, Filter):
            new_predicate = block.predicate.visit_and_update(folded_context_visitor)
            new_block = GremlinFoldedFilter(new_predicate)
        elif isinstance(block, Traverse):
            new_block = GremlinFoldedTraverse.from_traverse(block)
        elif isinstance(block, (MarkLocation, Backtrack)):
            # We remove MarkLocation and Backtrack blocks from the folded blocks output,
            # since they do not produce any Gremlin output code inside folds.
            continue
        else:
            raise AssertionError(u'Found an unexpected IR block in the folded IR blocks: '
                                 u'{} {} {}'.format(type(block), block, folded_ir_blocks))

        new_folded_ir_blocks.append(new_block)

    return new_folded_ir_blocks
65745
def _native_to_unicode(s):
  """"""
  if six.PY2:
    return s if isinstance(s, unicode) else s.decode("utf-8")
  else:
    return s
266440
def render_unicode(self, *args, **data):
        """"""

        return runtime._render(self,
                                self.callable_,
                                args,
                                data,
                                as_unicode=True)
451964
def to_str(obj):
    
    if isinstance(obj, str):
        return obj
    if isinstance(obj, unicode):
        return obj.encode('utf-8')
    return str(obj)
336572
def _non_unicode_repr(objekt, context, maxlevels, level):
    
    repr_string, isreadable, isrecursive = pprint._safe_repr(objekt, context,
                                                             maxlevels, level)
    if repr_string.startswith('u"') or repr_string.startswith("u'"):
        repr_string = repr_string[1:]
    return repr_string, isreadable, isrecursive