def to_string(self,
               short_variant: bool,
               lang: 'MorphLang' = None,
               lev: int = 0) -> str:
     res = io.StringIO()
     nws = self.new_items
     if (len(nws) > 0):
         for p in nws:
             dpr = DecreePartReferent()
             ii = p.find(' ')
             if (ii < 0):
                 dpr.add_slot(p, "", False, 0)
             else:
                 dpr.add_slot(p[0:0 + ii], p[ii + 1:], False, 0)
             print(" новый '{0}'".format(dpr.to_string(True, None, 0)),
                   end="",
                   file=res,
                   flush=True)
     if (self.kind != DecreeChangeValueKind.UNDEFINED):
         print(" {0}".format(
             str(
                 MetaDecreeChangeValue.KIND_FEATURE.
                 convert_inner_value_to_outer_value(
                     Utils.enumToString(self.kind), lang)).lower()),
               end="",
               file=res,
               flush=True)
     if (self.number is not None):
         print(" {0}".format(self.number), end="", file=res, flush=True)
     val = self.value
     if (val is not None):
         if (len(val) > 100):
             val = (val[0:0 + 100] + "...")
         print(" '{0}'".format(val), end="", file=res, flush=True)
         Utils.replaceStringIO(res, '\n', ' ')
         Utils.replaceStringIO(res, '\r', ' ')
     return Utils.toStringStringIO(res).strip()
예제 #2
0
 def __attach_uri_content(
         t0: 'Token',
         chars_: str,
         can_be_whitespaces: bool = False) -> 'UriItemToken':
     txt = io.StringIO()
     t1 = t0
     dom = UriItemToken.attach_domain_name(t0, True, can_be_whitespaces)
     if (dom is not None):
         if (len(dom.value) < 3):
             return None
     open_char = chr(0)
     t = t0
     if (dom is not None):
         t = dom.end_token.next0_
     first_pass3411 = True
     while True:
         if first_pass3411: first_pass3411 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (t != t0 and t.is_whitespace_before):
             if (t.is_newline_before or not can_be_whitespaces):
                 break
             if (dom is None):
                 break
             if (t.previous.is_hiphen):
                 pass
             elif (t.previous.is_char_of(",;")):
                 break
             elif (t.previous.is_char('.') and t.chars.is_letter
                   and t.length_char == 2):
                 pass
             else:
                 ok = False
                 tt1 = t
                 if (t.is_char_of("\\/")):
                     tt1 = t.next0_
                 tt0 = tt1
                 first_pass3412 = True
                 while True:
                     if first_pass3412: first_pass3412 = False
                     else: tt1 = tt1.next0_
                     if (not (tt1 is not None)): break
                     if (tt1 != tt0 and tt1.is_whitespace_before):
                         break
                     if (isinstance(tt1, NumberToken)):
                         continue
                     if (not (isinstance(tt1, TextToken))):
                         break
                     term1 = tt1.term
                     if (((term1 == "HTM" or term1 == "HTML" or term1
                           == "SHTML") or term1 == "ASP" or term1 == "ASPX")
                             or term1 == "JSP"):
                         ok = True
                         break
                     if (not tt1.chars.is_letter):
                         if (tt1.is_char_of("\\/")):
                             ok = True
                             break
                         if (not tt1.is_char_of(chars_)):
                             break
                     elif (not tt1.chars.is_latin_letter):
                         break
                 if (not ok):
                     break
         if (isinstance(t, NumberToken)):
             nt = Utils.asObjectOrNull(t, NumberToken)
             print(nt.get_source_text(), end="", file=txt)
             t1 = t
             continue
         tt = Utils.asObjectOrNull(t, TextToken)
         if (tt is None):
             rt = Utils.asObjectOrNull(t, ReferentToken)
             if (rt is not None and rt.begin_token.is_value("РФ", None)):
                 if (txt.tell() > 0 and Utils.getCharAtStringIO(
                         txt,
                         txt.tell() - 1) == '.'):
                     print(rt.begin_token.get_source_text(),
                           end="",
                           file=txt)
                     t1 = t
                     continue
             if (rt is not None and rt.chars.is_latin_letter
                     and rt.begin_token == rt.end_token):
                 print(rt.begin_token.get_source_text(), end="", file=txt)
                 t1 = t
                 continue
             break
         src = tt.get_source_text()
         ch = src[0]
         if (not str.isalpha(ch)):
             if (chars_.find(ch) < 0):
                 break
             if (ch == '(' or ch == '['):
                 open_char = ch
             elif (ch == ')'):
                 if (open_char != '('):
                     break
                 open_char = (chr(0))
             elif (ch == ']'):
                 if (open_char != '['):
                     break
                 open_char = (chr(0))
         print(src, end="", file=txt)
         t1 = t
     if (txt.tell() == 0):
         return dom
     i = 0
     i = 0
     while i < txt.tell():
         if (str.isalnum(Utils.getCharAtStringIO(txt, i))):
             break
         i += 1
     if (i >= txt.tell()):
         return dom
     if (Utils.getCharAtStringIO(txt,
                                 txt.tell() - 1) == '.'
             or Utils.getCharAtStringIO(txt,
                                        txt.tell() - 1) == '/'):
         Utils.setLengthStringIO(txt, txt.tell() - 1)
         t1 = t1.previous
     if (dom is not None):
         Utils.insertStringIO(txt, 0, dom.value)
     tmp = Utils.toStringStringIO(txt)
     if (tmp.startswith("\\\\")):
         Utils.replaceStringIO(txt, "\\\\", "//")
         tmp = Utils.toStringStringIO(txt)
     if (tmp.startswith("//")):
         tmp = tmp[2:]
     if (Utils.compareStrings(tmp, "WWW", True) == 0):
         return None
     res = UriItemToken._new2706(t0, t1, Utils.toStringStringIO(txt))
     return res