def force(self): if self.w_str is None: s = self.builder.build() if self.length < len(s): s = s[:self.length] self.w_str = W_BytesObject(s) return s else: return self.w_str._value
def _newtext_memo(self, s): if s is None: return self.w_None # can happen during annotation # try to see whether we exist as an interned string, but don't intern # if not w_t = self.interned_strings.get(s) if w_t is not None: return w_t return W_BytesObject(s)
def descr_add(self, space, w_other): try: other = W_BytesObject._op_val(space, w_other) except OperationError as e: if e.match(space, space.w_TypeError): return space.w_NotImplemented raise if self.builder.getlength() != self.length: builder = StringBuilder() builder.append(self.force()) else: builder = self.builder builder.append(other) return W_StringBufferObject(builder)
def newfilename(self, s): assert isinstance(s, str) # on pypy3, this decodes the byte string return W_BytesObject(s) # with the filesystem encoding
def newtext(self, s): assert isinstance(s, str) return W_BytesObject(s) # Python3 this is unicode
def newbytes(self, s): assert isinstance(s, str) return W_BytesObject(s)
def newtext(self, s): assert isinstance(s, str) if is_annotation_constant(s): return self._newtext_memo(s) return W_BytesObject(s) # Python3 this is unicode